I have an Arduino Uno with a Arduino Ethernet Shield 2 connected to a Adafruit VL53L0X. I have the unit out at a remote site measuring the disitance from the top of a tube to the filters held inside to get and estimate on how many filters I have left before I need to go and refill it.
#include <VL53L0X.h>
#include <SPI.h>
#include <Ethernet.h>
#include <Modbus.h>
#include <ModbusIP.h>
#include <Wire.h>
VL53L0X sensor;
int filtercount;
int daysleft;
float p;
float v;
//Modbus Registers Offsets (0-9999)
const int SENSOR_Hreg0 = 100;
const int SENSOR_Hreg1 = 101;
const int SENSOR_Hreg2 = 102;
const int SENSOR_Hreg3 = 103;
//Used Pins
//ModbusIP object
ModbusIP mb;
unsigned long ts;
void setup() {
Wire.begin();
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 177 };
mb.config(mac, ip);
// Add SENSOR_Hreg register
mb.addHreg(SENSOR_Hreg0);
mb.addHreg(SENSOR_Hreg1);
mb.addHreg(SENSOR_Hreg2);
mb.addHreg(SENSOR_Hreg3);
ts = millis();
sensor.init();
sensor.setTimeout(500);
sensor.startContinuous();
}
void loop() {
filtercount = (425.08 - sensor.readRangeContinuousMillimeters()) / 3.32401;
daysleft = filtercount / 6 ;
v= analogRead(A0) * (5.0 / 1023.0);
p= (v * 25.0) - 25.0;
//Call once inside loop() - all magic here
mb.task();
if (millis() > ts + 100) {
ts = millis();
mb.Hreg(SENSOR_Hreg0, sensor.readRangeContinuousMillimeters() );
mb.Hreg(SENSOR_Hreg1, filtercount );
mb.Hreg(SENSOR_Hreg2, daysleft );
mb.Hreg(SENSOR_Hreg3, p );
}
}
My question is: Is my device not responding because of a memory issue or a code issue? If its a memory issue then should I insert a reset into my code and force the unit to reset every hour or so? I am getting anywhere between 4 hours and 72 hours of run-time before the unit stops outputting.