Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <OneWire.h>
- OneWire ds(8); // DS18x20 Temperature chip i/o One-wire
- OneWire ds1(12);
- //Tempsensor variables
- byte address0[8] = {0x10, 0xB6, 0xBE, 0x30, 0x2, 0x8, 0x0, 0xD2}; // External DS18B20 GPS Sensor 28 73 CD F5 2 0 0 AE
- byte address1[12] = {0x10, 0x6E, 0xBD, 0x30, 0x2, 0x8, 0x0, 0xF9};
- int temp0 = 0, temp1 =0;
- // gets temperature data from onewire sensor network, need to supply byte address, it'll check to see what type of sensor and convert appropriately
- int getTempdata(byte sensorAddress[8]) {
- int HighByte, LowByte, TReading, SignBit, Tc_100, Whole;
- byte data[12], i, present = 0;
- ds.reset();
- ds.select(sensorAddress);
- ds.write(0x44,1); // start conversion, with parasite power on at the end
- delay(3000); // maybe 750ms is enough, maybe not
- // we might do a ds.depower() here, but the reset will take care of it.
- present = ds.reset();
- ds.select(sensorAddress);
- ds.write(0xBE); // Read Scratchpad
- for ( i = 0; i < 9; i++) { // we need 9 bytes
- data[i] = ds.read();
- }
- LowByte = data[0];
- HighByte = data[1];
- TReading = (HighByte << 8) + LowByte;
- SignBit = TReading & 0x8000; // test most sig bit
- if (SignBit) // negative
- {
- TReading = (TReading ^ 0xffff) + 1; // 2's comp
- }
- if (sensorAddress[0] == 0x10) {
- Tc_100 = TReading * 50; // multiply by (100 * 0.0625) or 6.25
- }
- else {
- Tc_100 = (6 * TReading) + TReading / 4; // multiply by (100 * 0.0625) or 6.25
- }
- Whole = Tc_100 / 100; // separate off the whole and fractional portions
- if (SignBit) // If its negative
- {
- Whole = Whole * -1;
- }
- return Whole;
- }
- void setup(void) {
- // initialize inputs/outputs
- // start serial port
- Serial.begin(9600);
- }
- void loop(void) {
- temp0 = getTempdata(address0);
- temp1 = getTempdata(address1);
- char msg[100];
- snprintf(msg, 100, "Internal Temperature: %i\n", "External Temperature: %i\n", temp0, temp1);
- Serial.print(msg);
- }
Advertisement
Add Comment
Please, Sign In to add comment