This is an old revision of the document!
This tutorial demonstrates how to use the Oak to read temperature data from the DS18B20 1-Wire Digital Thermometer and publish that data to the Particle.io Dashboard log. It will also demonstrate how to use the deep sleep capability of the Oak platform to minimize power requirements (if desired) between temperature readings.
The 1-Wire DS18B20 digital thermometer can operate at either 3.3 volts or 5 volts. Since the Oak is a 3.3V device, in this tutorial we will use the 3.3V supplied by the Oak's VCC 3.3V pin to power the DS18B20. The DS18B20 Data Input/Output lead (DQ) must be pulled up to 3.3V using a 4.7K resister. While the DS18B20 does support a parasitic mode, this will not be demonstrated in this tutorial. Parasitic mode does not require the DS18B20 VDD lead to be connected to external power, but it does require a strong pullup on the 1-Wire bus. To learn more about operating the DS18B20 in parasitic mode, see the DS18B20 device data sheet (https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf).
The provided example sketch (see below) uses the Particle.io function Particle.publish() to post temperature readings to the particle.io Dashboard log. In order to do this you must have an active Particle.io account, a functional Oak running the latest firmware, and that Oak claimed as an active device on Particle.io.
The actual command used is: Particle.publish(“Temp (F)”, tempFstring, 60, PRIVATE); where “Temp(F): is the event name and tempFstring is the actual temperature reading in string format.
For more information and other examples for how to use the Particle.publish function and other Particle device firmware Cloud functions, see https://docs.particle.io/reference/firmware/core/
The Oak is capable of entering a deep sleep to minimize power requirements. This may be desirable if, for example, your Oak will be battery powered. The provided example sketch demonstrates this mode of operation but will also support operating in a non-sleeping mode.
To indicate to the sketch that sleep mode is desired, we use pin 5 (pulled HIGH) as essentially as “switch”. If pin 5 is HIGH when read in setup(), the sketch operate in sleep mode. This will be considered the default operating mode and as such pin 5 will be defined as INPUT_PULLUP.
To facilitate the Oak's deep sleep and wake-up capabilities, you must also connect pin 10 (WAKE) to the reset (RST) pin. This allows the Oak to trigger a RESET after a user specified sleep period has expired. While in sleep mode, the sketch will enter and run setup after each time a RESET occurs. In this mode it never enters loop().
If you prefer to operate the Oak in non-sleep mode, or if you want to prevent it from sleeping (when in sleep mode) to allow for new sketch uploads, pin 5 simple needs to be connected to ground (GND) thus pulling pin 5 LOW. When pin 5 is LOW at power up the sketch will not sleep and does enter loop() where it remains and repeatedly reads and publishes data from the DS18B20 device. This mode consumes more power than does operating in a sleep mode.
If pin 5 is HIGH at power up (sleep mode), the example sketch will stay in sleep mode as long as pin 5 remains HIGH. If at anytime pin 5 is pulled LOW, the sketch will enter non-sleep mode following the next RESET. Once in non-sleep mode, it will remain in this mode at long as the Oak is powered up regardless of the state of pin 5 (HIGH or LOW).
In Sleep Mode (after reading and publishing temperature data) the Oak enters deep sleep and delays for a user specified number of seconds. When sleep time has expired, a RESET is triggered via pin 10 (WAKE). Following a RESET, the sketch starts from the beginning and never enters loop().