/** * \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 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]); }
/** * \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; }
// function to print the temperature for a device void printTemperature(DeviceAddress deviceAddress) { // method 1 - slower //Serial.print("Temp C: "); //Serial.print(sensors.getTempC(deviceAddress)); //Serial.print(" Temp F: "); //Serial.print(sensors.getTempF(deviceAddress)); // Makes a second call to getTempC and then converts to Fahrenheit // method 2 - faster float tempC = sensors.getTempC(deviceAddress); Serial.print("Temp C: "); Serial.print(tempC); Serial.print(" Temp F: "); Serial.println(DallasTemperature::toFahrenheit(tempC)); // Converts tempC to Fahrenheit }
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; }
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); }
void loop() { File dataFile; //String dataString; //char dataToSD[40]; //String timeString; char tempstring[10]; // create string arrays //float temp; static int WaitingForTemp = 0; //int readCount; DateTime now; // = rtc.now(); static int nowriting = 0; delay(1000); switch(system_FSM) { case S_IDLE: //Read time from RTC now = rtc.now(); if(now.minute() % 11 == 0) nowriting = 0; //Trigger state change if(WaitingForTemp == 1){ if (millis() - lastTempRequest >= delayInMillis) // waited long enough?? system_FSM = S_READ_SENS; } if(WaitingForTemp == 0) { system_FSM = S_TRIG_TEMP; if(now.minute() % 10 == 0 || nowriting == 0) system_FSM = S_WRITE_SD; nowriting = 1; } break; case S_TRIG_TEMP: // Trig async reading of DS1820 temp sensor sensors.requestTemperatures(); // remember time of trigger lastTempRequest = millis(); WaitingForTemp = 1; system_FSM = S_IDLE; break; case S_READ_SENS: //read value of sensors SensorData.sensor1 = sensors.getTempC(Sensor1); SensorData.sensor2 = sensors.getTempC(Sensor2); //SensorData.sensor1 = sensors.getTempC(Sensor1); //SensorData.sensor1 = sensors.getTempC(Sensor1); //SensorData.sensor1 = sensors.getTempC(Sensor1); WaitingForTemp = 0; system_FSM = S_IDLE; /* if(readCount == 0) system_FSM = S_WRITE_SD; else system_FSM = S_IDLE; readCount++; */ break; case S_WRITE_SD: // Read time and date from RTC TimeDate(rtc.now(),dateTimeString,1); // Open datafile dataFile = SD.open("templog.txt", FILE_WRITE); // Write values to SD card if (dataFile) { dataFile.print(dateTimeString); dataFile.print(";"); dataFile.print(SensorData.sensor1); dataFile.print(";"); dataFile.println(SensorData.sensor2); dataFile.close(); } // state change to IDLE system_FSM = S_IDLE; break; default: system_FSM = S_IDLE; } switch(menu_FSM) { case M_PAGE1: if(menu_FSM !=menu_last_state) { DisplayClear(); mySerial.write("Time"); // clear display + legends MenuShowTime = millis(); } now = rtc.now(); DisplayGoto(1,0); mySerial.write("Time"); // clear display + legends DisplayGoto(1,8); TimeDate(now,dateTimeString,2); mySerial.print(dateTimeString); DisplayGoto(2,6); TimeDate(now,dateTimeString,3); mySerial.print(dateTimeString); //reserved for showing time and SD card status menu_last_state = M_PAGE1; if(millis() - MenuShowTime >= MenuDelayInMillis) menu_FSM = M_PAGE2; break; case M_PAGE2: if(menu_FSM !=menu_last_state) { DisplayClear(); mySerial.write("Sens 1: C"); mySerial.write("Sens 2: C"); DisplayGoto(1,14); mySerial.write(223); DisplayGoto(2,14); mySerial.write(223); MenuShowTime = millis(); } DisplayGoto(1,10); mySerial.write(dtostrf(SensorData.sensor1,4,1,tempstring)); // write out the RPM value DisplayGoto(2,10); mySerial.write(dtostrf(SensorData.sensor2,4,1,tempstring)); // write out the TEMP value //mySerial.write(dtostrf(system_FSM,4,1,tempstring)); DEBUG menu_last_state = M_PAGE2; if(millis() - MenuShowTime >= MenuDelayInMillis) menu_FSM = M_PAGE3; break; case M_PAGE3: if(menu_FSM !=menu_last_state) { DisplayClear(); mySerial.write("Sens 3: N/A C"); // clear display + legends mySerial.write("Sens 4: N/A C"); DisplayGoto(1,14); mySerial.write(223); DisplayGoto(2,14); mySerial.write(223); MenuShowTime = millis(); } DisplayGoto(1,7); // mySerial.write(dtostrf(SensorData.sensor1,4,1,tempstring)); // write out the RPM value DisplayGoto(2,7); //mySerial.write(dtostrf(MenuShowTime,4,1,tempstring)); // write out the TEMP value menu_last_state = M_PAGE3; if(millis() - MenuShowTime >= MenuDelayInMillis) menu_FSM = M_PAGE1; break; case M_PAGE4: break; default: menu_FSM = M_PAGE1; } }
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); } } }
/* * Main Loop */ void loop() { wdt_reset(); mD.vals.uslCount++; //Increment main datarecord count AccelerometerScaled Ascaled = accel.ReadScaledAxis(); //Get Scaled Accelerometer AccelerometerRaw Araw = accel.ReadRawAxis(); //Get Raw Accelerometer MagnetometerScaled Mscaled = compass.ReadScaledAxis(); //Get Scaled Magnetometer MagnetometerRaw Mraw = compass.ReadRawAxis(); //Get Raw Magnetometer LGgyro.read(); //Get Gyro // offset compass by hard iron Mraw.XAxis += 40; Mraw.YAxis += 261; Mraw.ZAxis += 54; //write Acc, Mag, & Gyro values to record float AxisGs = Ascaled.XAxis; mD.vals.AcXPayload = AxisGs * 100; AxisGs = Ascaled.YAxis; mD.vals.AcYPayload = AxisGs * 100; AxisGs = Ascaled.ZAxis; mD.vals.AcZPayload = AxisGs * 100; mD.vals.MgXPayload = Mscaled.XAxis; mD.vals.MgYPayload = Mscaled.YAxis; mD.vals.MgZPayload = Mscaled.ZAxis; mD.vals.GyXPayload = LGgyro.g.x; mD.vals.GyYPayload = LGgyro.g.y; mD.vals.GyZPayload = LGgyro.g.z; //Perform tilt compensation calculation save to record sixDOF.compCompass(Mraw.XAxis, -Mraw.YAxis, -Mraw.ZAxis, Araw.XAxis, Araw.YAxis, Araw.ZAxis, true); float compHeading = sixDOF.atan2Int(sixDOF.xAxisComp(), sixDOF.yAxisComp()); compHeading = compHeading /100; if (compHeading < 0 ) { compHeading = abs(compHeading); } else { compHeading = 180 - compHeading + 180; } mD.vals.CmpssPayload = compHeading; //get BMP085 values save to record dps.getTemperature(&TmpPayloadFULL); dps.getPressure(&mD.vals.PressurePayload); mD.vals.TmpPayload = (int16_t)(TmpPayloadFULL); mD.vals.TmpExternal = (int16_t)(sensors.getTempC(outsideThermometer)* 10); sensors.requestTemperaturesByAddress(outsideThermometer); // Send the command to get temperatures //get GPS data byte lcount = 0; //reset a loop counter while (!NEWGPSDATA && lcount++ < 255) { //Exit the loop if we have new data or have been round it a number of times NEWGPSDATA = feedgps(); } if (NEWGPSDATA) { //We have new GPS data, get all of the fields we need. int tmp_year = 0; gps.crack_datetime(&tmp_year, &mD.vals.month, &mD.vals.day,&mD.vals.hour, &mD.vals.minute, &mD.vals.second, &mD.vals.hundredths, &mD.vals.age); mD.vals.year = tmp_year - 2000; if (gps.altitude() != TinyGPS_HJOE::GPS_INVALID_ALTITUDE && gps.altitude() >= 0) { gps.get_position(&mD.vals.iLat, &mD.vals.iLong, &mD.vals.age); mD.vals.iAlt = gps.altitude(); mD.vals.iAngle = gps.course(); mD.vals.iHspeed = gps.speed(); mD.vals.bSats = gps.satellites(); mD.vals.ihdop = gps.hdop(); } SET_LED_Status(SET_LED_BLUE,0); //Flash blue to show we are getting GPS data } else { SET_LED_Status(SET_LED_GREEN,0); //Flash Green to show that we are looping but not getting GPS data } if(ETSerialIn.receiveData()){ } //flip flop between I2C's to avoid both on one loop if (SENDWIRE && (millis() - elapseSIM900) > WAIT_SIM900) { mD.vals.tCount++; ETI2Cout.sendData(I2C_SLV_SIM900_ADDRESS); elapseSIM900 = millis(); } if (!SENDWIRE && (millis() - elapseNTXB) > WAIT_NTXB) { mD.vals.tCount++; ETI2Cout.sendData(I2C_SLV_NTXB_ADDRESS); elapseNTXB = millis(); //get I2C_SLV_SIM900_ADDRESS data } writeSDData(); //Write the data record to the SD card SET_LED_Status(SET_LED_OFF,0); //turn off the LED NEWGPSDATA = false; //Reset the New GPS Data flag SENDWIRE = !SENDWIRE; //Flipflop this }
void update18B20Temp(DeviceAddress deviceAddress, double &tempC) { tempC = sensors.getTempC(deviceAddress); }
void loop() { delay(1000); sensors.requestTemperatures(); float tempO = sensors.getTempC(outsideThermometer); float tempI = sensors.getTempC(insideThermometer); if (tempO == -127.00) { Serial.print("Error getting temperature"); } else { // Serial.print(" C: "); // Serial.println(tempC); } // build the timestamp chronodot.readTimeDate(); String timeStamp = ""; int yearZ = chronodot.timeDate.year; timeStamp += yearZ; timeStamp += "-"; int monthZ = chronodot.timeDate.month; if (monthZ < 10) timeStamp += "0"; timeStamp += monthZ; timeStamp += "-"; int dayZ = chronodot.timeDate.day; if (dayZ < 10) timeStamp += "0"; timeStamp += dayZ; timeStamp += ","; int hourZ = chronodot.timeDate.hours; if (hourZ < 10) timeStamp += "0"; timeStamp += hourZ; timeStamp += ":"; int minZ = chronodot.timeDate.minutes; if (minZ < 10) timeStamp += "0"; timeStamp += minZ; timeStamp += ":"; int secZ = chronodot.timeDate.seconds; if (secZ < 10) timeStamp += "0"; timeStamp += secZ; timeStamp += ":"; // open the log file and append the data row. File dataFile = SD.open("HAPPy_data.txt", FILE_WRITE); if (dataFile) { dataFile.print(timeStamp); dataFile.print(","); dataFile.print(tempO); dataFile.print(","); dataFile.print(tempI); dataFile.println(","); // close the log file... dataFile.close(); // print to the serial port too: Serial.println(timeStamp); Serial.print("Outside Temperature: "); Serial.println(tempO); Serial.print("Inside Temperature: "); Serial.println(tempI); Serial.println(); } // if the file isn't open, pop up an error: else { Serial.println("Shizzle! Error opening log file..."); } }