コード例 #1
0
ファイル: logtemps.c プロジェクト: edboel/projects
void setup() {
  //Serial.begin(9600);

  PgmPrint("Free RAM: ");
  //Serial.println(FreeRam());  

  // initialize the SD card at SPI_HALF_SPEED to avoid bus errors with
  // breadboards.  use SPI_FULL_SPEED for better performance.
  pinMode(10, OUTPUT);                       // set the SS pin as an output (necessary!)
  digitalWrite(10, HIGH);                    // but turn off the W5100 chip!

  if (!card.init(SPI_HALF_SPEED, 4)) error("card.init failed!");

  // initialize a FAT volume
  if (!volume.init(&card)) error("vol.init failed!");

  PgmPrint("Volume is FAT");
  //Serial.println(volume.fatType(),DEC);
  //Serial.println();

  if (!root.openRoot(&volume)) error("openRoot failed");

  // list file in root with date and size
  PgmPrintln("Files found in root:");
  root.ls(LS_DATE | LS_SIZE);
  //Serial.println();

  // Recursive list of all directories
  PgmPrintln("Files found in all dirs:");
  root.ls(LS_R);

  //Serial.println();
  PgmPrintln("Done");

  // Debugging complete, we start the server!
  Ethernet.begin(mac, ip);
  server.begin();
  
  // Start up the temperature library
  sensorsa.begin();
  sensorsb.begin();
  sensorsc.begin();
  sensorsd.begin();
  
  setTime(0); // start the clock
  time33mins = time60mins = now();

}
コード例 #2
0
void sensor_setup(){  
  temp_sensor.begin();//initialize one wire sensor
  temp_sensor.setResolution(insideThermometer, 9);  //configure sensor parameters 
  
   
#ifdef DEBUG_SENS
  // report on finding the devices on the bus or not
  if (!temp_sensor.getAddress(insideThermometer, 0)) softdebug.println("Unable to find address for Device 0");
  else{  
    
    // report parasite power requirements
    softdebug.print("Parasite power is: "); 
    if (temp_sensor.isParasitePowerMode()) softdebug.println("ON");
    else softdebug.println("OFF");
    
    sensors_temperature(); //print temperature for debugging
    
  }
  
  //print voltage sensor value for debugging
  softdebug.print("Vin=");
  softdebug.println(sensors_vin());
  
#endif //DEBUG_SENS
}
コード例 #3
0
float MXS1101::getTempC()
{
	oneWire.reset();
	_MXS1101.begin();
	_MXS1101.requestTemperatures();
	return _MXS1101.getTempCByIndex(0);
}
コード例 #4
0
ファイル: aquarium.cpp プロジェクト: djtulan/Arduino-Aquarium
/**
 * @brief arduino setup function
 */
void setup() {
  Serial.begin(9600);

  Display::Init();

  if (RTC.get() == 0) {
    // following line sets the RTC to the date & time this sketch was compiled
    RTC.set(hhmmss());
  }

  setSyncProvider(RTC.get); // the function to get the time from the RTC

  // Transmitter is connected to Arduino Pin #10
  mySwitch.enableTransmit(7);

  dallastemp.begin(); // Inizialisieren der Dallas Temperature library
  dallastemp.setWaitForConversion(false);

  aqua.begin();

  pinMode(BUTTON_PIN_1, INPUT_PULLUP);
  pinMode(BUTTON_PIN_2, INPUT_PULLUP);
//  pinMode(BUTTON_PIN_3, INPUT_PULLUP);
//  pinMode(BUTTON_PIN_4, INPUT_PULLUP);
}
コード例 #5
0
ファイル: heater_FSM.c プロジェクト: lvesterg/heater
void setup() {

  // Init display
  mySerial.begin(9600); // set up serial port for 9600 baud
  delay(500); // wait for display to boot up
  


  // Setup DS1820 temp sensor

  sensors.begin();
  sensors.setResolution(Sensor1, 11);
  sensors.setResolution(Sensor2, 11);
  sensors.setWaitForConversion(false);
  sensors.requestTemperatures();
  delayInMillis = 750 / (1 << (12 - 11)); //750 for 12bit, 400 for 11bit, 220 for 10bit, 100 for 9bit
                        // calc by   delayInMillis = 750 / (1 << (12 - resolution)); 
  lastTempRequest = millis(); 


  // Set next state i FSM
  menu_FSM = M_PAGE1;
  menu_last_state = M_PAGE1;
  system_FSM = S_IDLE;
 
 
   // **************** Set up display *******************
  DisplayClear();
  MenuShowTime = millis();
 
  
  // **************** Set up RTC ***********************
  Wire.begin();
  rtc.begin();
  //TimeDate(rtc.now(),dateTimeString,1);

  //DateTime now = rtc.now();

 // write on display
  DisplayGoto(2,0);
  mySerial.print("Version 0.9B");

  
  // **************** Set up SD card *******************
  pinMode(10, OUTPUT);
  DisplayGoto(1,0);
  mySerial.write("Init SD -> "); // clear display + legends
 
  DisplayGoto(1,11);
  // see if the card is present and can be initialized:
  if (!SD.begin())
    mySerial.write("Fail");
  else
    mySerial.write("OK");
  delay(2000);
  
  // ***************** Clear display ********************
  DisplayClear();
   
  }
