Hi PaulS
Still having problems with wireless comms between Uno (Tx) & Mega2560 (Rx); can you help please?
Tx from Uno seems OK but Rx on Mega doesn't report same temps as Tx'd
I'm running 8 DS18B20 sensors but hope to run more
Tx part (Rx to follow)
Thanks
//ONLY RUNS UNDER ARDUINO 1.0
//Arduino Uno as transmitter
/* YourDuino Multiple DS18B20 Temperature Sensors on 1 wire
Connections:
DS18B20 Pinout (Left to Right, pins down, flat side toward you)
- Left = Ground
- Center = Signal (Pin 2): (with 3.3K to 4.7K resistor to +5 or 3.3 )
- Right = +5 or +3.3 V
Questions: terry@yourduino.com
V1.01 01/17/2013 ...based on examples from Rik Kretzinger
/*-----( Import needed libraries )-----*/
// Get 1-wire Library here: http://www.pjrc.com/teensy/td_libs_OneWire.html
#include <OneWire.h>
//Get DallasTemperature Library here: http://milesburton.com/Main_Page?title=Dallas_Temperature_Control_Library
#include <DallasTemperature.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define ONE_WIRE_BUS_PIN 7
/*-----( Declare objects )-----*/
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS_PIN);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
/*-----( Declare Variables )-----*/
// Assign the 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 Probe00 = { 0x28, 0x18, 0x64, 0xAA, 0x04, 0x00, 0x00, 0xC6 };
DeviceAddress Probe01 = { 0x28, 0xE6, 0x4F, 0x08, 0x03, 0x00, 0x00, 0xFB };
DeviceAddress Probe02 = { 0x28, 0x7A, 0x60, 0x08, 0x03, 0x00, 0x00, 0xA0 };
DeviceAddress Probe03 = { 0x28, 0x9A, 0x47, 0xAA, 0x04, 0x00, 0x00, 0xF4 };
DeviceAddress Probe04 = { 0x28, 0x55, 0x52, 0xAA, 0x04, 0x00, 0x00, 0xE1 };
DeviceAddress Probe05 = { 0x28, 0xD8, 0x34, 0xAB, 0x04, 0x00, 0x00, 0x43 };
DeviceAddress Probe06 = { 0x28, 0x53, 0x44, 0xAA, 0x04, 0x00, 0x00, 0xB3 };
DeviceAddress Probe07 = { 0x28, 0x5B, 0x70, 0xAA, 0x04, 0x00, 0x00, 0x89 };
DeviceAddress Probe08 = { 0x28, 0x18, 0x76, 0xAB, 0x04, 0x00, 0x00, 0xB6 };
DeviceAddress Probe09 = { 0x28, 0xA3, 0x75, 0xAB, 0x04, 0x00, 0x00, 0x07 };
DeviceAddress Probe10 = { 0x28, 0xA3, 0xE6, 0xAA, 0x04, 0x00, 0x00, 0x71 };
//End of 1-wire initialisation
/*
* Simplest possible example of using RF24Network
*
* TRANSMITTER NODE
* Every 2 seconds, send a payload to the receiver node.
*/
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
// nRF24L01(+) radio attached using Getting Started board
RF24 radio(9,10); //CE, CSN connections on NRF24L01 board for Uno
// Network uses that radio
RF24Network network(radio);
// Address of our node
const uint16_t this_node = 1;
// Address of the other node
const uint16_t other_node = 0;
// How often to send 'hello world to the other unit
const unsigned long interval = 1000; //ms
// When did we last send?
unsigned long last_sent;
// How many have we sent already
unsigned long packets_sent;
// Structure of our payload
struct payload_t
{
byte data;
};
//End of nRF24L01 initialisation
void setup() /****** SETUP: RUNS ONCE ******/
{
// start serial port to show results
Serial.begin(9600);
Serial.print("Initializing Temperature Control Library Version ");
Serial.println(DALLASTEMPLIBVERSION);
// Initialize the Temperature measurement library
sensors.begin();
// set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
//9>>0.5C steps, 10>>0.25C steps, 11>>0.125C steps, 12>>0.06C steps
sensors.setResolution(Probe00, 10);
sensors.setResolution(Probe01, 10);
sensors.setResolution(Probe02, 10);
sensors.setResolution(Probe03, 10);
sensors.setResolution(Probe04, 10);
sensors.setResolution(Probe05, 10);
sensors.setResolution(Probe06, 10);
sensors.setResolution(Probe07, 10);
sensors.setResolution(Probe08, 10);
sensors.setResolution(Probe09, 10);
sensors.setResolution(Probe10, 10);
Serial.println("RF24Network/examples/helloworld_tx/");
SPI.begin();
radio.begin();
network.begin(/*channel*/ 90, /*node address*/ this_node);
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
delay(2000);
Serial.println();
Serial.print("Number of Devices found on bus = ");
Serial.println(sensors.getDeviceCount());
Serial.print("Getting temperatures... ");
Serial.println();
// Command all devices on bus to read temperature
sensors.requestTemperatures();
Serial.print("Probe 00 temperature is: ");
printTemperature(Probe00);
Serial.println();
Serial.print("Probe 01 temperature is: ");
printTemperature(Probe01);
Serial.println();
Serial.print("Probe 02 temperature is: ");
printTemperature(Probe02);
Serial.println();
Serial.print("Probe 03 temperature is: ");
printTemperature(Probe03);
Serial.println();
Serial.print("Probe 04 temperature is: ");
printTemperature(Probe04);
Serial.println();
Serial.print("Probe 05 temperature is: ");
printTemperature(Probe05);
Serial.println();
Serial.print("Probe 06 temperature is: ");
printTemperature(Probe06);
Serial.println();
Serial.print("Probe 07 temperature is: ");
printTemperature(Probe07);
Serial.println();
// Pump the network regularly
network.update();
// If it's time to send a message, send it!
unsigned long now = millis();
if ( now - last_sent >= interval )
{
last_sent = now;
//The union
union stuff
{
int temps[8];
byte data[16];
};
//An instance
int temp0 = (sensors.getTempCByIndex(00)); //used for testing
int temp1 = (sensors.getTempCByIndex(01)); //used for testing
int temp2 = (sensors.getTempCByIndex(02)); //used for testing
int temp3 = (sensors.getTempCByIndex(03)); //used for testing
int temp4 = (sensors.getTempCByIndex(04)); //used for testing
int temp5 = (sensors.getTempCByIndex(05)); //used for testing
int temp6 = (sensors.getTempCByIndex(06)); //used for testing
int temp7 = (sensors.getTempCByIndex(07)); //used for testing
stuff myStuff;
//Get the temperatures, and store them
myStuff.temps[0] = temp0;
myStuff.temps[1] = temp1;
myStuff.temps[2] = temp2;
myStuff.temps[3] = temp3;
myStuff.temps[4] = temp4;
myStuff.temps[5] = temp5;
myStuff.temps[6] = temp6;
myStuff.temps[7] = temp7;
Serial.print("Sending...");
Serial.print(myStuff.temps[0]);
payload_t payload = { /*millis(), packets_sent++,*/myStuff.data[16]};
RF24NetworkHeader header(/*to node*/ other_node);
bool ok = network.write(header,&payload,sizeof(payload));
if (ok)
Serial.println("ok.");
else
Serial.println("failed.");
}
// vim:ai:cin:sts=2 sw=2 ft=cpp
//The payload to send, then, is myStuff.data, with a size of 12 bytes.
//On the other end, you'd use myStuff.data as the receive buffer and read the values using myStuff.temps[n] to get the nth temperature.
}//--(end main loop )---
/*-----( Declare User-written Functions )-----*/
void printTemperature(DeviceAddress deviceAddress)
{
int tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00)
{
Serial.print("Error getting temperature ");
}
else
{
Serial.print("C: ");
Serial.print(tempC);
Serial.print(" F: ");
Serial.print(DallasTemperature::toFahrenheit(tempC));
}
}// End printTemperature
//*********( THE END )***********