Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
Z

zampedro

@zampedro
About
Posts
17
Topics
0
Shares
0
Groups
0
Followers
1
Following
0

Posts

Recent Best Controversial

  • Support for new Arduino Hardware platform: WavGat UNO R3 compatible board
    Z zampedro

    @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

    Development

  • Wireless Peacefair PZEM-004T Energy Monitor on Audrino Web Server
    Z zampedro

    @Karolis-Kirna Just a bit late but here it is.
    arduino+nrf24l01+pzem_2.jpg pzem-004t_2a.jpgarduino mini 3.3v 8Mhz+NRF24L01.jpg meter_panel.jpg meter_log1.jpg
    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); // ???
    }
    
    
    
    
    
    My Project

  • Wireless Peacefair PZEM-004T Energy Monitor on Audrino Web Server
    Z zampedro

    @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.

    My Project

  • i have problem in gas sensor
    Z zampedro

    @Reza
    sorry, I made a mistake. You have to check AOUT.

    Troubleshooting

  • i have problem in gas sensor
    Z zampedro

    @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);
    
    Troubleshooting

  • i have problem in gas sensor
    Z zampedro

    @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).

    Troubleshooting

  • i have problem in gas sensor
    Z zampedro

    It should be enough to read ppm from the sensor.

    Troubleshooting

  • i have problem in gas sensor
    Z zampedro

    yes, R2 is 1k. Change RL_VALUE from 5 to 1.
    0_1482728855950_mq2_a.JPG

    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

    Troubleshooting

  • i have problem in gas sensor
    Z zampedro

    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.
    0_1482692240236_mq2-sch.jpg

    Troubleshooting

  • i have problem in gas sensor
    Z zampedro

    @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
    0_1482682330215_mq-2_modules.jpg

    Troubleshooting

  • problem about gas sensor
    Z zampedro

    @Reza hi Reza,
    LPGCurve[3]={2.3, 0.21, -0.47}; COCurve[3] and SmokeCurve[3] are taken from MQ-2 datasheet where 2.3=Lg200 but the sketch uses "log" in

    int MQGetPercentage(float rs_ro_ratio, float *pcurve)
    {
    return (pow(10, ( ((log(rs_ro_ratio) - pcurve[1]) / pcurve[2]) + pcurve[0])));
    }

    In my system log stands for ln=natural logarithm so i have to change log with log10 in the sketch and in the MQ2 library.
    Try a Serial.print(log(10)) to check.

    Regards

    Troubleshooting

  • DHT22 and DS18b20 on same node: DS shows up with Humidity now.
    Z zampedro

    @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.

    Troubleshooting

  • DHT22 and DS18b20 on same node: DS shows up with Humidity now.
    Z zampedro

    @palande.vaibhav You have to compile domoticz from source, highly recommended if
    you run it on raspberry, orangepi etc...

    Troubleshooting

  • sensors stop working after time
    Z zampedro

    @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.

    Troubleshooting

  • sensors stop working after time
    Z zampedro

    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).

    Troubleshooting

  • DHT22 and DS18b20 on same node: DS shows up with Humidity now.
    Z zampedro

    I modified MySensorBase.cpp

    void MySensorsBase::SendSensor2Domoticz
    case V_TEMP:

    at lines 595 and 603 (numbers from last git code) for Temperature

    // SendTempHumBaroSensorFloat(cNode, pChild->batValue, Temp, Humidity, Baro, nforecast, (!pChild->childName.empty()) ? pChild->childName : "TempHumBaro");
    if ( (pChildHum->childID+1)== pChild->childID)
    SendTempHumBaroSensorFloat(cNode, pChild->batValue, Temp, Humidity, Baro, nforecast, (!pChild->childName.empty()) ? pChild->childName : "TempHumBaro");
    else
    SendTempSensor(cNode, pChild->batValue, Temp, (!pChild->childName.empty()) ? pChild->childName : "Temp");

    // SendTempHumSensor(cNode, pChild->batValue, Temp, Humidity, (!pChild->childName.empty()) ? pChild->childName : "TempHum");
    if ( (pChildHum->childID+1)== pChild->childID)
    SendTempHumSensor(cNode, pChild->batValue, Temp, Humidity, (!pChild->childName.empty()) ? pChild->childName : "TempHum");
    else
    SendTempSensor(cNode, pChild->batValue, Temp, (!pChild->childName.empty()) ? pChild->childName : "Temp");

    case V_HUM:
    

    at lines 678 and 686 for Humidity

    // SendTempHumBaroSensorFloat(cNode, pChildTemp->batValue, Temp, Humidity, Baro, nforecast, (!pChild->childName.empty()) ? pChild->childName : "TempHumBaro");
    if ( (pChild->childID+1)== pChildTemp->childID)
    SendTempHumBaroSensorFloat(cNode, pChildTemp->batValue, Temp, Humidity, Baro, nforecast, (!pChild->childName.empty()) ? pChild->childName : "TempHumBaro");
    else
    SendHumiditySensor(cNode, pChild->batValue, Humidity, (!pChild->childName.empty()) ? pChild->childName : "Hum");

    // SendTempHumSensor(cNode, pChildTemp->batValue, Temp, Humidity, (!pChild->childName.empty()) ? pChild->childName : "TempHum");
    if ( (pChild->childID+1)== pChildTemp->childID)
    SendTempHumSensor(cNode, pChildTemp->batValue, Temp, Humidity, (!pChild->childName.empty()) ? pChild->childName : "TempHum");
    else
    SendHumiditySensor(cNode, pChild->batValue, Humidity, (!pChild->childName.empty()) ? pChild->childName : "Hum");

    In this way hum+temp of DHT11 are shown together ( CHILD_ID_HUM +1 == CHILD_ID_TEMP ) and
    temperatures from ds18b20 are alone in separate widgets.

    #define CHILD_ID_HUM 9 // DHT11
    #define CHILD_ID_TEMP 10 // DHT11
    #define DS18B20_STARTID 15 // DS18B20

    Regards

    Troubleshooting

  • DHT22 and DS18b20 on same node: DS shows up with Humidity now.
    Z zampedro

    This is a really annoying thing.
    I finally decided to modify the Domoticz sources, and now
    temperature shows up with humidity only if they have
    consecutive ID, otherwise they are shown separated.

    Troubleshooting
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular