orgua / OneWireHub

OneWire slave device emulator
GNU General Public License v3.0
343 stars 86 forks source link

DS18B20 slave constantly crashes after few minutes #96

Closed raintonr closed 3 years ago

raintonr commented 3 years ago

EDIT: I thought this was due to trying to emulate multiple slaves in the same µC but after changing the code to emulate just a single DS18B20 the problem persists so it must be something fundamental in that code.

Loxone 1-Wire extension as master. Polling every 30 seconds. There are 6 real DS2438 sensors and 2 Arduino DS2438 slaves on this bus and they all work just fine.

Slave code (below) running on Pro Mini 328P 5V 16Mhz constantly crashes after just a few minutes.

I wanted to use an I2C SHT31 sensor presended as 4 DS18B20 devices: 1 temp, 1 humidity, 2 for delta values (want to report delta change in either value over a set period in the future).

After creating a load of code to sample the SHT31, calculate deltas and such it kept crashing. So I threw it all away and just tried the dummy code below with a single DS18B20 device. Super simple but this still crashes after just a few minutes.

Watching readings come in the delta value gets to only -41 or so before going back to -50. Crash and restart of the Pro Mini is the only way that could happen.

This code is fundamentally no different from the DS18B20_asInterface.ino example so can't see what's wrong.

Any ideas what's why this wouldn't work?

#include "OneWireHub.h"
#include "DS18B20.h"

// 1-Wire pin
#define PIN_ONE_WIRE 11

// How often to take readings (in ms)
#define READ_INTERVAL 3000

// Init Hub 
OneWireHub hub = OneWireHub(PIN_ONE_WIRE);
DS18B20 ds_tmp =  DS18B20(0x28, 0xBB, 0x9C, 0xFC, 0x9F, 0xEC, 0x31);

void setup() {
  hub.attach(ds_tmp);
}

float delta = -50;
unsigned long next_change = 0;

void loop() {
  // Constantly Flash the LED
  digitalWrite(LED_BUILTIN, (millis() % 200 < 50) ? 1 : 0);

  hub.poll();

  if (millis() > next_change) {
    // Dummy test values - would sample a sensor here normally.
    ds_tmp.setTemperature(delta);

    // Move them so we can see what's happening
    delta = delta < 100 ? delta + 1 : -50;

    // Don't sample again for a while
    next_change = millis() + READ_INTERVAL;
  }
}
raintonr commented 3 years ago

Well this is embarrassing...

After much more investigation discovered my Pro Mini was rebooting due to bad voltage supply. Despite what the specs say, looks like the Loxone 1-Wire extension does not supply enough juice to keep an Arduino Mini Pro running in a stable state. Enough to boot and run for a while, but not enough to stop it seemingly randomly rebooting after a while.

The other emulated modules on the bus are working fine because they are fed from a separate supply due to having MQ135 sensors connected that I knew would need more current that the 1-Wire extension could supply, and hence didn't see any such issues.

Sorry for the bad report.

At least we can leave this here as a cautionary tale for those who follow ;)