Salve a tutti,
devo poter stampare sulla seriale (e su un display LCD) l'indirizzo corretto di un generico sensore ds18B20 , oltre che la sua temperatura.
Il problema che riscontro è che l'indirizzo che leggo (sia nel formato seriale che decimale), è invertito, ovvero se su arduino leggo:
287783B809000085
su raspberry l'indirizzo corretto è:
28000009b88377
Come faccio ? Mi aiutate a scrivere la procedura di conversione ?
Vi posto il mio codice:
#include <PCD8544.h>
PCD8544 lcd;
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is conntec to the Arduino digital pin 4
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
// variable to hold device addresses
DeviceAddress Thermometer;
void setup() {
// Start serial communication for debugging purposes
Serial.begin(9600);
// Start up the library
sensors.begin();
lcd.begin(84, 48);
}
void loop() {
// Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
sensors.requestTemperatures();
sensors.getAddress(Thermometer, 0);
Serial.print("Celsius temperature: ");
// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
Serial.println(sensors.getTempCByIndex(0));
delay(1000);
printAddress(Thermometer);
lcd.setCursor(0, 0);
lcd.print(" Temperatura C");
lcd.setCursor(0, 1);
lcd.print(" -------");
lcd.setCursor(0,2);
lcd.print(sensors.getTempCByIndex(0));
delay(200);
}
// function to print a device address
void printAddress(DeviceAddress deviceAddress) {
for (uint8_t i = 0; i < 8; i++){
if (deviceAddress[i] < 16) Serial.print("0");
Serial.print(deviceAddress[i], HEX);
}
}