Hi forum users i've been learning the arduino for about 3 or 4 months and I'm a novice to be fair, I would like to view data on xively from my arduino hooked up with two ds18b20 sensors, I have managed to write the code it works , but gives me two temperatures based on just one sensor, rather than two, im not sure which of the code needs changing to differentiate between the two sensors, they are on the same one wire bus, but both have seperate addresses, anyone had any joy doing this? or can help me with the correct programming, here is the code to look through :
#include <SPI.h>
#include <Ethernet.h>
#include <HttpClient.h>
#include <Xively.h>
#include <OneWire.h>
#include <DallasTemperature.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC address for your Ethernet shield
char xivelyKey[] = "wq9o8rrgKNp8cDPOhntuHzwsdUOjkiPnWFf5IIAS6qncLYXW"; // Your Xively key to let you upload data
#define ONE_WIRE_BUS 3 //data wire is plugged into pin 3 on the Arduino
#define TEMPERATURE_PRECISION 12
OneWire oneWire(ONE_WIRE_BUS); //Setup a oneWire instance to communicate with any OneWire devices.
DallasTemperature sensors(&oneWire); //pass our oneWire reference to the Dallas Temperature.
DeviceAddress TEMP1 ={ 0x28, 0xE8, 0x74, 0xB3, 0x05, 0x00, 0x00, 0xC8 }; // address of sensor on one wire bus
DeviceAddress TEMP2 ={ 0x28, 0xA0, 0xCF, 0xF8, 0x04, 0x00, 0x00, 0xFC }; // address of sensor 2 on one wire bus
char sensorId0[] = "Temp_reading_1"; // Define the strings for our datastream IDs
char sensorId1[] = "Temp_reading_2"; // Define the strings for our datastream IDs
XivelyDatastream datastreams[] = {
XivelyDatastream(sensorId0, strlen(sensorId0), DATASTREAM_FLOAT),
XivelyDatastream(sensorId1, strlen(sensorId1), DATASTREAM_FLOAT),
};
XivelyFeed feed(55082926, datastreams, 2 /* number of datastreams */); // Finally, wrap the datastreams into a feed
EthernetClient client;
XivelyClient xivelyclient(client);
void setup() {
Serial.begin(9600); // put your setup code here, to run once:
Serial.println("Starting single datastream upload to Xively...");
Serial.println();
while (Ethernet.begin(mac) != 1)
{
Serial.println("Error getting IP address via DHCP, trying again...");
delay(15000);
}
sensors.begin();
sensors.setResolution(TEMP1, TEMPERATURE_PRECISION);
sensors.setResolution(TEMP2, TEMPERATURE_PRECISION);
}
void loop() {
sensors.requestTemperatures();
int sensorValue = (sensors.getTempCByIndex(0)); //this is teh code from MBurton
datastreams[0].setFloat(sensorValue);
datastreams[1].setFloat(sensorValue);
Serial.print("Read sensor value ");
Serial.println(datastreams[0].getFloat());
Serial.print("Read sensor value ");
Serial.println(datastreams[1].getFloat());
Serial.println("Uploading it to Xively");
int ret = xivelyclient.put(feed, xivelyKey);
Serial.print("xivelyclient.put returned ");
Serial.println(ret);
Serial.println();
delay(1000);
}
Any help will be greatly appreciated