Hello there
My board is a MKR wifi 1010 and I use 2 digital temp sensors DS18B20.
I need to access them by their 64 bits address because index look up fail when I disconnect one of them. My project is for 2 fermentation tank and I need to disconnect the probe when I wash the tank.
I have been able to get the addresses with an UNO easilly
I can't reach them on the MKR1010 under their addresses
I can reach them on the MKR 1010 under index lookup but I do not want to use this because of above issue...
I think I know where is the issue in the code but I do not know how to fix it...
In the UNO code, the words uint8_t and getTempC are blued as if they are recognized but are not blued in the MKR code.
I have read many post on that but cannot point the fix to apply. Pretty sure this is about the library and the board...
UNO code:
#include <OneWire.h>
#include <DallasTemperature.h>
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Addresses of DS18B20s
uint8_t sensor1[8] = { 0x28, 0xE1, 0x6F, 0x96, 0xF0, 0x01, 0x3C, 0xC2 };
uint8_t sensor2[8] = { 0x28, 0xE0, 0xBA, 0x49, 0xF6, 0x44, 0x3C, 0x57 };
void setup(void)
{
Serial.begin(9600);
sensors.begin();
}
void loop(void)
{
sensors.requestTemperatures();
Serial.print("Sensor 1: ");
float tempC1 = sensors.getTempC(sensor1);
Serial.print(tempC1);
Serial.print("Sensor 2: ");
float tempC2 = sensors.getTempC(sensor2);
Serial.print(tempC2);
Serial.println();
delay(1000);
}
MKR 1010 code:
// DallasTemperature - Version: Latest
#include <DallasTemperature.h>
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>
#include "thingProperties.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 8
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Addresses of DS18B20s
uint8_t sensor1[8] = { 0x28, 0xE1, 0x6F, 0x96, 0xF0, 0x01, 0x3C, 0xC2 };
uint8_t sensor2[8] = { 0x28, 0xE0, 0xBA, 0x49, 0xF6, 0x44, 0x3C, 0x57 };
#define R1 7
#define t1 8
#define L2 11
#define R2 9
#define t2 10
float hist = 0.5;
float temp_Min_1;
float temp_Min_2;
float temp_Max_1;
float temp_Max_2;
int L1 = 6;
bool toggle1;
bool toggle2;
void setup() {
//initialyse Serial
Serial.begin(9600);
delay(500);
//initialyse sensors
sensors.begin();
//initialyse relay
pinMode(R1, OUTPUT);
pinMode(R2, OUTPUT);
//initialyse LED
pinMode(L1, OUTPUT);
pinMode(L2, OUTPUT);
toggle1=false;
toggle2=false;
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
bool requestTemperaturesByAddress(const uint8_t*);
// sends command for one device to perform a temperature conversion by index
//bool requestTemperaturesByIndex(uint8_t);
// returns temperature raw value (12 bit integer of 1/16 degrees C)
//int16_t getTemp(const sensor1);
if (toggle1){
t1 = sensors.getTempC(sensor1);
digitalWrite(R1,HIGH);
Serial.println(set_temp_1);
Serial.println(temp_Max_1);
Serial.println(temp_Min_1);
Serial.println(t1);
Serial.println();
delay(1000);
}
else{
digitalWrite(R1,LOW);
}
}
void onOnoff1Change() {
if (onoff1) {
digitalWrite(L1,HIGH);
toggle1=true;
} else {
digitalWrite(L1,LOW);
toggle1=false;
}
}
void onOnoff2Change() {
}
void onSetTemp1Change() {
temp_Max_1 = set_temp_1 + hist/2;
temp_Min_1 = set_temp_1 - hist/2;
}
void onSetTemp2Change() {
}