コード例 #6
0
void setup()
{
    pinMode(13, OUTPUT);

    // Set up all of the Digital IO pins.
    pinMode(pin_leftCutterCheck,INPUT);
    pinMode(pin_rightCutterCheck,INPUT);
    pinMode(pin_leftCutterControl,OUTPUT);
    pinMode(pin_rightCutterControl,OUTPUT);
    // Turn off the cutters by default
    digitalWrite(pin_leftCutterControl,LOW);
    digitalWrite(pin_rightCutterControl,LOW);

	// Initialize the rear panel LED outputs
    pinMode(pin_ledHigh,OUTPUT);
    pinMode(pin_ledMid,OUTPUT);
	pinMode(pin_ledLow,OUTPUT);
	digitalWrite(pin_ledHigh, LOW);
	digitalWrite(pin_ledMid, LOW);
	digitalWrite(pin_ledLow, LOW);
	
	temperatureTop.begin();
    temperatureBot.begin();
    
    // Make sure we have temperature sensors, if not, set to something
    // unreasonable. This would be 0 in Alabama.
    if(!temperatureTop.getAddress(topAddress,0))
    {
        msgStatus.temperature_1 = 0.0;
    } else {
        temperatureTop.setResolution(topAddress,9);
        temperatureTop.setWaitForConversion(false);
        temperatureTop.requestTemperatures();
    }
    if(!temperatureBot.getAddress(botAddress,0))
    {
        msgStatus.temperature_2 = 0.0;
    } else {
        temperatureBot.setResolution(botAddress,9);
        temperatureBot.setWaitForConversion(false);
        temperatureBot.requestTemperatures();
    }
    nh.initNode(); 
	nh.advertise(status_pub);
	nh.advertiseService(cutter_srv);
}
コード例 #7
0
ファイル: OpenGarden.cpp プロジェクト: thaussma/OpenGarden
//Sensor initializing functions:
void OpenGardenClass::initSensors(void){
  pinMode(sensorPowerPin, OUTPUT);
  pinMode(ecPowerPin, OUTPUT);
  digitalWrite(sensorPowerPin, LOW); 
  digitalWrite(ecPowerPin, LOW);
  sensors.begin();
  dht.begin();
}
コード例 #8
0
void Thermometer::begin() {
   if (!initialized) {
      // Start up the library
      sensors.begin();
      sensors.setResolution(thermometerAddress, RESOLUTION);

      initialized = true;
   }
}
コード例 #9
0
double Sensor::getDS18B20Reading()
{
    OneWire oneWire(index);
    DallasTemperature sensor = DallasTemperature(&oneWire);
    sensor.setResolution(12);
    sensor.begin();
    sensor.requestTemperatures();
    return sensor.getTempCByIndex(0);
}
コード例 #10
0
void setup(void)
{
  // start serial port
  Serial.begin(9600);
  Serial.println("Dallas Temperature IC Control Library Demo");

  // locate devices on the bus
  Serial.print("Locating devices...");
  sensors.begin();
  Serial.print("Found ");
  Serial.print(sensors.getDeviceCount(), DEC);
  Serial.println(" devices.");

  // report parasite power requirements
  Serial.print("Parasite power is: "); 
  if (sensors.isParasitePowerMode()) Serial.println("ON");
  else Serial.println("OFF");
  
  // assign address manually.  the addresses below will beed to be changed
  // to valid device addresses on your bus.  device address can be retrieved
  // by using either oneWire.search(deviceAddress) or individually via
  // sensors.getAddress(deviceAddress, index)
  //insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };

  // Method 1:
  // search for devices on the bus and assign based on an index.  ideally,
  // you would do this to initially discover addresses on the bus and then 
  // use those addresses and manually assign them (see above) once you know 
  // the devices on your bus (and assuming they don't change).
  if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0"); 
  
  // method 2: search()
  // search() looks for the next device. Returns 1 if a new address has been
  // returned. A zero might mean that the bus is shorted, there are no devices, 
  // or you have already retrieved all of them.  It might be a good idea to 
  // check the CRC to make sure you didn't get garbage.  The order is 
  // deterministic. You will always get the same devices in the same order
  //
  // Must be called before search()
  //oneWire.reset_search();
  // assigns the first address found to insideThermometer
  //if (!oneWire.search(insideThermometer)) Serial.println("Unable to find address for insideThermometer");

  // show the addresses we found on the bus
  Serial.print("Device 0 Address: ");
  printAddress(insideThermometer);
  Serial.println();

  // set the resolution to 9 bit (Each Dallas/Maxim device is capable of several different resolutions)
  sensors.setResolution(insideThermometer, 9);
 
  Serial.print("Device 0 Resolution: ");
  Serial.print(sensors.getResolution(insideThermometer), DEC); 
  Serial.println();

  
}
コード例 #11
0
ファイル: code.c プロジェクト: Tambralinga/loguino
 void DS18B20_init(){
     #ifdef DEBUG_DS18B20_POLLER
         DEBUG_1("Starting");
     #endif
     ds_sensors.begin();
     ds_count = ds_sensors.getDeviceCount();
     #ifdef DEBUG_DS18B20_POLLER
         DEBUG_1("Finished");
     #endif
 }
