Using the DS2482S-800 breakout with Arduino involves wiring up the breakout to your Arduino-compatible microcontroller with two DS18B20 sensors, installing the Adafruit_DS248x library, and running the provided example code.
Wiring
Wire as shown for a 5V board like an Uno. If you are using a 3V board, like an Adafruit Feather, wire the board's 3V pin to the breakout VIN.
Here is an Adafruit Metro wired up to the breakout with two DS18B20 sensors using the STEMMA QT connector. The DS18B20 sensors are connected directly to the breakout on channel 0 and channel 4.
- Breakout STEMMA VIN to Metro 5V (red wire)
- Breakout STEMMA GND to Metro GND (black wire)
- Breakout STEMMA SDA to Metro SDA (blue wire)
- Breakout STEMMA SCL to Metro SCL (yellow wire)
- Breakout channel 0 - to DS18B20 GND
- Breakout channel 0 1W to DS18B20 signal
- Breakout channel 0 + to DS18B20 VIN
- Breakout channel 4 - to DS18B20 GND
- Breakout channel 4 1W to DS18B20 signal
- Breakout channel 4 + to DS18B20 VIN
Here is an Adafruit Metro wired up using a solderless breadboard:
- Breakout VIN to Metro 5V (red wire)
- Breakout GND to Metro GND (black wire)
- Breakout SDA to Metro SDA (blue wire)
- Breakout SCL to Metro SCL (yellow wire)
- Breakout channel 0 - to DS18B20 GND (black wire)
- Breakout channel 0 1W to DS18B20 signal (green wire)
- Breakout channel 0 + to DS18B20 VIN (red wire)
- Breakout channel 4 - to DS18B20 GND (black wire)
- Breakout channel 4 1W to DS18B20 signal (green wire)
- Breakout channel 4 + to DS18B20 VIN (red wire)
Library Installation
You can install the Adafruit_DS248x library for Arduino using the Library Manager in the Arduino IDE.
Click the Manage Libraries ... menu item, search for Adafruit_DS248x, and select the Adafruit DS248x library:
If asked about dependencies, click "Install all".
If the dependencies are already installed, you must make sure you update them through the Arduino Library Manager before loading the example!
#include "Adafruit_DS248x.h" #define DS18B20_CMD_SKIP_ROM 0xCC #define DS18B20_CMD_CONVERT_T 0x44 #define DS18B20_CMD_READ_SCRATCHPAD 0xBE Adafruit_DS248x ds248x; void setup() { Serial.begin(115200); while (!Serial) delay(10); Serial.println("Adafruit DS2482-800 8 channel test sketch!"); if (!ds248x.begin(&Wire, DS248X_ADDRESS)) { Serial.println(F("DS2482-800 initialization failed.")); while (1); } Serial.println("DS2482-800 OK!"); } void loop() { for (int i = 0; i < 8; i++) { ds248x.selectChannel(i); Serial.print("Reading channel: "); Serial.println(i); float temperature = readTemperature(i); Serial.print("\tTemperature: "); Serial.print(temperature); Serial.println(" °C"); delay(1000); } } float readTemperature(uint8_t channel) { // Select the channel on the DS2482-800 if (!ds248x.selectChannel(channel)) { // Handle error if channel selection fails Serial.println("Failed to select channel"); return NAN; // Return 'Not a Number' to indicate an error } // Start temperature conversion ds248x.OneWireReset(); ds248x.OneWireWriteByte(DS18B20_CMD_SKIP_ROM); // Skip ROM command ds248x.OneWireWriteByte(DS18B20_CMD_CONVERT_T); // Convert T command delay(750); // Wait for conversion (750ms for maximum precision) // Read scratchpad ds248x.OneWireReset(); ds248x.OneWireWriteByte(DS18B20_CMD_SKIP_ROM); // Skip ROM command ds248x.OneWireWriteByte(DS18B20_CMD_READ_SCRATCHPAD); // Read Scratchpad command uint8_t data[9]; for (int i = 0; i < 9; i++) { ds248x.OneWireReadByte(&data[i]); } // Calculate temperature int16_t raw = (data[1] << 8) | data[0]; float celsius = (float)raw / 16.0; return celsius; }
Upload the sketch to your board and open up the Serial Monitor (Tools -> Serial Monitor) at 115200 baud. You'll see the DS2482S-800 recognized over I2C. In the loop, each of the 8 channels are selected and read one by one. Each channel's temperature data is printed to the Serial Monitor. If you do not have a sensor attached to a channel, then you'll see negative data print out for it. In the print out below, you'll see data from sensors on channel 0 and channel 4.
Text editor powered by tinymce.