You can wire up 1-Wire devices in two modes parasitic powered and externally powered
- Parasitic power lets you have all data and power on a single data line + ground wire. Its more minimal but we believe it is a little more sensitive to power fluctuations
- Externally powered has data on the single data line + ground wire, and then a separate power supply. It requires more wires but we think it is more stable in readings.
We show 2 sensor boards in these photos, but you can connect as many as you like, 1-Wire supports any number of shared devices on a single data line.
External power
In this wiring style, each board is powered externally. Connect:-
GND to the Arduino Ground pin (black wires)
-
Vin to the Arduino 5V pin (can also connect to an external battery of 3-5VDC) (red wires)
-
Data shared connection to A1 on the level converter (green wire)
- A single 4.7K resistor connects from the shared data line to 3V
-
B1 of the level converter connects to Arduino #2 (blue wire)
- Level shifter HV connects to Arduino 5V (red wire)
- Level shifter LV connects to Arduino 3V (yellow wire)
Parasitic Power
Alternatively you can use parasitic power to connect up MAX31850's - to do that basically follow the above except do not connect the VIN wires on the breakout boards
- GND to the Arduino Ground pin (black wires)
- Vin does not get connected
- Data shared connection to A1 on the level converter (green wire)
- A single 4.7K resistor connects from the shared data line to 3V
-
B1 of the level converter connects to Arduino #2 (blue wire)
- Level shifter HV connects to Arduino 5V (red wire)
- Level shifter LV connects to Arduino 3V (yellow wire)
If you have the sensor far from the Arduino, you can extend the Data and GND lines going to each sensor by up to 10 meters!
Download Arduino libraries
For 1-Wire devices, we'll be using the OneWire library and a modified version of the DallasTemp library (Dallas was the name of the original company making 1-Wire devices, Maxim bought them later)
The original version of the DallasTemp library doesn't have support for the MAX31850, so we had to modify it! If you're having difficulty sensing the breakout sensors make sure you have completely removed any old copies of the libraries from your libraries and replaced them with ours
Start by downloading both OneWire and DallasTemp libraries from the GitHub repositories, or better yet, just click these buttons here:
Place the OneWire library folder your sketchbookfolder/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE. You can figure out your sketchbookfolder by opening up the Preferences tab in the Arduino IDE.
If you're not familiar with installing Arduino libraries, please visit our tutorial: All About Arduino Libraries!Place the DallasTemp library folder in your sketchbookfolder/libraries/ folder like you did with OneWire - and restart the IDE
First up, you should see how many sensors were detected. In our case its 2
External vs Parasite power
Here is the same setup under external power. The temperature is much closer to the true temp (room temp, about 72 degrees F) because the power supply is more stable. If you are using parasite power you may need to calculate the temperature offset (calibrating the sensor) to get the true sensor at the location.
Writing your own sketch
OneWire and DallasTemp are very powerful but for most people, they just want to get temperatures printed out in their project!
Here is some super-basic code based on the Simple example to handle any number of sensors, simply printing out the temperature and the last two bytes of the unique ID number. You can see we figure out how many sensors are attached with
sensors.getDeviceCount()which will let us know the # of connected sensors, and then can get the temperature from each one starting from index #0 up with
sensors.getTempCByIndex(index #)The index #'s will always be sorted by address number so every time you start, the index #0 sensor will be the same as last time you started up. If you swap the sensors with another breakout, the index # may change so that's when you would have to check the code to figure out whether the index #'s are different
#include <OneWire.h> #include <DallasTemperature.h> // Data wire is plugged into port 2 on the Arduino #define ONE_WIRE_BUS 2 // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) OneWire oneWire(ONE_WIRE_BUS); // Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire); DeviceAddress addr; void setup(void) { // start serial port Serial.begin(9600); Serial.println("Dallas Temperature IC Control Library Demo"); // Start up the library sensors.begin(); } void loop(void) { // call sensors.requestTemperatures() to issue a global temperature // request to all devices on the bus Serial.print("Requesting temperatures..."); sensors.requestTemperatures(); // Send the command to get temperatures Serial.println("DONE"); for (uint8_t s=0; s < sensors.getDeviceCount(); s++) { // get the unique address sensors.getAddress(addr, s); // just look at bottom two bytes, which is pretty likely to be unique int smalladdr = (addr[6] << 8) | addr[7]; Serial.print("Temperature for the device #"); Serial.print(s); Serial.print(" with ID #"); Serial.print(smalladdr); Serial.print(" is: "); Serial.println(sensors.getTempCByIndex(s)); } }
The Address pinouts
So if you're wondering how you can read those address pins, you can do so but the DallasTemp library doesn't support it, instead, you'll have to go with the lower-level OneWire library.
Open up the OneWire->MAX31850_Temperature example and load it into your Arduino.
More about OneWire and DallasTemp
Arduino Playground has some good resources on OneWire at http://playground.arduino.cc/Learning/OneWire and PJRC has documented it as well over at http://www.pjrc.com/teensy/td_libs_OneWire.html
Page last edited February 26, 2014
Text editor powered by tinymce.