Project

General

Profile

sketch for DS18B20 (only) to JeeNode v6

Added by sammutj about 5 years ago

hello, I need to experiment with just one DS18B20 connected to a JeeNode (no other sensor or PIR required).

Can you direct me to a sketch that handles this?

NB: I searched a lot on this forum but could not locate a sketch that deals only with DS18B20. I had difficulties trying to modify another sketch that handles other sensors (humidity, PIR, LDR etc)


Replies (6)

RE: sketch for DS18B20 (only) to JeeNode v6 - Added by ozzy about 5 years ago

A search for “arduino ds18b20 library” on Google will do the trick.

RE: sketch for DS18B20 (only) to JeeNode v6 - Added by damonb about 5 years ago

see attached.
This sketch measures the DS18B20 and the battery voltage once per minute.
After it transmits the packet, it goes to back to sleep to save the battery (using @jcw’s lowpower methods).
The battery is assumed to be less than 3.3V for direct sensing on an analogue pin (in my case 1.5V i.e. a single AA via a AA Power Board).
You will need the OneWire library (I used this one: http://www.pjrc.com/teensy/td\_libs\_OneWire.html).
Enjoy!

RE: sketch for DS18B20 (only) to JeeNode v6 - Added by sammutj about 5 years ago

Hello Damonb, thanks for the sketch and links.

I managed to upload the sketch to the Jeenode and can see some results on a separate Arduino MEGA running rf12demo sketch.

I have some questions, maybe you can help:

  1. This is a typical reading I am receiving :

OK 4 30 0 0 0 42 1 100

I understand that the first digit “4” is the node ID and “30” means the 30th reading. I assume “0 0 0” are related to the battery voltage reading and “42 1 100” are related to the DS18B20 reading.
How do i convert “42 1 100” in actual temperature in degrees celcius?

  1. I am running the Jeenode using USB BUBII, so power to the processor is 3.3 Volts. To test the battery voltage reading, I connected a potentiometer as follows: ends to Gnd and 3.3V, and wiper to A input of Port 2. I set the potentiometer to get a voltage of 1 volt. However as you can see in the received packet, the data remains “0 0 0”. What do you think is wrong?

  2. One line of the sketch is “#define SEND_MODE 2 // set to 3 if fuses are e=06/h=DE/l=CE, else set to 2”
    What are these mentioned fuses?

Thank you.

RE: sketch for DS18B20 (only) to JeeNode v6 - Added by sammutj about 5 years ago

In the mean time i discovered how to answer question 1.

“42 1 100” means 0142 Hex, which would mean = 322 decimal = 00000001 01000010 binary = 20.125 degrees celcius.

maybe you help me answer questions 2 and 3.

RE: sketch for DS18B20 (only) to JeeNode v6 - Added by damonb about 5 years ago

You are on the right track but not quite there yet.
If you look into the sketch you will find a ‘struct’ that defines the content of the packets sent out by the radio.
The first component of the struct is an unsigned 32-bit integer (‘uint32_t’ i.e. 4 bytes) for the packet sequence number.
Then an ‘int’ (16 bits i.e. 2 bytes) for the temperature value.
Then a single byte for the battery voltage.
The RF12Demo output is just a decimal representation of each byte, not hex, so interpret the output like this:
OK means the packet passed the CRC check.
4 is the packet header byte.
Then comes the actual packet payload as follows:
30 0 0 0 is the 4 bytes of the packet sequence number, LSB first (sometimes referred to as “little endian”).
42 1 is the 2 bytes for the temperature direct from the DS18B20… 42 + (1 * 256) = 298 decimal - as per the DS18B20 datasheet, divide this by 16 to get degrees C = 18.625
100 is the battery voltage (volts * 100) = 1.00 volts.

It sounds like you are just starting out with jeenode/arduino code.
I highly recommend you trawl through @jcw’s JeeLabs blog: it’s a gold mine where you will find all of this explained and much more besides.
For example, for an explanation of the jeenode RF12 packet header byte see this page: http://jeelabs.org/2011/06/10/rf12-broadcasts-and-acks/
(hint: 4 is indeed the node id, but there are 3 other bits there that just happen to be zero in your example)
But a warning: once you start reading the blog it’s difficult to stop! ;-)

RE: sketch for DS18B20 (only) to JeeNode v6 - Added by damonb about 5 years ago

P.S. re Q 3:
Search the code to see where the SEND_MODE is used…
Find it in a call to

rf12_sendWait(SEND_MODE);

…. then look up the definition of rf12_sendWait() in the doco here: http://jeelabs.net/pub/docs/jeelib/md\_intro\_rf12.html
voila!

    (1-6/6)