コード例 #12
0
ファイル: Tester.cpp プロジェクト: hdo/arduino_panstamp
void setup(void)
{
  // start serial port
  Serial.begin(38400);
  delay(1000);
  Serial.println("Dallas Temperature IC Control Library Demo");

  // Start up the library
  sensors.begin();
  
  // Grab a count of devices on the wire
  numberOfDevices = sensors.getDeviceCount();
  
  // locate devices on the bus
  Serial.print("Locating devices...");
  
  Serial.print("Found ");
  Serial.print(numberOfDevices, DEC);
  Serial.println(" devices.");

  // report parasite power requirements
  Serial.print("Parasite power is: "); 
  if (sensors.isParasitePowerMode()) Serial.println("ON");
  else Serial.println("OFF");
  
  // Loop through each device, print out address
  for(int i=0;i<numberOfDevices; i++)
  {
    // Search the wire for address
    if(sensors.getAddress(tempDeviceAddress, i))
	{
		Serial.print("Found device ");
		Serial.print(i, DEC);
		Serial.print(" with address: ");
		printAddress(tempDeviceAddress);
		Serial.println();
		
		Serial.print("Setting resolution to ");
		Serial.println(TEMPERATURE_PRECISION, DEC);
		
		// set the resolution to TEMPERATURE_PRECISION bit (Each Dallas/Maxim device is capable of several different resolutions)
		sensors.setResolution(tempDeviceAddress, TEMPERATURE_PRECISION);
		
		 Serial.print("Resolution actually set to: ");
		Serial.print(sensors.getResolution(tempDeviceAddress), DEC); 
		Serial.println();
	}else{
		Serial.print("Found ghost device at ");
		Serial.print(i, DEC);
		Serial.print(" but could not detect address. Check power and cabling");
	}
  }

}
コード例 #13
0
ファイル: main.cpp プロジェクト: rob-smallshire/mistral-slave
void setup() {
    delay(2000);

    Serial.begin(9600);

    Serial.print("Setup...");

    sensors.begin(); // IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement
    inside_thermometer.setResolution(10);
    cabinet_thermometer.setResolution(10);
    outside_thermometer.setResolution(10);

    I2c.begin();
    I2c.timeOut(100);
    I2c.write(SERVO_CONTROLLER_ADDRESS, SERVO_CONFIG_REGISTER, SERVO_STANDARD_MODE);
    analogReference(EXTERNAL);

    fan_a.begin(ConfigureMax6651(i2c_master, ADDRESS_VCC)
                                .v12()
                                .preScaler(PRESCALER_DIVIDE_BY_2)
                                .tachometerCountTime(TACH_COUNT_TIME_2_0)
                                .tachometerAlarm(true)
                                .minAlarm(true)
                                .maxAlarm(true)
                                .gpio0AsAlertOutput()
                                .gpioAsOutput(1, true)
                                .gpio2AsClockOutput()
                                .gpioAsOutput(3, true)
                                .gpioAsOutput(4, true)
                                .logger(&Serial));

    fan_b.begin(ConfigureMax6651(i2c_master, ADDRESS_GND)
                                .v12()
                                .preScaler(PRESCALER_DIVIDE_BY_2)
                                .tachometerCountTime(TACH_COUNT_TIME_2_0)
                                .tachometerAlarm(true)
                                .minAlarm(true)
                                .maxAlarm(true)
                                .gpio0AsAlertOutput()
                                .gpioAsOutput(1, true)
                                .gpio2AsClockInput()
                                .gpioAsOutput(3, true)
                                .gpioAsOutput(4, true)
                                .logger(&Serial));

   //fan_a.stop();
   //fan_b.stop();

   // TODO: Fan and iris calibration

   controller.begin();

   Serial.println("done.");
}
コード例 #14
0
void setup()
{
   // Note: Ethernet shield uses digitial IO pins 10,11,12, and 13   
   Serial.begin(9600);
  
   Serial.println(version);
   Serial.println();
  
   // locate devices on the 1Wire bus
   Serial.print("Locating devices on 1Wire bus...");
   sensors.begin();
   int count = sensors.getDeviceCount();
   Serial.print("Found ");
   Serial.print( count );
   Serial.println(" devices on 1wire bus");

   // select the first sensor   
   for ( int i=0; i<count; i++ )
   {
      if ( sensors.getAddress(thermometer, i) ) 
      {
         Serial.print("1wire device ");
         Serial.print(i);
         Serial.print(" has address: ");
         printAddress(thermometer);
         Serial.println();
      }
      else
      {
         Serial.print("Unable to find address for 1wire device "); 
         Serial.println( i );
      }  
   }
  
   // if you want to use a particular sensor, you can hard code it here 
   if (0)
   { 
      DeviceAddress addr = { 0x10, 0xE4, 0xF1, 0xD2, 0x01, 0x08, 0x00, 0xBE };
      for (uint8_t i = 0; i < 8; i++)
      {
         thermometer[i] = addr[i];
      }
   }
  
   // show the addresses we found on the bus
   Serial.print("Using 1wire device: ");
   printAddress(thermometer);
   Serial.println();

   // set the resolution to 9 bit 
   sensors.setResolution(thermometer, 9);
  
   dhcpInit();
}
コード例 #15
0
ファイル: endevor2.cpp プロジェクト: RobertNewkirk/particle
void setup()
{


  oled.begin();    // Initialize the OLED
  oled.clear(ALL); // Clear the display's internal memory
  oled.display();  // Display what's in the buffer (splashscreen)
  delay(1000);     // Delay 1000 ms
  oled.clear(PAGE); // Clear the buffer.
  // display the version at boot for 2 seconds
  oled.setFontType(1);
  oled.setCursor(0,8);
  oled.print(FILENAME);
  oled.setCursor(0,24);
  oled.print(MYVERSION);
  oled.display();
  oled.setFontType(0);
  delay(5000);

  request.port = 80;
  request.hostname = "things.ubidots.com";
  Serial.begin(9600);
  sensor.begin();

  Particle.variable("count_devices", &deviceCount, INT);
  Particle.function("q", queryDevices);
  Particle.function("setmode", setModeFunc);
  Particle.function("printEEProm", printEEPROMFunc);
  Particle.function("relay", relayFunc);

  //Need to set the device Index Array at startup
  deviceCount = getDeviceCount();
  queryDevices("auto");

  Particle.publish("reboot",Time.timeStr() );

     //encoder
  pinMode(encoderA, INPUT_PULLUP);
  pinMode(encoderB, INPUT_PULLUP);
  pinMode(button,INPUT_PULLUP);
  pinMode(relay, OUTPUT);
  attachInterrupt(encoderA, doEncoderA, CHANGE);
  attachInterrupt(encoderB, doEncoderB, CHANGE);

 // temperatureJob();  // do this one time so the first screen gets displayed





}
コード例 #16
0
ファイル: temp_serial1.c プロジェクト: edboel/projects
void setup()
{
  Serial.begin(9600);
  
  // Switch on the backlight
  pinMode ( BACKLIGHT_PIN, OUTPUT );
  digitalWrite ( BACKLIGHT_PIN, HIGH );
  
  lcd.begin(16,2);               // initialize the lcd 
  sen1.begin();
  sen2.begin();
  sen3.begin();
  sen4.begin();
  sen5.begin();

  lcd.home ();                   // go home
  lcd.print(" getting temps ");  
  lcd.setCursor ( 0, 1 );        // go to the next line
  lcd.print (" init serial   ");
  delay ( 1000 );
  digitalWrite ( BACKLIGHT_PIN, LOW);
  
}
コード例 #17
0
void Hardware_Initialize()
{
    // DS18B20 initialization
    sensors.begin();
    sensors.setResolution(inSoilThermometer, TEMPERATURE_PRECISION);

    pinMode(WSPEED, INPUT_PULLUP); // input from wind meters windspeed sensor
    pinMode(RAIN, INPUT_PULLUP); // input from wind meters rain gauge sensor

    pinMode(SOIL_MOIST_POWER, OUTPUT); // power control for soil moisture
    digitalWrite(SOIL_MOIST_POWER, LOW); // Leave off by defualt

    // Setup status LED
    pinMode(STATUS_LED, OUTPUT);
    digitalWrite(STATUS_LED, LOW);

    Serial.begin(9600);   // open serial over USB

    // Initialize the I2C sensors and ping them
    sensor.begin();

    //
    // You can only receive acurate barrometric readings or acurate altitiude
    // readings at a given time, not both at the same time. The following two lines
    // tell the sensor what mode to use. You could easily write a function that
    // takes a reading in one made and then switches to the other mode to grab that
    // reading, resulting in data that contains both acurate altitude and barrometric
    // readings. For this example, we will only be using the barometer mode. Be sure
    // to only uncomment one line at a time.
    //

    sensor.setModeBarometer(); // Set to Barometer Mode
    //baro.setModeAltimeter(); // Set to altimeter Mode

    // These are additional MPL3115A2 functions the MUST be called for the sensor to work.

    sensor.setOversampleRate(7); // Set Oversample rate

    //
    // Call with a rate from 0 to 7. See page 33 for table of ratios.
    // Sets the over sample rate. Datasheet calls for 128 but you can set it
    // from 1 to 128 samples. The higher the oversample rate the greater
    // the time between data samples.
    //

    sensor.enableEventFlags(); // Necessary register calls to enble temp, baro ansd alt

    return;
}
コード例 #18
0
ファイル: ds18b20.cpp プロジェクト: Shanjiv/1st-IOT-Project
uint8_t ds18b20_initialize()
{
  sensors.begin();
  n_sensors = sensors.getDeviceCount();
  sprintf(debug_str, "N%d", n_sensors);
  debug(debug_str);
  if(n_sensors > 4) n_sensors = 4; 
  uint8_t resolution = get_resolution(&sensors);
  if(resolution > 12 || resolution < 9) {
    debug("reset");
    sleep_mseconds(100);
    beenode_reset();
  }
  return n_sensors;
}
コード例 #19
0
void setup()
{
  Serial.begin(9600);
  Serial.print("Initializing SD card...");
  pinMode(10, OUTPUT);
  sensors.begin();
  sensors.setResolution(outsideThermometer, 10);
  sensors.setResolution(insideThermometer, 10);
//  bmp085Calibration();
 
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    return;
  }
  Serial.println("card initialized.");
}
コード例 #20
0
ファイル: TempSensor.cpp プロジェクト: basaf/MQTT_Module
/**
*	\brief Initializes the temperature sensors with a given resolution
*/
void tempSenosrsInit(const uint8_t resolution){
	sensors.begin();
	if(resolution >= 9 && resolution <=12){
		sensors.setResolution(resolution);
		Serial.println(F("Setting resolution to ")); Serial.print(resolution); Serial.println(F(" bit"));
	}
	else{
		//default is 10-bit
		Serial.println(F("Setting default resolution of temperature sensors"));
		sensors.setResolution(DEFAULT_RESOLUTION);
	}
	
	Serial.println(F("Create address table for OneWire sensors..."));
	createAddressTable();
	
	Serial.print(F("Temperature Sensors initialized @ pin ")); Serial.println(ONE_WIRE_BUS_PIN); 
}
コード例 #21
0
ファイル: application.cpp プロジェクト: TheokieZA/Sming
void init()
{
	Serial.begin(SERIAL_BAUD_RATE); // 115200 by default
	Serial.systemDebugOutput(true); // Allow debug output to serial

	sensors.begin(); // It's required for one-wire initialization!
	sensors.setResolution(12);

	WifiStation.config(WIFI_SSID, WIFI_PWD);
	WifiStation.enable(true);
	WifiAccessPoint.enable(false);

	// Run our method when station was connected to AP (or not connected)
	WifiStation.waitConnection(connectOk, 20, connectFail); // We recommend 20+ seconds for connection timeout at start

	procTimer2.initializeMs(3000, readData).start();
}
コード例 #22
0
ファイル: main.cpp プロジェクト: geosk/brewery
void setup(void)
{
	// init pins
	pinMode(TEN_WIRE, OUTPUT);

	// start serial port
	prevMillis= millis();
	Serial.begin(9600);

    pinMode(BT_Rx, INPUT);
    pinMode(BT_Tx, OUTPUT);
    blueToothSerial.begin(38400);

	// Start up the library
	sensors.begin();

	// Load brewering receipt from EEPROM
	//cmd_Load();
}
コード例 #23
0
ファイル: MexClk.cpp プロジェクト: eduardomdrs/rtc_therm_7seg
void setup()
{
	fsmState = EDIT_TIME_MODE;

	// initialize thermometer
	sensor.begin();
	sensor.setWaitForConversion(true);
	sensor.getAddress(devAddr, 0);
	sensor.requestTemperatures();
	tempInCelsius = (int) (sensor.getTempC(devAddr)*10);

	// initialize buttons
	buttonA.setClickTicks(250);
	buttonA.setPressTicks(600);
	buttonA.attachLongPressStart(longPressA);
	buttonA.attachClick(singleClickA);
	buttonA.attachDoubleClick(doubleClickA);

	buttonB.setClickTicks(250);
	buttonB.setPressTicks(600);
	buttonB.attachClick(singleClickB);
	buttonB.attachDoubleClick(doubleClickB);
	buttonB.attachLongPressStart(longPressB);

	// initialize serial
	Serial.begin(115200);

	// initialize rtc
	
	setSyncProvider(RTC.get);
	setSyncInterval(1);
	if(timeStatus()!= timeSet) 
	{
		Serial.println("Unable to sync with the RTC");
		fsmState = ERROR_MODE;
	} else
	{
		Serial.println("RTC has set the system time"); 
	}
	
	// default alarm settings, 08:30, disabled
	pinMode(ALARM_PIN, INPUT_PULLUP);
}
コード例 #24
0
ファイル: application.cpp プロジェクト: darcyg/nRF_TP
void setup() {
	RFDELAY(1000);
#if GATEWAY_NODE == 1
	pLayer.begin();
	Serial.begin(115200);
	Serial.setTimeout(20);
	pinMode(13, OUTPUT);
#else
  Serial.begin(57600);

  transportProtocol.begin(&sensorNetworkMessageHandler);

  pinMode(LIGHT_PIN, INPUT);
  pinMode(BATTERY_PIN, INPUT);
  pinMode(CURRENT_PIN, INPUT);
  pinMode(BATT_MEASURE_EN, OUTPUT);

  sensors.begin();

  transportProtocol.ping(0);
#endif
}
コード例 #25
0
void setup()
{
	Serial.begin(9600);
	
	LCD.begin();
	LCD.setTouch(true);
	LCD.setPenSolid(true);
	LCD.setFontSolid(false);
	LCD.setOrientation(LANDSCAPE);
	LCD.setFont(0x03);	
	
	//Initialize Digital Potentiometer
	pinMode(SLAVE_SELECT_PIN, OUTPUT);
	digitalWrite(SLAVE_SELECT_PIN, HIGH);
	SPI.begin(); 
	
	// Initialize temperature sensor
	temperatureSensor.begin();

	pinMode(PUMP_CONTROL, OUTPUT);
	setPumpOn(false);
	
	//TODO: Make it bootable even w/o SD in
	//pinMode(PUMP_POWER1, OUTPUT);
	//pinMode(PUMP_POWER2, OUTPUT);
	//pinMode(PUMP_POWER3, OUTPUT);
	//setPumpOn(false);
	
	pinMode(VALVE_CONTROL1, OUTPUT);
	pinMode(VALVE_CONTROL2, OUTPUT);
	digitalWrite(VALVE_CONTROL1, HIGH);
	digitalWrite(VALVE_CONTROL2, HIGH);	
	oneMinuteButton.draw();
	fiveMinuteButton.draw();
	tenMinuteButton.draw();
	LCD.tText(1, 2, WHITE, "Pick a calibration period");
}
コード例 #26
0
ファイル: 5sparktemp.cpp プロジェクト: RobertNewkirk/particle
void setup()
{


  oled.begin();    // Initialize the OLED
  oled.clear(ALL); // Clear the display's internal memory
  oled.display();  // Display what's in the buffer (splashscreen)
  delay(1000);     // Delay 1000 ms
  oled.clear(PAGE); // Clear the buffer.
  request.port = 80;
  request.hostname = "things.ubidots.com";
  Serial.begin(9600);
  sensor.begin();

  Particle.variable("count_devices", &deviceCount, INT);
  Particle.function("q", queryDevices);
  Particle.function("setmode", setModeFunc);
  Particle.function("printEEProm", printEEPROMFunc);
  Particle.function("regDevice", regDeviceFunc);

  //Need to set the device Index Array at startup
  deviceCount = getDeviceCount();
  queryDevices("auto");

   Particle.publish("reboot",Time.timeStr() );

     //encoder
  pinMode(encoderA, INPUT_PULLUP);
  pinMode(encoderB, INPUT_PULLUP);
  attachInterrupt(encoderA, doEncoderA, CHANGE);
  attachInterrupt(encoderB, doEncoderB, CHANGE);





}
コード例 #27
0
void setup() {
  memset(voltsChr,0,sizeof(voltsChr));
  memset(amps0Chr,0,sizeof(amps0Chr));
  memset(amps1Chr,0,sizeof(amps1Chr));
  memset(tmpChr,0,sizeof(tmpChr));

    // if the program crashed, skip things that might make it crash
  String rebootMsg = ESP.getResetReason();
  if (rebootMsg=="Exception") safeMode=true;
  else if (rebootMsg=="Hardware Watchdog") safeMode=true;
  else if (rebootMsg=="Unknown") safeMode=true;
  else if (rebootMsg=="Software Watchdog") safeMode=true;

  if (sw1>=0) {
    pinMode(sw1, OUTPUT);
  }
  if (sw2>=0) {
    pinMode(sw2, OUTPUT);
  }
  if (sw3>=0) {
    pinMode(sw3, OUTPUT);
  }
  if (sw4>=0) {
    pinMode(sw4, OUTPUT);
  }

  // "mount" the filesystem
  bool success = SPIFFS.begin();
  if (!success) SPIFFS.format();

  if (!safeMode) fsConfig(); // read node config from FS

#ifdef _TRAILER
  wifiMulti.addAP("DXtrailer", "2317239216");
#else
  wifiMulti.addAP("Tell my WiFi I love her", "2317239216");
#endif

  int wifiConnect = 240;
  while ((wifiMulti.run() != WL_CONNECTED) && (wifiConnect-- > 0)) { // spend 2 minutes trying to connect to wifi
    // connecting to wifi
    delay(1000);
  }

  if (wifiMulti.run() != WL_CONNECTED ) { // still not connected? reboot!
    ESP.reset();
    delay(5000);
  }

  if (hasHostname) { // valid config found on FS, set network name
    WiFi.hostname(String(nodename)); // set network hostname
    ArduinoOTA.setHostname(nodename);  // OTA hostname defaults to esp8266-[ChipID]
    MDNS.begin(nodename); // set mDNS hostname
  }

  WiFi.macAddress(mac); // get esp mac address, store it in memory, build fw update url
  sprintf(macStr,"%x%x%x%x%x%x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  sprintf(theURL,"/iotfw?mac=%s", macStr);

  // request latest config from web api
  if (!safeMode) getConfig();

  // check web api for new firmware
  if (!safeMode) httpUpdater();

  // start UDP for ntp client
  udp.begin(localPort);

  updateNTP();

  setSyncProvider(getNtptime); // use NTP to get current time
  setSyncInterval(600); // refresh clock every 10 min

#ifndef _MINI
  // start the webserver
  httpd.onNotFound(handleNotFound);
  httpd.begin();
  // Add service to MDNS-SD
  MDNS.addService("http", "tcp", 80);
#endif

  // start websockets server
  webSocket.begin();
  webSocket.onEvent(webSocketEvent);

  // setup other things
  setupOTA();
  setupMQTT();

  // setup i2c if configured, basic sanity checking on configuration
  if (hasI2C && iotSDA>=0 && iotSCL>=0 && iotSDA!=iotSCL) {
    sprintf(str,"I2C enabled, using SDA=%u SCL=%u", iotSDA, iotSCL);
    mqtt.publish(mqttpub, str);

    Wire.begin(iotSDA, iotSCL); // from api config file

    //Wire.begin(12, 14); // from api config file
    i2c_scan();

    printConfig();

    if (hasRGB) setupRGB();
    if (hasIout) setupADS();
    if (hasSpeed) setupSpeed();

  }

  // OWDAT = 4;
  if (OWDAT>0) { // setup onewire if data line is using pin 1 or greater
    sprintf(str,"Onewire Data OWDAT=%u", OWDAT);
    mqtt.publish(mqttpub, str);
    oneWire.begin(OWDAT);
    if (hasTout) {
      ds18b20 = DallasTemperature(&oneWire);
      ds18b20.begin(); // start one wire temp probe
    }
    if (hasTpwr>0) {
      pinMode(hasTpwr, OUTPUT); // onewire power pin as output
      digitalWrite(hasTpwr, LOW); // ow off
    }
  }


  if (useMQTT) {
    String rebootReason = String("Last reboot cause was ") + rebootMsg;
    rebootReason.toCharArray(str, rebootReason.length()+1);
    mqtt.publish(mqttpub, str);
  }
}
コード例 #28
0
ファイル: 5sparktemp.cpp プロジェクト: RobertNewkirk/particle
int getDeviceCount() {
     sensor.begin();
    deviceCount = sensor.getDeviceCount();
    return deviceCount;
}
コード例 #29
0
ファイル: XMega_QRP.c プロジェクト: malbel/xmega-qrp
int main(void) {    
    
    Config32MHzClock(); // Setup the 32MHz Clock. Should really be using 2MHz...
    
    // Setup output and input ports.
    LEDPORT.DIRSET = 0xFF; 
    LEDPORT.OUT = 0xFF;
    AD9835_PORT.DIRCLR = 0x40;
    PORTC.DIRSET = 0x04;

    // Start up the timer.
    init_timer();
    
    sensors.begin();
    sensors.requestTemperatures();
    
    // Wait a bit before starting the AD9835.
    // It seems to take a few hundred ms to 'boot up' once power is applied.
    _delay_ms(500); 
    
    // Configure the AD9835, and start in sleep mode.
    AD9835_Setup();
    AD9835_Sleep();
    
    // Setup the AD9835 for our chosen datamode.
    TX_Setup();
    AD9835_Awake();
    
    // Broadcast a bit of carrier.
    _delay_ms(1000);
    
    TXString("Booting up...\n"); // Kind of like debug lines.
    
    // Start up the GPS RX UART.
    init_gps();
    
    // Turn Interrupts on.
    PMIC.CTRL = PMIC_HILVLEN_bm | PMIC_LOLVLEN_bm;
    sei();
    
    sendNMEA("$PUBX,00"); // Poll the UBlox5 Chip for data.
    
    //TXString("GPS Active, Interrupts On.\n");
    
    int found_sensors = sensors.getDeviceCount();
    
    //sprintf(tx_buffer,"Found %u sensors.\n",found_sensors);
   // TXString(tx_buffer);
    unsigned int counter = 0; // Init out TX counter.
    
 
    while(1){
        // Identify every few minutes
        if ((counter%30 == 0)&&(data_mode != FALLBACK)) TXString("DE VK5VZI Project Horus HAB Launch - projecthorus.org \n");
    
	    // Read ADC PortA pin 0, using differential, signed input mode. Negative input comes from pin 1, which is tied to ground. Use VCC/1.6 as ref.
	    uint16_t temp = readADC(); 
	    float bat_voltage = (float)temp * 0.001007572056668* 8.5;
        floatToString(bat_voltage,1,voltString);
   
    
    
        // Collect GPS data
        
        gps.f_get_position(&lat, &lon);
	    sats = gps.sats();
	    if(sats>2){LEDPORT.OUTCLR = 0x80;}
	    speed = gps.f_speed_kmph();
	    altitude = (long)gps.f_altitude();
	    gps.crack_datetime(0, 0, 0, &time[0], &time[1], &time[2]);
	    
	    floatToString(lat, 5, latString);
	    floatToString(lon, 5, longString);
	    
        sensors.requestTemperatures();
        _intTemp = sensors.getTempC(internal);
        _extTemp = sensors.getTempC(external);
        if (_intTemp!=85 && _intTemp!=127 && _intTemp!=-127 && _intTemp!=999) intTemp = _intTemp;
        if (_extTemp!=85 && _extTemp!=127 && _extTemp!=-127 && _extTemp!=999) extTemp = _extTemp;
	    
	    if(data_mode != FALLBACK){
	    
            // Construct our Data String
            sprintf(tx_buffer,"$$DARKSIDE,%u,%02d:%02d:%02d,%s,%s,%ld,%d,%d,%d,%d,%s",counter++,time[0], time[1], time[2],latString,longString,altitude,speed,sats,intTemp,extTemp,voltString);
            
            
            // Calculate the CRC-16 Checksum
            char checksum[10];
            snprintf(checksum, sizeof(checksum), "*%04X\n", gps_CRC16_checksum(tx_buffer));
         
            // And copy the checksum onto the end of the string.
            memcpy(tx_buffer + strlen(tx_buffer), checksum, strlen(checksum) + 1);
        }else{
            // If our battery is really low, we don't want to transmit much data, so limit what we TX to just an identifier, battery voltage, and our position.
            
            sprintf(tx_buffer, "DE VK5VZI HORUS8 %s %s %s %ld", bat_voltage, latString, longString,altitude);
        }
        
        // Blinky blinky...
        LEDPORT.OUTTGL = 0x20;
        
        // Transmit!
        TXString(tx_buffer);
       
        
        sendNMEA("$PUBX,00"); // Poll the UBlox5 Chip for data again.
        
        /*
        // Check the battery voltage. If low, switch to a more reliable mode.
        if((bat_voltage < BATT_THRESHOLD) && (data_mode != RELIABLE_MODE)){
            new_mode = RELIABLE_MODE;
            // This string should be changed if the 'reliable' mode is changed.
            TXString("Battery Voltage Below 9V. Switching to DominoEX8.\n");
        }
        */
        // Perform a mode switch, if required. 
        // Done here to allow for mode changes to occur elsewhere.
        if(new_mode != -1){
            data_mode = new_mode;
            TX_Setup();
            new_mode = -1;
        }
        
        // And wait a little while before sending the next string.
        // Don't delay for domino - synch stuffs up otherwise
        if(data_mode != DOMINOEX8){
            _delay_ms(1000);
        }
        
        
    }

    
}
コード例 #30
0
void nanpy::DallasTemperatureClass::elaborate( nanpy::MethodDescriptor* m ) {
        ObjectsManager<DallasTemperature>::elaborate(m);

        if (strcmp(m->getName(),"new") == 0) {
            int prm = 0;
            OneWire* wr = new OneWire(m->getInt(0));
            DallasTemperature* dt = new DallasTemperature(&(*wr));
            v.insert(dt);
            dt->begin();
            m->returns(v.getLastIndex());
        }

        if (strcmp(m->getName(), "setResolution") == 0) {
            v[m->getObjectId()]->setResolution(m->getInt(0));
            m->returns(0);
        }

        if (strcmp(m->getName(), "getResolution") == 0) {
            m->returns(v[m->getObjectId()]->getResolution());
        }

        if (strcmp(m->getName(), "requestTemperatures") == 0) {
            if (m->getNArgs() == 1) {
                m->returns(v[m->getObjectId()]->requestTemperaturesByIndex(m->getInt(0)));
            } else if (m->getNArgs() > 1) {
                byte addr[8];
                for(int i = 0 ; i < m->getNArgs() ; i++) {
                    addr[i] = (byte)m->getInt(i);
                }
                m->returns(v[m->getObjectId()]->requestTemperaturesByAddress(addr));
            } else {
                v[m->getObjectId()]->requestTemperatures();
                m->returns(0);
            }
        }

        if (strcmp(m->getName(), "getTempC") == 0) {
            if(m->getNArgs() == 1) {
                m->returns(v[m->getObjectId()]->getTempCByIndex(m->getInt(0)));
            } else {
                byte addr[8];
                for(int i = 0 ; i < m->getNArgs() ; i++) {
                    addr[i] = (byte)m->getInt(i);
                }
                m->returns(v[m->getObjectId()]->getTempC(addr));
            }
        }

        if (strcmp(m->getName(), "getTempF") == 0) {
            if(m->getNArgs() == 1) {
                m->returns(v[m->getObjectId()]->getTempFByIndex(m->getInt(0)));
            } else {
                byte addr[8];
                for(int i = 0 ; i < m->getNArgs() ; i++) {
                    addr[i] = (byte)m->getInt(i);
                }
                m->returns(v[m->getObjectId()]->getTempF(addr));
            }
        }

        if (strcmp(m->getName(), "getAddress") == 0) {
            byte addr[8];
            String addr_hex = String();
            if(!v[m->getObjectId()]->getAddress(addr, m->getInt(0))) {
                m->returns(1);
                return;
            }
   
            char stmp[3];
            for( int cc = 0; cc < 8; cc++ )
            {
                sprintf(stmp, "%02X", addr[cc]);
                addr_hex.concat( stmp );
                if (cc < 7)
                    addr_hex.concat( "." );
            }
            m->returns(addr_hex);
        }

        if (strcmp(m->getName(), "getDeviceCount") == 0) {
            m->returns(v[m->getObjectId()]->getDeviceCount());
        }
};