My first RFM69 Battery sensor: an ultrasonic sonar to measure the level of my fuel tank (don't laugh, winters can be cold in Burgundy )
Many thanks to @sundberg84 and @mfalkvidd for advice to the Newbie i am and to @Gerator for the RFM69 gateway
My first RFM69 Battery sensor: an ultrasonic sonar to measure the level of my fuel tank (don't laugh, winters can be cold in Burgundy )
Many thanks to @sundberg84 and @mfalkvidd for advice to the Newbie i am and to @Gerator for the RFM69 gateway
@sundberg84 Thank you
My knowledge being very limited, i understand this might be difficult for my to go on the RFM69 version ?
Hopefully, my nrf24 network based on your designs works well
Here is what i have tried:
I try using GPIO 2 and 15 to pilot the RFM69
here an extract of my GatewayESP8266.ino
// Enable debug prints to serial monitor
#define MY_DEBUG
// Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h
#define MY_BAUD_RATE 9600
// Enables and select radio type (if attached)
//#define MY_RADIO_RF24
#define MY_RADIO_RFM69
#define MY_IS_RFM69HW // Omit if your RFM is not "H"
#define MY_RFM69_IRQ_PIN 2
#define MY_RFM69_IRQ_NUM MY_RFM69_IRQ_PIN
#define MY_RFM69_CS_PIN 15 // NSS. Use MY_RFM69_SPI_CS for older versions (before 2.2.0)
../..
void setup()
{
pinMode(MY_RFM69_IRQ_PIN, OUTPUT);
pinMode(MY_RFM69_CS_PIN, OUTPUT);
// Setup locally attached sensors
}
../..
void loop()
{
// Send locally attached sensors data here
digitalWrite(MY_RFM69_IRQ_PIN, HIGH);
delay(1000);
digitalWrite(MY_RFM69_IRQ_PIN, LOW);
delay(1000);
}
What's going wrong is i need to unplug the wire to GPIO2 at boot time unless it won't boot
then if i do that and replug the wire after boot, TFM is not initialized properly and
i get this log:
MCO:BGN:INIT GW,CP=RRNGE---,FQ=80,REL=255,VER=2.3.2
114 TSF:LRT:OK
130 TSM:INIT
143 TSF:WUR:MS=0
163 TSM:INIT:TSP OK
184 TSM:INIT:GW MODE
206 TSM:READY:ID=0,PAR=0,DIS=0
238 MCO:REG:NOT NEEDED
scandone
1311 GWT:TIN:CONNECTING...
2339 GWT:TIN:CONNECTING...
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 2
connected with TPLINK_BUREAU, channel 1
dhcp client start...
cnt
3168 GWT:TIN:CONNECTING...
ip:192.168.1.50,mask:255.255.255.0,gw:192.168.1.1
4329 GWT:TIN:CONNECTING...
4357 GWT:TIN:IP: 192.168.1.50
4389 MCO:BGN:STP
pm open,type:2 0
14407 MCO:BGN:INIT OK,TSP=1
14436 TSM:READY:NWD REQ
15462 ?TSF:MSG:SEND,0-0-255-255,s=255,c=3,t=20,pt=0,l=0,sg=0,ft=0,st=OK:
My knowlegde in electronics is level zero unfortunalty
The adafruit Huzzah documentation states that
GPIO #2, is also used to detect boot-mode. It also is connected to the blue LED that is near the WiFi antenna. It has a pullup resistor connected to it, and you can use it as any output (like #0) and blink the blue LED.
So i thought i could wire directly GPIO2 to DIO0 on the RFM69 like explained https://www.mysensors.org/build/connect_radio but obviously i do something wrong
Please Help
@mfalkvidd You're right: For production i'm going to build isolation for the sensor not to be in contact
Anyway: The flash point of domestic fuel oil is 55 ° C, which means that fuel oil cannot ignite below this temperature. In addition, in its liquid form, fuel oil is non-flammable at room temperature.
Thanks to @sundberg84
My Nrf24 gateaway is know quasi professionnal !
Can't wait to test the RFM69 version
I guess this means i finally managed to get it working:
4131 MCO:BGN:STP
4133 MCO:BGN:INIT OK,TSP=1
4135 TSM:READY:NWD REQ
4139 ?TSF:MSG:SEND,0-0-255-255,s=255,c=3,t=20,pt=0,l=0,sg=0,ft=0,st=OK:
pm open,type:2 0
30149 TSF:MSG:READ,5-5-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
30155 TSF:MSG:BC
30157 TSF:MSG:FPAR REQ,ID=5
30159 TSF:PNG:SEND,TO=0
30161 TSF:CKU:OK
30163 TSF:MSG:GWL OK
30641 TSF:MSG:SEND,0-0-5-5,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0
32650 TSF:MSG:READ,5-5-0,s=255,c=3,t=24,pt=1,l=1,sg=0:1
32655 TSF:MSG:PINGED,ID=5,HP=1
Hello, certainly yes; anyhow, my setup is quite experimental yet:
I will post more details when my config is better.
@scalz @Sasquatch Thank you for suggestions, i will test next week-end
My gateaway is an esp8266 adafruit huzzah feather and my node arduino mini pro (8mhz 3v) using the psb of @sundberg84 ([here])(https://www.openhardware.io/view/389/EasyNewbie-PCB-RFM69-HWW-edition-for-MySensors)
I did not place any capacitor on the gateway, which is usb powered in my tests.
I will try to connect a decoupling capacitor like explained here like 47uF
Hi all, for the sake of beginners like myself and to get advice on it, here is the code i have done to measure the battery of my sensors
based on @sundberg84 here: EasyNewbie-PCB-for-MySensors and articles i've read here
Please provide advice on how to manage switching analogReference()
Here is the class definition:
class MyBM {
public:
MyBM();
MyBM(const float _VMIN, const float _VMAX);
void setup(void);
void MeasureBattery(void); //The battery calculations
private:
void burnreadings(void);
float VBAT_PER_BITS;
float VMIN; // Vmin (radio Min Volt)=1.9V (564v)
float VMAX; // Vmax = (2xAA bat)=3.0V (892v)
int batteryPcnt = 0; // Calc value for battery %
int batLoop = 0; // Loop to help calc average
int batArray[3]; // Array to store value for average calc.
unsigned int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point
int sValue;
float Vbat;
};
You can change the values in the constructor MyBM() ; by default it is the resistors 1M and 470k for EasyPCB.
Following advice found on stackoverflow, i make 8 readings in burnreadings() when switching from analogReference(INTERNAL) to analogReference(DEFAULT) back & forth
MyBM::MyBM() {
this->VMIN= 2.0 ; // Vmin (radio Min Volt)=1.9V (564v)
this->VMAX= 3.3; // Vmax = (2xAA bat)=3.0V (892v)
this->VBAT_PER_BITS= (1470/470)*(1.1/1024);
}
MyBM::MyBM(const float _VMIN, const float _VMAX) {
MyBM();
this->VMIN= _VMIN;
this->VMAX= _VMAX;
}
void MyBM::burnreadings(void)
{
for (int i = 0; i < 8; i++)
{
analogRead(BATTERY_SENSE_PIN);
}
}
void MyBM::setup(void) {
//=========================
// BATTERY MEASURER
//DEFAULT: the default analog reference of 5 volts (on 5V Arduino boards) or 3.3 volts (on 3.3V Arduino boards)
//INTERNAL: an built-in reference, equal to 1.1 volts on the ATmega168 or ATmega328 and 2.56 volts on the ATmega8 (not available on the Arduino Mega)
//EXTERNAL: the voltage applied to the AREF pin (0 to 5V only) is used as the reference.
analogReference(INTERNAL); // set the ADC reference to 1.1V
burnreadings(); // make 8 readings but don't use them
delay(10); // idle some time
//Battery inital calc
DPR("With Battery VMax (100%) = "); DPR(VMAX); DPR("volts and Vmin (0%) = "); DPR(VMIN); DPRLN(" volts");
DPR("Battery Percent 25%/50%/75% calculates to: "); DPR(((VMAX - VMIN) / 4) + VMIN); DPR("/"); DPR(((VMAX - VMIN) / 2) + VMIN); DPR("/"); DPRLN(VMAX - ((VMAX - VMIN) / 4));
sValue = analogRead(BATTERY_SENSE_PIN);
DPR("Batterysens :"); DPRLN(sValue);
Vbat = sValue * VBAT_PER_BITS;
batteryPcnt = static_cast<int>(((Vbat - VMIN) / (VMAX - VMIN)) * 100.);
DPR("Current battery are measured to (please confirm!): "); DPR(batteryPcnt); DPR(" % - Or "); DPRLN(Vbat); DPRLN(" Volts");
analogReference(DEFAULT); // set the ADC reference back to internal
burnreadings(); // make 8 readings but don't use them
delay(10); // idle again
//=========================
}
void MyBM::MeasureBattery() {
analogReference(INTERNAL); // set the ADC reference to 1.1V
burnreadings(); // make 8 readings but don't use them
delay(10); // idle some time
// Battery monitoring reading
sValue = analogRead(BATTERY_SENSE_PIN);
DPR("Batterysens :"); DPRLN(sValue);
//delay(500);
// Calculate the battery in %
Vbat = sValue * VBAT_PER_BITS;
batteryPcnt = static_cast<int>(((Vbat - VMIN) / (VMAX - VMIN)) * 100.);
DPR("Battery percent: "); DPR(batteryPcnt); DPR(" %"); DPR("Battery Voltage: "); DPR(Vbat); DPRLN(" Volts");
// Add it to array so we get an average of 3 (3x20min)
batArray[batLoop] = batteryPcnt;
if (batLoop > 2) {
batteryPcnt = (batArray[0] + batArray[1] + batArray[2]);
batteryPcnt = batteryPcnt / 3;
if (batteryPcnt > 100) {
batteryPcnt = 100;
}
DPR("Battery Average (Send): "); DPR(batteryPcnt); DPRLN(" %");
sendBatteryLevel(batteryPcnt);
batLoop = 0;
}
else
{
batLoop++;
}
analogReference(DEFAULT); // set the ADC reference back to internal
burnreadings(); // make 8 readings but don't use them
delay(10); // idle again
}
Here is how i use it with a sensor that manages both interrupts and a sensor-specific timeout
// sdj is an object representing the sensor
MyBM bm;
void setup()
{
sdj.setup();
bm.setup();
}
void loop()
{
if (tripped==0) {
the_switch= sdj.get();
} else if (tripped==MY_WAKE_UP_BY_TIMER) {
if (sdj.wait_next()) {
// timeout needs to do something for the sensor
sdj.resetCode();
} else {
// timeout , nothing occured for sensor
bm.MeasureBattery();
}
}
// Sleep until something happens with the sensor or timeout
tripped= sdj.sleep(WAIT_LOOP);
}
@mfalkvidd thank you for your help.
The node is a EasyNewbie-PCB-for-MySensors thanks to @sundberg84 in battery mode
Maybe i have a noise problem: i did not set the "BAT" jumper because my battery might be a bit to powerfull (3.7-4V) a little above what the radio may be able to receive.
@hlehoux BTW, in my case this seems to be related to the battery being very low.
Hi all, discovered today this thread while i was searching for a problem of message received twice.
Even though i've been using mySensors for several years, this is the first time i encounter this.
I was not aware there is no guarantee that a message is sent only once....
Unfortunatly, the message is sent to an actuator to tell to "toggle" the light: so if received twice, the effect is not very efficient.
I will have to implement something...
@mfalkvidd You're right: For production i'm going to build isolation for the sensor not to be in contact
Anyway: The flash point of domestic fuel oil is 55 ° C, which means that fuel oil cannot ignite below this temperature. In addition, in its liquid form, fuel oil is non-flammable at room temperature.
My first RFM69 Battery sensor: an ultrasonic sonar to measure the level of my fuel tank (don't laugh, winters can be cold in Burgundy )
Many thanks to @sundberg84 and @mfalkvidd for advice to the Newbie i am and to @Gerator for the RFM69 gateway
Thank you @sundberg84 !
Well the node's been working for a whole day without loosing any message, and it reports its battery so everything seems fine.
By the way, i have my first RFm69 node based on easyPCB now working (a sonar to measure fuel tank) connected to the gateway of @Gerator : works great
@sundberg84 Thank you for your advice.
Yes, i guess this battery has a too high voltage. But the advantage is that the battery is small.
If i understand correctly, since i did not set the BAT jumper, the radio is not fed directly from the battery ; i measure 3.3V at the radio .
If i would set the BAT jumper , the radio would be directly fed by the battery, so with 3,85V which could kill the radio.
I don't have space for 2xAA , I understand finding a small 3.3V battery would be clever so i'm gonna search for that.
I will test during a full night with one hour sleep to check if i really occurs often or not.
Do you suggest i should remove the booster ? I have very little experience regarding how long my node will workwith this battery.
Ah Ah, electronics is a strange world for us simple software programmers.
Thank you again for EasyPCB
I will run it with extended debug mode for a few hours to get more insights
@mfalkvidd thank you for your help.
The node is a EasyNewbie-PCB-for-MySensors thanks to @sundberg84 in battery mode
Maybe i have a noise problem: i did not set the "BAT" jumper because my battery might be a bit to powerfull (3.7-4V) a little above what the radio may be able to receive.
Hello, this might be a question from beginner only, but i'm wondering if i needed to do something specific after a long sleep of my node before being able to send a message.
I have from time to time send error when my node wakes up to send a message after a long period of sleep.
So my question is wether i have to execute anything special to get my node ready to send() a message after waking up from this long sleep() ?
Many thank for the advice
Here is a log when it works perfectly:
22:06:44.169 -> 6807 MCO:SLP:MS=14400000,SMS=0,I1=0,M1=1,I2=255,M2=255
22:06:44.169 -> 6813 TSF:TDI:TSL
22:06:48.121 -> 6815 MCO:SLP:WUP=0
22:06:48.121 -> 6817 TSF:TRI:TSB
22:06:48.121 -> Loop
22:06:48.121 -> analogRead: 18/933
22:06:48.121 -> digitalRead:1
22:06:48.121 -> Interrupt received for switch:1
22:06:48.121 -> 6828 MCO:SLP:MS=150,SMS=0,I1=0,M1=1,I2=255,M2=255
22:06:48.155 -> 6836 TSF:TDI:TSL
22:06:48.255 -> 6838 MCO:SLP:WUP=0
22:06:48.289 -> 6840 TSF:TRI:TSB
22:06:48.289 -> Loop
22:06:48.289 -> analogRead: 18/219
22:06:48.289 -> digitalRead:0
22:06:48.289 -> Interrupt received for switch:-1
22:06:48.461 -> Code=1
22:06:48.461 -> 6871 TSF:MSG:SEND,9-9-8-0,s=1,c=1,t=47,pt=0,l=1,sg=0,ft=0,st=OK:1
22:06:48.498 -> 6881 TSF:MSG:SEND,9-9-8-8,s=1,c=1,t=2,pt=0,l=1,sg=0,ft=0,st=OK:1
22:06:48.498 -> 6889 TSF:RTE:N2N OK
and Here an example of failure (30 minutes later)
22:06:48.498 -> 6891 MCO:SLP:MS=14400000,SMS=0,I1=0,M1=1,I2=255,M2=255
22:06:48.498 -> 6897 TSF:TDI:TSL
22:35:31.596 -> 12425 MCO:SLP:WUP=0
22:35:31.596 -> 12427 TSF:TRI:TSB
22:35:31.596 -> Loop
22:35:31.596 -> analogRead: 18/861
22:35:31.596 -> digitalRead:1
22:35:31.596 -> Interrupt received for switch:3
22:35:31.596 -> 12435 MCO:SLP:MS=150,SMS=0,I1=0,M1=1,I2=255,M2=255
22:35:31.596 -> 12443 TSF:TDI:TSL
22:35:31.797 -> 12447 MCO:SLP:WUP=-1
22:35:31.797 -> 12449 TSF:TRI:TSB
22:35:31.797 -> Loop
22:35:31.797 -> Code=3
22:35:31.797 -> 12457 !TSF:MSG:SEND,9-9-8-0,s=1,c=1,t=47,pt=0,l=1,sg=0,ft=2,st=NACK:3
22:35:31.797 -> 12468 !TSF:MSG:SEND,9-9-8-8,s=1,c=1,t=2,pt=0,l=1,sg=0,ft=3,st=NACK:3
22:35:31.797 -> 12476 !TSF:RTE:N2N FAIL
22:35:31.797 -> 12482 !TSF:MSG:SEND,9-9-8-8,s=1,c=1,t=2,pt=0,l=1,sg=0,ft=3,st=NACK:3
Here is the code i use to wait:
int8_t MySDJ::sleep(const uint32_t _long) {
return ::sleep(digitalPinToInterrupt(GetdigitalPin()), CHANGE, wait_next() ? 150 : _long , false);
}
and my loop():
if (tripped==0) {
the_switch= sdj.get();
DPR("Interrupt received for switch:"); DPRLN(the_switch);
} else if (tripped==MY_WAKE_UP_BY_TIMER) {
if (sdj.wait_next()) {
// timeout, We should send this code to someone
Serial.print("Code="); Serial.println(sdj.getCode());
send(msg.set( sdj.getCode() )); // send to controller
send(MsgRelayGlobal.set( sdj.getCode() )); // send message to node relay actuator
sdj.resetCode();
} else {
// on ne mesure la batterie que si pas d'action pendant le délai
bm.MeasureBattery();
}
}
// Sleep until something happens with the sensor or timeout
tripped= sdj.sleep(WAIT_LOOP);