/* Read multiple DS18B20 1-Wire digital temperature sensors by address.
More info: https://www.makerguides.com */
// Include the required Arduino libraries:
#include "OneWire.h"
#include "DallasTemperature.h"
#include <LiquidCrystal_I2C.h>
const byte I2C_ADDR = 0x27;
const byte LCD_COLUMNS = 20;
const byte LCD_LINES = 4;
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
// Define to which pin of the Arduino the 1-Wire bus is connected:
#define ONE_WIRE_BUS 2 // broche 2
// Create a new instance of the oneWire class to communicate with any OneWire device:
OneWire oneWire(ONE_WIRE_BUS);
// Pass the oneWire reference to DallasTemperature library:
DallasTemperature sensors(&oneWire);
// Addresses of DS18B20 sensors connected to the 1-Wire bus
// MMMMMMMMMMMMMMMM adresse réelle Materiel MMMMMMMMMMMMMMM
//byte sensor1[8] = {0x28, 0xBB, 0x22, 0xBB, 0x00, 0x00, 0x00, 0x9F};
//byte sensor2[8] = {0x28, 0xDB, 0x5E, 0xBF, 0x00, 0x00, 0x00, 0x1E};
// TTTTTTTTTTTTTTTT adresse pour Test avec json TTTTTTTTTTTTTTTTTT
byte sensor1[8] = {0x28, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x7E};
byte sensor2[8] = {0x28, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0xDE};
void setup() {
// Begin serial communication at a baud rate of 9600:
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.setCursor(4, 0); // colonne, ligne
lcd.print("Temperatures:");
// Start up the library:
sensors.begin();
// Set the resolution for all devices to 9 bits (résolution 0,5°C)
sensors.setResolution(9);
}
void loop() {
// Send the command for all devices on the bus to perform a temperature conversion:
sensors.requestTemperatures();
Serial.print("Sonde 1: ");
lcd.setCursor(0, 1); // colonne, ligne
lcd.print("Sonde 1: ");
printTemperature(sensor1); // call the printTemperature function with the address of sensor1 as input
Serial.print("Sonde 2: ");
lcd.setCursor(0, 2); // colonne, ligne
lcd.print("Sonde 2: ");
printTemperature(sensor2); // call the printTemperature function with the address of sensor2 as input
Serial.println(); // prints an empty line
delay(1000);
}
void printTemperature(DeviceAddress address) {
// Fetch the temperature in degrees Celsius for device address:
float tempC = sensors.getTempC(address);
//============ Moniteur serie ==============
Serial.print(tempC, 1);
Serial.print(" \xC2\xB0"); // shows degree symbol
Serial.print("C | ");
//=========== LCD ==================
lcd.print(tempC, 1); // 1 chiffre apres la virgule
lcd.print("\xDF\x43 "); // °C
}