Hi,
Does anyone have some pointers for me? I'm trying to read temperature readings from 4x DS18B20 sensors, connected to a LinkIt One. There's a 4.7K resistor between the data line and 5V+ from the LinkIt One. With a seperate Volt meter, I can see the volts on the "bus" is between 4.7V and 5.5V, while connected to the USB port on my laptop. Using the 3.3V pin on the LinkIt One does the same, through voltages range from 3.8V to 4.1V on the Volt meter.
I have tried numerous sketches but they all have the same symptoms. Sometimes I get readings, sometimes not.
Here is one such sample:
// This Arduino sketch reads DS18B20 "1-Wire" digital
// temperature sensors.
// Copyright (c) 2010 Mark McComb, hacktronics LLC
// License: http://www.opensource.org/licenses/mit-license.php (Go crazy)
// Tutorial:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 10
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Assign the unique addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
DeviceAddress GarageTemp = { 0x28, 0x50, 0x00, 0xA0, 0x07, 0x00, 0x00, 0xE3 };
DeviceAddress PVTemp = { 0x28, 0x78, 0xCA, 0xA1, 0x07, 0x00, 0x00, 0xE4 };
DeviceAddress UnderPVTemp = { 0x28, 0x52, 0xCA, 0xA0, 0x07, 0x00, 0x00, 0x12 };
DeviceAddress GarageRoofTemp = { 0x28, 0xEB, 0x92, 0x65, 0x05, 0x00, 0x00, 0xDF };
void setup(void)
{
// start serial port
Serial.begin(9600);
// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(GarageTemp, 6);
sensors.setResolution(PVTemp, 6);
sensors.setResolution(UnderPVTemp, 12);
sensors.setResolution(GarageRoofTemp, 12);
}
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
// if (tempC == -127.00) {
// Serial.print("Error getting temperature");
// } else {
Serial.print("C: ");
Serial.print(tempC);
// }
}
void loop(void)
{
delay(1000);
Serial.print("Getting temperatures...\n\r");
sensors.requestTemperatures();
Serial.print("Garage temperature is: ");
printTemperature(GarageTemp);
Serial.print("\n\r");
Serial.print("Garage Roof temperature is: ");
printTemperature(GarageRoofTemp);
Serial.print("\n\r");
Serial.print("PV temperature is: ");
printTemperature(PVTemp );
Serial.print("\n\r");
Serial.print("Under PV Temp is: ");
printTemperature(UnderPVTemp);
Serial.print("\n\r\n\r");
}
Serial console output:
// This Arduino sketch reads DS18B20 "1-Wire" digital
// temperature sensors.
// Copyright (c) 2010 Mark McComb, hacktronics LLC
// License: The MIT License | Open Source Initiative (Go crazy)
// Tutorial:
// Arduino 1-Wire Tutorial#include <OneWire.h>
#include <DallasTemperature.h>// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 10// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);// Assign the unique addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// Arduino 1-Wire Address FinderDeviceAddress GarageTemp = { 0x28, 0x50, 0x00, 0xA0, 0x07, 0x00, 0x00, 0xE3 };
DeviceAddress PVTemp = { 0x28, 0x78, 0xCA, 0xA1, 0x07, 0x00, 0x00, 0xE4 };
DeviceAddress UnderPVTemp = { 0x28, 0x52, 0xCA, 0xA0, 0x07, 0x00, 0x00, 0x12 };
DeviceAddress GarageRoofTemp = { 0x28, 0xEB, 0x92, 0x65, 0x05, 0x00, 0x00, 0xDF };void setup(void)
{
// start serial port
Serial.begin(9600);
// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(GarageTemp, 6);
sensors.setResolution(PVTemp, 6);
sensors.setResolution(UnderPVTemp, 12);
sensors.setResolution(GarageRoofTemp, 12);
}void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
// if (tempC == -127.00) {
// Serial.print("Error getting temperature");
// } else {
Serial.print("C: ");
Serial.print(tempC);
// }
}void loop(void)
{
delay(1000);
Serial.print("Getting temperatures...\n\r");
sensors.requestTemperatures();Serial.print("Garage temperature is: ");
printTemperature(GarageTemp);
Serial.print("\n\r");
Serial.print("Garage Roof temperature is: ");
printTemperature(GarageRoofTemp);
Serial.print("\n\r");
Serial.print("PV temperature is: ");
printTemperature(PVTemp );
Serial.print("\n\r");
Serial.print("Under PV Temp is: ");
printTemperature(UnderPVTemp);
Serial.print("\n\r\n\r");
}