@Reza I implemented your sketch, tried to start/stop(up to a few hours) the gateway(serial gateway) and the controller(domoticz on orangepi pc) to see if the logs help in some way. Nothing, it works.
It should be logged until the freeze occurs.
zampedro
@zampedro
Best posts made by zampedro
-
RE: sensors stop working after time
-
RE: i have problem in gas sensor
@Reza
there are two problems with MQ-2 sensors :
1 the sketch, at the bottom, uses log instead of log10
2 are you sure that RL_VALUE is 5 (kOhm) in your MQ-2 board? In my is 1, the one labeled 102 in the pic.Regards
-
RE: i have problem in gas sensor
1 look at the last line of the sketch:
return (pow(10, ( ((log(rs_ro_ratio) - pcurve[1]) / pcurve[2]) + pcurve[0]))); }``
change to:
return (pow(10, ( ((log10(rs_ro_ratio) - pcurve[1]) / pcurve[2]) + pcurve[0]))); }``
2 RL_VALUE in your MQ2 board should be 1 (kohm), R2 in the schematic.
-
RE: i have problem in gas sensor
yes, R2 is 1k. Change RL_VALUE from 5 to 1.
I suggest you use the MQ-2 sensor library https://github.com/xerlay11/MQ-2-sensor-library and obviously change log and RL_VALUE.
Regards -
RE: sensors stop working after time
Which MySensors library are you using?
With 2.0 i had the sleep issue solved (for now) with MY_PARENT_NODE_ID and MY_PARENT_NODE_IS_STATIC(as suggested by tekka). -
RE: DHT22 and DS18b20 on same node: DS shows up with Humidity now.
@AWI Thanks for the hint.
I thought this wasn't a "issue" but just a "really annoying thing".
However i run domoticz on a Orange PI PC with WiringOP support and i can't find precompiled images. -
RE: i have problem in gas sensor
It should be enough to read ppm from the sensor.
Latest posts made by zampedro
-
RE: Support for new Arduino Hardware platform: WavGat UNO R3 compatible board
@konbaasiang nice, good to know.
I am having problems with SPI interface.
For example i have a 2.4" TFT+XPT2046 touch controller+SD card reader( all on SPI), after many tests i found out that sometimes, reading from XPT2046 SPI, wavgat add 0x1000h which is impossible since the xpt2046 controller has a 12 bits adc. TFT and card reader are Ok instead.
With genuine arduino all work as expected.
Still testing wavgat+NFR24L01, sometimes works sometimes doesn't.
Regards -
RE: Wireless Peacefair PZEM-004T Energy Monitor on Audrino Web Server
@Karolis-Kirna Just a bit late but here it is.
The code:/* * Send Watt and Kwh to gateway * using PZEM-004t * 26/8/2020 cambiato linea 45, 21-23 */ /*++++++++++++++ Global Settings +++++++++++++++++*/ #define SN "PZEM Monitor" #define SV "0.4" // Enable and select radio type attached #define MY_RADIO_NRF24 #define MY_NODE_ID 9 #define MY_PARENT_NODE_ID 11 // from domoticz log #define MY_PARENT_NODE_IS_STATIC /*+++++++++++++ Local Settings ++++++++++++++++++++*/ #define SEND_ONLY_IF_CHANGED //#define MY_DEBUG //#define DEBUG //#define TEST // Aggiunge codice di test da levare #if F_CPU == 8000000L #define MY_BAUD_RATE 9600 #endif #include <debugpaolo.h> #include <SPI.h> #include <MySensors.h> //#include <SoftwareSerial.h> // Arduino IDE <1.6.6 #include <PZEM004T.h> #define RX_PIN 4 #define TX_PIN 5 PZEM004T pzem(RX_PIN,TX_PIN); // RX pin,TX pin IPAddress ip(192,168,1,1); #define CHILD_WATT_ID 0 #define VOLTAGE_ID 1 unsigned long lastSend=0; unsigned long SEND_FREQUENCY = 40000; // Minimum time between send (in milliseconds). We don't want to spam the gateway. MyMessage wattMsg(CHILD_WATT_ID,V_WATT); MyMessage kWhMsg(CHILD_WATT_ID,V_KWH); //MyMessage kwhSaveMsg(CHILD_WATT_ID,V_VAR1); //MyMessage varMsg(CHILD_WATT_ID,V_VAR); // chi lo sa non va in domoticz double oldKwh=0.0; double oldwh=0.0; float oldwatt=0.0; #ifdef TEST double whtest=0.0; #endif #ifdef SEND_ONLY_IF_CHANGED int kwh_counter; #define KWH_COUNTER_MAX 33 //dopo 23 volte(15 min) invia comunque #endif MyMessage msgVoltage(VOLTAGE_ID, V_VOLTAGE); float lastv=0; #define V_COUNTER_MAX 70 int v_counter=0; int BATTERY_SENSE_PIN = A3; // select the input pin for the battery sense point int oldBatteryPcnt = 0; #define MAX_BATTERY_CHECK 56 // 56*40 sec = 56 min circa int battery_check; #define VREF 1.106 #define RBATT 5.73305 // ((1578+333.4)/333.4)? #define VFACTOR RBATT*VREF/1023 // /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++ SETUP +++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ void setup() { // begin(incomingMessage); analogReference(INTERNAL); pzem.setAddress(ip); battery_check = MAX_BATTERY_CHECK; } /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++ Presentation ++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo(SN, SV); present(CHILD_WATT_ID, S_POWER); present(VOLTAGE_ID, S_MULTIMETER); } /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++ Loop +++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ void loop() { /* +++++++++++++++++++++++++++++++++++++++++++ ++++ PZEM section +++++++++ +++++++++++++++++++++++++++++++++++++++++++*/ float v = pzem.voltage(ip); if (v < 0.5) { delay(500); // check v twice v = pzem.voltage(ip); if (v < 0.5 ) v = 0.0; } DEBUG_PRINT(v);DEBUG_PRINT("V; "); #ifdef DEBUG float i = pzem.current(ip); if(i >= 0.0){ DEBUG_PRINT(i);DEBUG_PRINT("A; "); } float VA=v*i; if(VA >= 0.0){ DEBUG_PRINT(VA);DEBUG_PRINTLN("VA; "); } #endif /* --------------------------- *------- Sezione potenza ---- ----------------------------*/ float watt = pzem.power(ip); #ifdef TEST watt=kwh_counter*2; #endif DEBUG_PRINT(watt);DEBUG_PRINT("W ");DEBUG_PRINT(VA);DEBUG_PRINTLN("VA "); if (watt <=0 ) { DEBUG_PRINT(watt);DEBUG_PRINTLN("W. Sensore NC o assenza rete! "); if ( oldwatt>0) { watt =0; send(wattMsg.set(watt,1)); // Send watt value to gw oldwatt=0.0; } } else { if ( oldwatt==0.0) { send(wattMsg.set(watt,1)); // Send watt value to gw DEBUG_PRINT(watt);DEBUG_PRINTLN("Rete ritornata! "); oldwatt = watt; } else { DEBUG_PRINT(watt);DEBUG_PRINTLN("W; "); float diffwatt=abs(watt-oldwatt); if ( diffwatt >= 49.9 ) { // watt in aumento di 50watt DEBUG_PRINT("Differenza ");DEBUG_PRINT(diffwatt);DEBUG_PRINTLN("W; "); oldwatt = watt; send(wattMsg.set(watt,1)); // Send watt value to gw } else { float perc = 100.0*diffwatt/oldwatt; // oldwatt o watt? DEBUG_PRINT("Perc ");DEBUG_PRINT(perc);DEBUG_PRINTLN("% "); if ( perc >= 49.9 ) { // variazione del 50% DEBUG_PRINT("Percentuale Diff ");DEBUG_PRINT(perc);DEBUG_PRINTLN("%; "); oldwatt = watt; send(wattMsg.set(watt,1)); // Send watt value to gw // send(varMsg.set(watt,1)); // non va in domoticz } else { if ( (perc >= 15.0) && (diffwatt>=8) ) { DEBUG_PRINT("Diff ");DEBUG_PRINT(diffwatt); DEBUG_PRINT("Perc ");DEBUG_PRINT(perc);DEBUG_PRINTLN("%; "); oldwatt = watt; send(wattMsg.set(watt,1)); // Send watt value to gw } } } } } //send(wattMsg.set(watt,1)); // Send watt value to gw /* --------------------------- *------- Sezione energia ---- ---------------------------*/ float wh = pzem.energy(ip); #ifdef TEST whtest+=10.0; wh=whtest; #endif if(wh >= 0.0){ DEBUG_PRINT(wh);DEBUG_PRINT("Wh; "); } else wh = 0.0; DEBUG_PRINTLN(); #ifdef SEND_ONLY_IF_CHANGED if ( (kwh_counter==0) ||(abs(wh-oldwh) > 187) ) { // 100 wh #else if ( wh > 0.0 ) { #endif double kwh = (double)wh/(double)1000.0; send(kWhMsg.set(kwh, 3)); // Send kwh value to gw oldwh=wh; #ifdef SEND_ONLY_IF_CHANGED kwh_counter=0; #endif } #ifdef SEND_ONLY_IF_CHANGED DEBUG_PRINT("kwh_counter="); kwh_counter++; DEBUG_PRINT(kwh_counter);DEBUG_PRINT(" "); if (kwh_counter == KWH_COUNTER_MAX ) kwh_counter = 0; DEBUG_PRINTLN(); #endif /* +++++++++++++++++++++++++++++++++++++++++++ ++++ Battery check section +++++++++ +++++++++++++++++++++++++++++++++++++++++++*/ if ( battery_check == MAX_BATTERY_CHECK) { analogRead(BATTERY_SENSE_PIN); // needed for accuracy int sensorValue = analogRead(BATTERY_SENSE_PIN); DEBUG_PRINT("A0 Value = ");DEBUG_PRINTLN(sensorValue); float batteryV = sensorValue * VFACTOR; // 100% 4.0v 0% 3.3v int batteryPcnt = ( batteryV - 3.3) / (4.0 - 3.3) * 100; batteryPcnt = (batteryPcnt > 100) ? 100 : batteryPcnt; batteryPcnt = (batteryPcnt < 0) ? 0 : batteryPcnt; DEBUG_PRINT("Battery Voltage: ");DEBUG_PRINT(batteryV);DEBUG_PRINTLN(" V"); DEBUG_PRINT("Battery Percent: ");DEBUG_PRINT(batteryPcnt);DEBUG_PRINTLN(" %"); //if (oldBatteryPcnt != batteryPcnt) { sendBatteryLevel(batteryPcnt); oldBatteryPcnt = batteryPcnt; //} battery_check=0; } else { battery_check++; DEBUG_PRINT("Check = "); DEBUG_PRINTLN(battery_check); } /* +++++++++++++++++++++++++++++++++++++++++++ ++++ 230 Voltage section +++++++++ +++++++++++++++++++++++++++++++++++++++++++*/ #ifdef SEND_ONLY_IF_CHANGED float diffv= abs(v-lastv); if ( ((v_counter == 0) || ( diffv > 3.50)) ) { DEBUG_PRINT("v diff: ");DEBUG_PRINT(diffv);DEBUG_PRINTLN("V "); if ( diffv > 3.50 ) v_counter = 0; else v_counter++; DEBUG_PRINT("v_counter : ");DEBUG_PRINTLN(v_counter); #endif send(msgVoltage.set(v, 1)); lastv = v; #ifdef SEND_ONLY_IF_CHANGED } else { v_counter++; if (v_counter >= V_COUNTER_MAX ) v_counter = 0; DEBUG_PRINT("v_counter : ");DEBUG_PRINTLN(v_counter); } #endif sleep(SEND_FREQUENCY); delay(500); // ??? }
-
RE: Wireless Peacefair PZEM-004T Energy Monitor on Audrino Web Server
@jaykumar Yes,
i built it a couple of years ago, but it's operative for about three months.
I used :
arduino mini pro 3.3v/8Mhz powered by a 3.7v 14500 Li-Ion battery
NRF24L01
PZEM-004T (modified to work at 3.3v)It's a simple watt/energy meter that sends data to the controller(domoticz) every 40 secs, the PZEM-004T does most of the work.
-
RE: i have problem in gas sensor
@Reza
sorry, I made a mistake. You have to check AOUT. -
RE: i have problem in gas sensor
@Reza
you can't convert 16 bits unsigned integers greater than 32767 into 16 bits signed integers because they're treated as negative numbers according to 2's complement math.
You must check with a multimeter VCC(for supply voltage sanity) and DOUT( for ppm reading) on the sensor board.I see two lines to be modified:
if (b == 0) { uint16_t valMQ = MQGetGasPercentage(MQRead(MQ_SENSOR_ANALOG_PIN) / Ro, GAS_CO); if (c == 0) { uint16_t valMQ = MQGetGasPercentage(MQRead(MQ_SENSOR_ANALOG_PIN) / Ro, GAS_CO);
-
RE: i have problem in gas sensor
@Reza
You are sending a 16 bits signed integer, so the maximum value is 32767.send(msg.set((int16_t)ceil(valMQ)));
Try to send GAS_SMOKE instead of GAS_CO.
Pay attention to the power supply, the sensor need 5v 200mA ( i misured 130ma). -
RE: i have problem in gas sensor
It should be enough to read ppm from the sensor.
-
RE: i have problem in gas sensor
yes, R2 is 1k. Change RL_VALUE from 5 to 1.
I suggest you use the MQ-2 sensor library https://github.com/xerlay11/MQ-2-sensor-library and obviously change log and RL_VALUE.
Regards -
RE: i have problem in gas sensor
1 look at the last line of the sketch:
return (pow(10, ( ((log(rs_ro_ratio) - pcurve[1]) / pcurve[2]) + pcurve[0]))); }``
change to:
return (pow(10, ( ((log10(rs_ro_ratio) - pcurve[1]) / pcurve[2]) + pcurve[0]))); }``
2 RL_VALUE in your MQ2 board should be 1 (kohm), R2 in the schematic.
-
RE: i have problem in gas sensor
@Reza
there are two problems with MQ-2 sensors :
1 the sketch, at the bottom, uses log instead of log10
2 are you sure that RL_VALUE is 5 (kOhm) in your MQ-2 board? In my is 1, the one labeled 102 in the pic.Regards