Hi,
I am new to this forum so I hope this is the right place.
I have a thermometer which sends Oregon data to the base station. I used an Arduino Nano together with an RXB6 Receiver to get the signal and display it on an Adafruit 7 segement i2c display, which worked quite well.
Unfortunatly, it randomly stops receiving data. As a workaround I restart the Arduino programmatically and it continues working afterwards but this does not seeme like an elegant solution to me.
This is the code I am using. The oregon library is the one by Mickael. (GitHub - Mickaelh51/Arduino-Oregon-Library: To decode data from Oregon Sensors)
#include <Wire.h>
#include <Adafruit_GFX.h>
#include "Adafruit_LEDBackpack.h"
#include <SPI.h>
#include <EEPROM.h>
#include <Oregon.h>
#include <avr/wdt.h>
#define MHZ_RECEIVER_PIN 2
#define MHZ_VIN_PIN 4
Adafruit_7segment matrix = Adafruit_7segment();
unsigned long last_reception = 0L;
int connectionLostCounter = 0;
void softwareReset() {
asm volatile (" jmp 0");
}
void setup() {
attachInterrupt(digitalPinToInterrupt(MHZ_RECEIVER_PIN), ext_int_1, CHANGE);
pinMode(MHZ_VIN_PIN, OUTPUT);
digitalWrite(MHZ_VIN_PIN, HIGH);
EEPROM.get(5, connectionLostCounter);
if (connectionLostCounter < 0) {
connectionLostCounter = 0;
EEPROM.put(5, connectionLostCounter);
}
matrix.begin(0x70);
matrix.setBrightness(1);
matrix.print(connectionLostCounter);
matrix.writeDisplay();
delay(1000);
matrix.writeDigitRaw(0, 0B01000000);
matrix.writeDigitRaw(1, 0B01000000);
matrix.writeDigitRaw(3, 0B01000000);
matrix.writeDigitRaw(4, 0B01000000);
matrix.writeDisplay();
delay(500);
}
void loop() {
cli();
word p = pulse;
pulse = 0;
sei();
if (p != 0)
{
if (orscV2.nextPulse(p))
{
const byte* DataDecoded = DataToDecoder(orscV2);
int SensorID = FindSensor(id(DataDecoded),1);
float temp = temperature(DataDecoded);
printTemp(temp);
if (battery(DataDecoded) == 10) {
doubleBlink(temp);
}
last_reception = millis();
}
} else {
if (millis() - last_reception >= 300000) {
EEPROM.put(5, connectionLostCounter + 1);
softwareReset();
}
}
}
void doubleBlink(float temp) {
char tempString[6] = "";
dtostrf(temp, 6, 2, tempString);
matrix.writeDigitNum(3, tempString[2] - '0', false);
matrix.writeDisplay();
delay(1000);
matrix.writeDigitNum(3, tempString[2] - '0', true);
matrix.writeDisplay();
delay(1000);
matrix.writeDigitNum(3, tempString[2] - '0', false);
matrix.writeDisplay();
delay(1000);
matrix.writeDigitNum(3, tempString[2] - '0', true);
matrix.writeDisplay();
delay(1000);
}
void printTemp(float temp) {
char tempString[6] = "";
dtostrf(temp, 6, 2, tempString);
temp < 0 ? matrix.writeDigitRaw(0, 0B01000000) : matrix.writeDigitRaw(0, 0);
abs(temp) >= 10 ? matrix.writeDigitNum(1, tempString[1] - '0') : matrix.writeDigitRaw(1, 0);
matrix.writeDigitNum(3, tempString[2] - '0', false);
matrix.writeDigitNum(4, tempString[4] - '0');
matrix.writeDisplay();
delay(1000);
matrix.writeDigitNum(3, tempString[2] - '0', true);
matrix.writeDisplay();
delay(500);
}
Any help would be appreciated. Thanks in advance
Moritz