ZUNO2 strange bahaviour using DS18B20
Posted: 02 Feb 2023 23:21
I have problem playing with DS18B20 temperature sensors > Copy / paste 'Multiple DS18B20 temperature sensors' example.
Problem is in this line of code:
temperature = ds18b20.getTemperature(ADDR(i))
Whenever program executes getTemperature() ZUNO resets. Resets are repeating in infinite loop and ZUNO flashes red LED 4 times.
Where is the problem? It took me half a day to figure out:
#define ADDR_SIZE 8
byte addresses[ADDR_SIZE * N_SENSOR];
Byte array of addresses is to short to store whatever ds18b20.findAllSensors(addresses) writes in. Looks like writing goes over the end and overwrites some compiled code.
What was my solution? I increased addresses[] length (for 5 bytes or more) and the problem is gone:
addresses[(ADDR_SIZE * MAX_TEMP_SENSORS) + 5]
Is there a bug in ZUNO_DS18B20.h library? Am I really the only one having this basic strange behaviour?
ZUNO2 rev.6
Bootloader version: 3.0.10
Arduino IDE 2.0.3
Two DS18B20 temp. sensors
Included + S2
Problem is in this line of code:
temperature = ds18b20.getTemperature(ADDR(i))
Whenever program executes getTemperature() ZUNO resets. Resets are repeating in infinite loop and ZUNO flashes red LED 4 times.
Where is the problem? It took me half a day to figure out:
#define ADDR_SIZE 8
byte addresses[ADDR_SIZE * N_SENSOR];
Byte array of addresses is to short to store whatever ds18b20.findAllSensors(addresses) writes in. Looks like writing goes over the end and overwrites some compiled code.
What was my solution? I increased addresses[] length (for 5 bytes or more) and the problem is gone:
addresses[(ADDR_SIZE * MAX_TEMP_SENSORS) + 5]
Is there a bug in ZUNO_DS18B20.h library? Am I really the only one having this basic strange behaviour?
ZUNO2 rev.6
Bootloader version: 3.0.10
Arduino IDE 2.0.3
Two DS18B20 temp. sensors
Included + S2