bool setTemperature(unsigned long iTemp){ //Serial.println("Req temp"); sensors.requestTemperatures(); // Send the command to get temperatures //Serial.println("Requested"); float tempr = sensors.getTempCByIndex(0); //Serial.println("Temp res"); //displayData("Temp res"); char buffer[256]; displayData(itoa(tempr, buffer, 10)); displayData(","); displayData(itoa(iTemp, buffer, 10)); displayData(","); //Serial.println("params"); // Serial.println("thi:" + iTenHighMax); // Serial.println("tlo:" + iTenLowMax); if ((tempr <= iTemp) && (iTenHigh < iTenHighMax)){ digitalWrite(TEN_WIRE, HIGH); displayData("H"); iTenHigh++; iTenLow = 0; }else{ digitalWrite(TEN_WIRE, LOW); displayData("L"); iTenLow++; if(iTenLow >= iTenLowMax) iTenHigh = 0; } displayData("\r\n"); return (tempr >= (iTemp - 1)) and (tempr <= (iTemp + 10)); }
/** * \brief Prints all connected OneWire sensors with there index and current temperature value. */ void tempSensorsPrintInfo(void){ uint8_t address[8]; float temp; uint8_t deviceCount=sensors.getDeviceCount(); Serial.print("Found devices: "); Serial.println(deviceCount); Serial.println(" "); sensors.requestTemperatures(); for(int i=0; i<deviceCount; i++){ Serial.print("Device: "); Serial.println(i); if(sensors.getAddress(address, i)){ temp=sensors.getTempC(address); Serial.print("Temp: "); Serial.print(temp); Serial.println(" "); //delay(100); Serial.print("Resolution: "); Serial.println(sensors.getResolution(address)); Serial.println(""); //delay(100); } } }
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(); }
void doTout() { String vStr; memset(tmpChr,0,sizeof(tmpChr)); if (hasTpwr>0) { digitalWrite(hasTpwr, HIGH); // ow on delay(5); // wait for powerup } ds18b20.requestTemperatures(); byte retry = 20; float temp=0.0; do { temp = ds18b20.getTempCByIndex(0); retry--; delay(2); } while (retry > 0 && (temp == 85.0 || temp == (-127.0))); if (hasTpwr>0) { digitalWrite(hasTpwr, LOW); // ow off } vStr = String("temp=") + String(temp,3); vStr.toCharArray(tmpChr, vStr.length()+1); }
void temperatureJob() { float gotTemp = 0; Serial << "the device count is " << deviceCount << endl; sensor.requestTemperatures(); // get all the tempratures first to speed up, moved up from getTemp() for (int i =0; i < deviceCount; i++ ) { gotTemp = sensor.getTempF(*deviceAddressArray[i]); if (gotTemp < -195 ) continue; Serial << "gotTemp() = " << i << " " << gotTemp << endl; request.body = formatTempToBody(gotTemp, i); // if (mycounter % PUSHFREQ == 0 && PUSHTOUBIFLAG == 1 ) { if (mycounter % PUSHFREQ == 0 && PUSHTOUBIFLAG == 1) { String mypath = String("/api/v1.6/variables/"); mypath.concat(ubivar[i]); mypath.concat("/values"); Serial << "going to push "<< request.body << " to " << mypath << endl; request.path = mypath; http.post(request, response, headers); if( debug ) Serial << "http body: " << request.body << endl; Serial << " Did we reboot? I hope not "; } if( debug) debugSerial(i); } }
float MXS1101::getTempC() { oneWire.reset(); _MXS1101.begin(); _MXS1101.requestTemperatures(); return _MXS1101.getTempCByIndex(0); }
void DS18B20_sample(){ #ifdef DEBUG_DS18B20_POLLER DEBUG_1("Starting"); #endif #ifdef DEBUG_DS18B20_POLLER DEBUG_5("Requesting Temperatures"); #endif char buf[25]; ds_sensors.requestTemperatures(); for (int i=0; i < ds_count; i++){ #ifdef DEBUG_DS18B20_POLLER DEBUG_5("Logging DSB Pin"); #endif sprintf(buf, "DS18B20.%d", i); logMessage(buf, ds_sensors.getTempCByIndex(i), "Degrees/C"); #ifdef DEBUG_DS18B20_POLLER DEBUG_5("Logged DSB Pin"); #endif } #ifdef DEBUG_DS18B20_POLLER DEBUG_2("Requested Temperatures"); #endif #ifdef DEBUG_DS18B20_POLLER DEBUG_1("Finished"); #endif }
/* Temperature Sensor */ long sensorRoofTempdecic(void) { long value = 0; dallas_roof_sen.requestTemperatures(); value = dallas_roof_sen.getTempCByIndex(0); return value; }
void loop(void) { delay(2000); // call sensors.requestTemperatures() to issue a global temperature // request to all devices on the bus Serial.print("Requesting temperatures..."); sensors.requestTemperatures(); // Send the command to get temperatures Serial.println("DONE"); // Loop through each device, print out temperature data for(int i=0;i<numberOfDevices; i++) { // Search the wire for address if(sensors.getAddress(tempDeviceAddress, i)) { // Output the device ID Serial.print("Temperature for device: "); Serial.println(i,DEC); // It responds almost immediately. Let's print out the data printTemperature(tempDeviceAddress); // Use a simple function to print out the data } //else ghost device! Check your power requirements and cabling } }
/** * @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); }
void readTempHumid() { temperatureSensor.requestTemperatures(); double tempCelcius = temperatureSensor.getTempCByIndex(0); String toDrawTemp = doubleToString(tempCelcius, 2); double humidityVoltage = (double) analogRead(5) / 1024 * REFERENCE_VOLTAGE; double humidityPercentage = (humidityVoltage / REFERENCE_VOLTAGE - 0.16) / 0.0062; double relativeHumidity = humidityPercentage / (1.0546 - 0.00216 * tempCelcius); if(relativeHumidity > 100) relativeHumidity = 100; else if(relativeHumidity < 0) relativeHumidity = 0; String toDrawHumid = doubleToString(relativeHumidity, 2); if(deviceStatus == TEMP_VIEW) { LCD.rectangle(81, 0, 320, 240, BLACK); LCD.tText(7, 6, WHITE, "Temp(C): " + toDrawTemp + "C"); LCD.tText(7, 7, WHITE, "RH%: " + toDrawHumid + "%"); } if(writeToSD) { String toWrite = toDrawTemp + "\t" + toDrawHumid + "\n"; LCD.appendString2File("Data", toWrite); } }
/** * \brief Creates a table with all sensors which are connected via OneWire. * * The table is created on the basis of a previous table which is stored * in the EEPROM. This helps to have a consistent assignment of the sensor ID * to the connected sensor. Otherwise this can change after a reset or if a * sensor is removed. */ error_t createAddressTable(void){ uint8_t address[8]; tempSensorTable.size=0; uint8_t index=0; tempSensorTable_t eepromTable; memset(&tempSensorTable,0,sizeof(tempSensorTable_t)); int8_t deviceCount=sensors.getDeviceCount(); for(int i=0; i<deviceCount; i++){ if(sensors.getAddress(address, i)){ memcpy(tempSensorTable.tableEntry[index].address,address,sizeof(address)); tempSensorTable.tableEntry[index].tempSensorID=i; tempSensorTable.tableEntry[index].enabled=1; //default: send temp sensor value ++index; } } tempSensorTable.size=index; if(!loadAddressTableFromEEPROM(&eepromTable)){ //table found in EEPROM mergeTables(&eepromTable, &tempSensorTable); } writeAddressTableToEEPROM(&tempSensorTable); return ERR_NO_ERR; }
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 }
double Sensor::getDS18B20Reading() { OneWire oneWire(index); DallasTemperature sensor = DallasTemperature(&oneWire); sensor.setResolution(12); sensor.begin(); sensor.requestTemperatures(); return sensor.getTempCByIndex(0); }
void Thermometer::begin() { if (!initialized) { // Start up the library sensors.begin(); sensors.setResolution(thermometerAddress, RESOLUTION); initialized = true; } }
void readData() { Serial.print("Requesting temperatures..."); sensors.requestTemperatures(); // Send the command to get temperatures Serial.println("DONE"); temp = sensors.getTempCByIndex(0); Serial.print("Temperature for Device 1 is: "); Serial.print(temp); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire }
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 }
void updateTemperature() { sensor.requestTemperatures(); tempInCelsius = (int) (sensor.getTempC(devAddr)*10); digitValues[0] = tempInCelsius / 100; digitValues[1] = (tempInCelsius % 100) / 10; digitValues[2] = tempInCelsius % 10; for (int i = 0; i < N-1; i++) display.writeDigit(i, digitValues[i]); }
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(); }
/** * \brief Reads all connected temperature sensors. * * Table: DS18B20 Conversion Times and Resolution Settings * Resolution 9 bit 10 bit 11 bit 12 bit * Conversion Time (ms) 93.75 187.5 375 750 * LSB (°C) 0.5 0.25 0.125 0.0625 * See also: http://www.maximintegrated.com/en/app-notes/index.mvp/id/4377 */ error_t tempSensorRead(void){ sensors.requestTemperatures(); for(int i=0; i<tempSensorTable.size; i++){ if(sensors.isConnected(tempSensorTable.tableEntry[i].address)){ tempSensorTable.tableEntry[i].sensorValue=sensors.getTempC(tempSensorTable.tableEntry[i].address); } else{ tempSensorTable.tableEntry[i].sensorValue=999; } } return ERR_NO_ERR; }
void LogTemps(){ if (!file.open(root, filename, O_CREAT | O_APPEND | O_WRITE)) { //error(“open”); } // write values to the file sensorsa.requestTemperatures(); sensorsb.requestTemperatures(); sensorsc.requestTemperatures(); sensorsd.requestTemperatures(); file.print(now() ); file.print("|"); file.print(sensorsa.getTempCByIndex(0)); file.print("|"); file.print(sensorsb.getTempCByIndex(0)); file.print("|"); file.print(sensorsc.getTempCByIndex(0)); file.print("|"); file.print(sensorsd.getTempCByIndex(0)); file.print("\n"); if (!file.close() || file.writeError){ // error(“close/write”); } }
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; }
float Thermometer::readTemperatureF() { float tempC = (float)DEVICE_DISCONNECTED; this->lastReadingError = true; sensors.requestTemperatures(); tempC = sensors.getTempC(thermometerAddress); if (tempC == (float)DEVICE_DISCONNECTED) { this->lastReadingError = true; } else { this->lastReadingError = false; } return DallasTemperature::toFahrenheit(tempC); }
int sensors_temperature(){ // call temp_sensor.requestTemperatures() to issue a global temperature request to all devices on the bus temp_sensor.requestTemperatures(); // Send the command to get temperatures // call temp_sensor.getTempC to read temperature in degrees Celsius from the device int temperature =(int) temp_sensor.getTempC(insideThermometer); #ifdef DEBUG_SENS softdebug.println(); softdebug.print("Temp C: "); softdebug.println(temperature); #endif return temperature; }
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; }
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(); }
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."); }
int queryDevices(String command) { if(command == "auto") { // sets and prints the device array for(int i=0; i < deviceCount; i++ ) { sensor.getAddress(deviceIndexArray[i], i); Serial.print("Device Index "); Serial.print(i); printAddress(deviceIndexArray[i]); Serial.print("\n"); } Serial.print("----------------------------------\n"); return 1; } if(command == "array" ) { // prints the device Array but does not set it Serial << "Display deviceIndexArray " << endl << "----------------------------------\n" << endl; for ( int i=0; i < 5; i++ ) { Serial << "\n deviceIndexArray[" << i << "]: "; printAddress(deviceIndexArray[i]); } Serial << "\n----------------------------------\n" << endl; } }
//Sensor initializing functions: void OpenGardenClass::initSensors(void){ pinMode(sensorPowerPin, OUTPUT); pinMode(ecPowerPin, OUTPUT); digitalWrite(sensorPowerPin, LOW); digitalWrite(ecPowerPin, LOW); sensors.begin(); dht.begin(); }
/** * \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); }