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
  1. Home
  2. My Project
  3. Power/ Usage sensor - multi channel - local display

Power/ Usage sensor - multi channel - local display

Scheduled Pinned Locked Moved My Project
41 Posts 6 Posters 19.6k Views 7 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M MarkV

    AWI I got it up and running with your new sketches!! :smiley:
    Great work!!!!! Domoticz recognizes that there are sensors in the network.

    But something is still wrong, the usage isn't going up..
    Whats wrong?

    Didn't connect a display and rotaryswitch and also didn't commented things out..

    Why does it show every sensor twice? One with subtype unknown and one with electric??
    I also seen that with the humidity temp sensor..

    Schermafdruk 2015-09-20 17.45.11.png

    The serial on the master arduino says:
    Schermafdruk 2015-09-20 18.10.52.png

    There's not more than a tiny plaster wall between the two arduinos, a total distance of one meter...

    AWIA Offline
    AWIA Offline
    AWI
    Hero Member
    wrote on last edited by
    #6

    @MarkV A few thing from what I read from the serial out:

    • The slave does not sense any pulses, all the values are at 0

    • The master gets a "fail" when sending data to the Gateway. Looks like a communication issue

    • Are you using an USB or LAN gateway. The Domoticz output show both.... I don't know if Domoticz can handle that.

    • You can try to delete the "old"/previous nodes and start the thing again. Domoticz should use a combined Usage/ Power sensor

    M 1 Reply Last reply
    0
    • J jeti

      Hi, great work :+1:

      as my S0 meter uses 2000imp/kwh and my reading seem to be twice as high as they should be i guess your meters do 1000imp/kwh?
      As i am still working on my programming skills i could not figure out where to change this :flushed:
      can you give me a hint which 1000 to change out with my 2000?

      thanks!

      AWIA Offline
      AWIA Offline
      AWI
      Hero Member
      wrote on last edited by
      #7

      @jeti You are right, I never thought about other meters than the 1 pulse = 1 Whr ones..sorry. There are a few ways of getting it changed:

      • You can keep leave most as it is and when you send/ or display the values divide the pulses by two and double the Watt values in the routines "LCD_local_display" and "sendPowerUpdate"

      • or: make the necessary calculations when the data comes in. This is a little more complicated in routine "storeMeterJSON" but if you understand the logic (including error corrrection) should be not too hard.

      1 Reply Last reply
      0
      • AWIA AWI

        @MarkV A few thing from what I read from the serial out:

        • The slave does not sense any pulses, all the values are at 0

        • The master gets a "fail" when sending data to the Gateway. Looks like a communication issue

        • Are you using an USB or LAN gateway. The Domoticz output show both.... I don't know if Domoticz can handle that.

        • You can try to delete the "old"/previous nodes and start the thing again. Domoticz should use a combined Usage/ Power sensor

        M Offline
        M Offline
        MarkV
        wrote on last edited by MarkV
        #8

        @AWI
        I´m using a LAN GW, i disconnected the serial and made the LAN one of it.
        Mmm, the comms error is strange, they're at max one meter apart, with a tiny plaster wall in between, both also got a cap between vcc and gnd.
        Next weekend i´m going to have a look at the slave input, rather strange that it doesn´t receives pulses.
        I connected the 5volt line to all the 6 pulse meters and connected their output to D2 - D8, through a cord of network cable.
        Thanks for all your help so far!!!!!

        AWIA 1 Reply Last reply
        0
        • J Offline
          J Offline
          jeti
          wrote on last edited by jeti
          #9

          @AWI
          thanks! as i do not have display (yet) i just did the calculations in the "sendPowerUpdate" -> now it works perfect :smile:
          I just double check with a powermeter to see if everything is ok.

          1 Reply Last reply
          0
          • M MarkV

            @AWI
            I´m using a LAN GW, i disconnected the serial and made the LAN one of it.
            Mmm, the comms error is strange, they're at max one meter apart, with a tiny plaster wall in between, both also got a cap between vcc and gnd.
            Next weekend i´m going to have a look at the slave input, rather strange that it doesn´t receives pulses.
            I connected the 5volt line to all the 6 pulse meters and connected their output to D2 - D8, through a cord of network cable.
            Thanks for all your help so far!!!!!

            AWIA Offline
            AWIA Offline
            AWI
            Hero Member
            wrote on last edited by
            #10

            @MarkV just one tip for today... You should connect the common ground to the pulse meters. The inputs use a pull-up to vcc..

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MarkV
              wrote on last edited by
              #11

              Dawm maybe thats the problem..
              I connected the 5v as commen to the pulse + and the - to the digital inputs.

              So to be sure i need to connect the pulse + to the digitale inputs and the pulse - to gnd????

              AWIA 1 Reply Last reply
              0
              • M MarkV

                Dawm maybe thats the problem..
                I connected the 5v as commen to the pulse + and the - to the digital inputs.

                So to be sure i need to connect the pulse + to the digitale inputs and the pulse - to gnd????

                AWIA Offline
                AWIA Offline
                AWI
                Hero Member
                wrote on last edited by
                #12

                @MarkV I would depend on your S0 meters, but normal is "open collector" so you can connect '-' to ground and '+' to the input (= pull-up to Vcc).

                (another way to connect is + to vcc and - to input, but then you need external "pull down" resistors and change the sketch)

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  MarkV
                  wrote on last edited by MarkV
                  #13

                  Then thats the problem with the slave arduino getting no data. I connected the pulse output like you mentioned second and didn't changed the sketch.
                  Maybe i'm home tomorrow then i will give it a try.
                  Or is it hard to chsnge the sketch? And what should i change?

                  AWIA 1 Reply Last reply
                  0
                  • M MarkV

                    Then thats the problem with the slave arduino getting no data. I connected the pulse output like you mentioned second and didn't changed the sketch.
                    Maybe i'm home tomorrow then i will give it a try.
                    Or is it hard to chsnge the sketch? And what should i change?

                    AWIA Offline
                    AWIA Offline
                    AWI
                    Hero Member
                    wrote on last edited by
                    #14

                    @MarkV it is indicated in the sketch but you also need external resistors for pull-down. If you disable the internal pull-up resistors the levels are inverted. So you also need to'invert' the measurements or you are measuring the pulse width instead of the time between pulses.

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      MarkV
                      wrote on last edited by
                      #15

                      Tonight i checked the wires and changed them and i believe your wright, the output is:
                      Schermafdruk 2015-09-22 21.30.56.png

                      But it keeps giving a error, so i hangt them near each other with approx. 10cm space in between, why does it stil say fail after a good startup with ok and after 10a20sec it starts saying fail..

                      Is the readout correct?
                      And what more could cause the fail error?

                      AWIA 1 Reply Last reply
                      0
                      • M MarkV

                        Tonight i checked the wires and changed them and i believe your wright, the output is:
                        Schermafdruk 2015-09-22 21.30.56.png

                        But it keeps giving a error, so i hangt them near each other with approx. 10cm space in between, why does it stil say fail after a good startup with ok and after 10a20sec it starts saying fail..

                        Is the readout correct?
                        And what more could cause the fail error?

                        AWIA Offline
                        AWIA Offline
                        AWI
                        Hero Member
                        wrote on last edited by
                        #16

                        @MarkV In most of the cases "fail" is related to the power supply of the radio. Did you follow the instructions for connection of the radio?

                        1 Reply Last reply
                        0
                        • AWIA AWI

                          the code for the measurement device::

                          //---------------------------------------------------------------------------------------------
                          // Arduino Pulse Counting Sketch for counting pulses from up to 12 pulse output meters.
                          // uses direct port manipulation to read from each register of 6 digital inputs simultaneously
                          //
                          // Licence: GNU GPL
                          // part of the openenergymonitor.org project
                          //
                          // Author: Trystan Lea
                          // AWI: adapted to produce JSON and error checking at client side.
                          //---------------------------------------------------------------------------------------------
                          //---------------------------------------------------------------------------------------------
                          // Pulse Counting Class - could be placed in seperate library...
                          //---------------------------------------------------------------------------------------------
                          class PulseOutput
                          {
                          public:                                 		 //AWI: access to all
                            boolean pulse(int,int,unsigned long);                  //Detects pulses, in pulseLib.ino
                            unsigned long rate( unsigned long );                   //Calculates rate 
                          
                            unsigned long count;                                   //pulse count accumulator
                            unsigned long countAccum;                              //pulse count total accumulator for extended error checking (only resets at startup)
                            unsigned long prate;                                   //pulse width in time 
                            unsigned long prateAccum;                              //pulse rate accumulator for calculating mean.
                          
                          private:
                            boolean ld,d;                                          //used to determine pulse edge
                            unsigned long lastTime,time;                           //used to calculate rate
                          };
                          
                          //---------------------------------------------------------------------------------------------
                          // Variable declaration
                          //---------------------------------------------------------------------------------------------
                          
                          //CHANGE THIS TO VARY RATE AT WHICH PULSE COUNTING ARDUINO SPITS OUT PULSE COUNT+RATE DATA
                          //time in seconds;
                          const unsigned long printTime = 1000000;	// delay between serial outputs in us (one meter at a time)  
                          const int lastMeter = 7 ; 	 	// is number of meters + 1
                          
                          byte curMeter = 2 ;				// current meter for serial output, wraps from 2 to lastMeter
                          
                          //---------------------------------------------------------------------------------------------
                          PulseOutput p[14];            //Pulse output objects
                          
                          int a,b,la,lb;                //Input register variables
                          
                          unsigned long ltime, time;    //time variables
                          
                          void setup()
                          {
                           // take care: pull-up inverses state! line 155
                          	//setup input pins here with pull_up, else (default) float
                          	pinMode( 2, INPUT_PULLUP);
                          	pinMode( 3, INPUT_PULLUP);
                          	pinMode( 4, INPUT_PULLUP);
                          	pinMode( 5, INPUT_PULLUP);
                          	pinMode( 6, INPUT_PULLUP);
                          	pinMode( 7, INPUT_PULLUP);
                          	pinMode( 8, INPUT_PULLUP);
                          	pinMode( 9, INPUT_PULLUP);
                          	pinMode(10, INPUT_PULLUP);
                          	pinMode(11, INPUT_PULLUP);
                          	pinMode(12, INPUT_PULLUP);
                          	pinMode(13, INPUT_PULLUP);
                           
                           
                            Serial.begin(115200);       //standard serial
                            DDRD = DDRD | B00000000;
                            DDRB = DDRD | B00000000;
                          }
                          
                          void loop()
                          {
                          
                            la = a;                    //last register a used to detect input change 
                            lb = b;                    //last register b used to detect input change
                          
                            //--------------------------------------------------------------------
                            // Read from input registers
                            //--------------------------------------------------------------------
                            a = PIND >> 2;             //read digital inputs 2 to 7 really fast
                            b = PINB;                  //read digital inputs 8 to 13 really fast
                            time = micros();
                            if (la!=a || lb!=b)
                            {
                          
                          
                              //--------------------------------------------------------------------
                              // Detect pulses from register A
                              //--------------------------------------------------------------------
                              p[2].pulse(0,a,time);                //digital input 2
                              p[3].pulse(1,a,time);                //    ''        3
                              p[4].pulse(2,a,time);                //    ''        etc
                              p[5].pulse(3,a,time);
                              p[6].pulse(4,a,time);
                              p[7].pulse(5,a,time);
                          
                              //--------------------------------------------------------------------
                              // Detect pulses from register B
                              //--------------------------------------------------------------------
                              p[8].pulse(0,b,time);                //digital input 8
                              p[9].pulse(1,b,time);                //etc
                              p[10].pulse(2,b,time);
                              p[11].pulse(3,b,time);
                              p[12].pulse(4,b,time);
                              p[13].pulse(5,b,time);
                          
                            }
                          
                            //--------------------------------------------------------------------
                            // Spit out data every printTime sec (time here is in microseconds)
                            //--------------------------------------------------------------------
                            // build JSON: for all counters print Count (W), Count Accum(W), Average ms
                            // Format {"m":meter,"c":count,"r":rate, "cA":countAccum}
                            if ((time-ltime)>(printTime))    
                            {
                              ltime = time;                          	//Print timer
                              
                              {
                                Serial.print("{\"m\":"); 
                                Serial.print(curMeter-1);           	//Print meter number
                                Serial.print(",\"c\":"); 
                                Serial.print(p[curMeter].count);    	//Print pulse count
                                Serial.print(",\"r\":"); 
                                Serial.print(p[curMeter].rate(time));	//Print pulse rate
                          	  p[curMeter].countAccum += p[curMeter].count;	//Increment and print count accumulator to allow for error checking at client side;
                          	  Serial.print(",\"cA\":"); 
                                Serial.print(p[curMeter].countAccum); 
                                Serial.println("}");
                                p[curMeter].count = 0;                //Reset count (we just send count increment)
                                p[curMeter].prateAccum = 0;       	//Reset accum so that we can calculate a new average
                              }
                          	curMeter++ ;							
                          	if (curMeter > lastMeter){				// wrap a around if passed last meter
                          		curMeter = 2;} 
                            }
                          }
                          
                          // library for pulse, originally in separate file 
                          
                          //-----------------------------------------------------------------------------------
                          //Gets a particular input state from the register binary value
                          // A typical register binary may look like this:
                          // B00100100
                          // in this case if the right most bit is digital pin 0
                          // digital 2 and 5 are high
                          // The method below extracts this from the binary value
                          //-----------------------------------------------------------------------------------
                          #define BIT_TST(REG, bit, val)( ( (REG & (1UL << (bit) ) ) == ( (val) << (bit) ) ) )
                          
                          //-----------------------------------------------------------------------------------
                          // Method detects a pulse, counts it, finds its rate, Class: PulseOutput
                          //-----------------------------------------------------------------------------------
                          boolean PulseOutput::pulse(int pin, int a, unsigned long timeIn)
                          {
                             ld = d;                                    //last digital state = digital state
                             
                             if (BIT_TST(a,pin,1)) d = 1; else d = 0;   //Get current digital state from pin number
                             
                             // if (ld==0 && d==1)                      // no internal pull_up if state changed from 0 to 1: internal pull-up inverts state
                          	if (ld==1 && d==0)                         //pull_up f state changed from 0 to 1: internal pull-up inverts state
                             {
                               count++;                                 //count the pulse
                               
                               // Rate calculation
                               lastTime = time;           
                               time = timeIn ;						// correction to allow for processing
                               prate = (time-lastTime);// - 400;          //rate based on last 2 pulses
                                                                          //-190 is an offset that may not be needed...??
                               prateAccum += prate - 2000;                     //accumulate rate for average calculation
                               
                               return 1;
                             }
                             return 0;
                          }
                          
                          
                          //-----------------------------------------------------------------------------------
                          // Method calculates the average rate based on multiple pulses (if there are 2 or more pulses)
                          //-----------------------------------------------------------------------------------
                          unsigned long PulseOutput::rate(unsigned long timeIn)
                          {
                           if (count > 1)
                           {
                             prate = prateAccum / count;                          //Calculate average
                           } else 
                           {
                           
                           if ((timeIn - lastTime)>(prate*2)) prate = 0;}         //Decrease rate if no pulses are received
                                                                                  //in the expected time based on the last 
                                                                                  //pulse width.
                           return prate; 
                          }
                          
                           
                          
                          
                          
                          
                          
                          FotoFieberF Offline
                          FotoFieberF Offline
                          FotoFieber
                          Hardware Contributor
                          wrote on last edited by
                          #17

                          @AWI
                          Your measurement sketch is really nice. There is one line I do not understand.

                          prateAccum += prate - 2000;

                          Is this prateAccum needed or couldn't it be left away? What is the meaning of 2000 in this context?

                          Cu,
                          FotoFieber

                          AWIA 1 Reply Last reply
                          0
                          • FotoFieberF FotoFieber

                            @AWI
                            Your measurement sketch is really nice. There is one line I do not understand.

                            prateAccum += prate - 2000;

                            Is this prateAccum needed or couldn't it be left away? What is the meaning of 2000 in this context?

                            Cu,
                            FotoFieber

                            AWIA Offline
                            AWIA Offline
                            AWI
                            Hero Member
                            wrote on last edited by
                            #18

                            @FotoFieber To be honest .. a left over from some experiments. Just leave it out... you won't notice the difference.

                            M 1 Reply Last reply
                            0
                            • J Offline
                              J Offline
                              jeti
                              wrote on last edited by jeti
                              #19

                              @AWI thanks again!
                              I am using your sketches with only one S0 Meter (the 2000pulse/kwh one).
                              *One thing i just found out, that as long as the master arduino is connected to the serial port of my pc it is running fine but when its not, it does not send.I have checked the voltage at the radio and it is the same... I also do not have any display or rotary encoder, as I do the visualisation with FHEM.
                              Do you know why this is the case? * -> Voltage was to low... but the secon question remains:

                              Any idea to use differen pulses/kwh S0 meters? for example one 2000pulse/kwh and one 800 pulse/kwh.
                              thanks in advance!

                              AWIA 1 Reply Last reply
                              0
                              • M Offline
                                M Offline
                                marten
                                wrote on last edited by
                                #20

                                Arduino: 1.6.5 (Windows 7), Board:"Arduino Nano, ATmega328"

                                sketch_oct03e:128: error: 'V_TEXT' was not declared in this scope
                                sketch_oct03e.ino: In function 'void setup()':
                                sketch_oct03e:162: error: 'S_INFO' was not declared in this scope
                                sketch_oct03e.ino: In function 'void loop()':
                                sketch_oct03e:337: error: 'V_TEXT' was not declared in this scope
                                sketch_oct03e.ino: In function 'void incomingMessage(const MyMessage&)':
                                sketch_oct03e:364: error: 'V_TEXT' was not declared in this scope
                                'V_TEXT' was not declared in this scope

                                Dit rapport zou meer informatie hebben met
                                "Tijdens de compilatie uitgebreide uitvoer weergeven"
                                ingeschakeld in Bestand > Voorkeuren.

                                M AWIA 2 Replies Last reply
                                0
                                • M marten

                                  Arduino: 1.6.5 (Windows 7), Board:"Arduino Nano, ATmega328"

                                  sketch_oct03e:128: error: 'V_TEXT' was not declared in this scope
                                  sketch_oct03e.ino: In function 'void setup()':
                                  sketch_oct03e:162: error: 'S_INFO' was not declared in this scope
                                  sketch_oct03e.ino: In function 'void loop()':
                                  sketch_oct03e:337: error: 'V_TEXT' was not declared in this scope
                                  sketch_oct03e.ino: In function 'void incomingMessage(const MyMessage&)':
                                  sketch_oct03e:364: error: 'V_TEXT' was not declared in this scope
                                  'V_TEXT' was not declared in this scope

                                  Dit rapport zou meer informatie hebben met
                                  "Tijdens de compilatie uitgebreide uitvoer weergeven"
                                  ingeschakeld in Bestand > Voorkeuren.

                                  M Offline
                                  M Offline
                                  marten
                                  wrote on last edited by
                                  #21

                                  this is what i'll get when trying to upload the master sketch

                                  1 Reply Last reply
                                  0
                                  • M marten

                                    Arduino: 1.6.5 (Windows 7), Board:"Arduino Nano, ATmega328"

                                    sketch_oct03e:128: error: 'V_TEXT' was not declared in this scope
                                    sketch_oct03e.ino: In function 'void setup()':
                                    sketch_oct03e:162: error: 'S_INFO' was not declared in this scope
                                    sketch_oct03e.ino: In function 'void loop()':
                                    sketch_oct03e:337: error: 'V_TEXT' was not declared in this scope
                                    sketch_oct03e.ino: In function 'void incomingMessage(const MyMessage&)':
                                    sketch_oct03e:364: error: 'V_TEXT' was not declared in this scope
                                    'V_TEXT' was not declared in this scope

                                    Dit rapport zou meer informatie hebben met
                                    "Tijdens de compilatie uitgebreide uitvoer weergeven"
                                    ingeschakeld in Bestand > Voorkeuren.

                                    AWIA Offline
                                    AWIA Offline
                                    AWI
                                    Hero Member
                                    wrote on last edited by AWI
                                    #22

                                    @marten You need to use the "Development" branch of MySensors until the production version gets updated -or- you can uncomment the lines with "const int ..."

                                    // new V_TEXT variable type (development 20150905)
                                    //const int V_TEXT = 47 ;
                                    // new S_INFO sensor type (development 20150905)
                                    //const int S_INFO = 36 ;
                                    
                                    1 Reply Last reply
                                    0
                                    • J Offline
                                      J Offline
                                      jeti
                                      wrote on last edited by
                                      #23
                                      This post is deleted!
                                      1 Reply Last reply
                                      0
                                      • J jeti

                                        @AWI thanks again!
                                        I am using your sketches with only one S0 Meter (the 2000pulse/kwh one).
                                        *One thing i just found out, that as long as the master arduino is connected to the serial port of my pc it is running fine but when its not, it does not send.I have checked the voltage at the radio and it is the same... I also do not have any display or rotary encoder, as I do the visualisation with FHEM.
                                        Do you know why this is the case? * -> Voltage was to low... but the secon question remains:

                                        Any idea to use differen pulses/kwh S0 meters? for example one 2000pulse/kwh and one 800 pulse/kwh.
                                        thanks in advance!

                                        AWIA Offline
                                        AWIA Offline
                                        AWI
                                        Hero Member
                                        wrote on last edited by
                                        #24

                                        @jeti as mentioned in a previous post..

                                        There are a few ways of getting it changed:

                                        You can keep/ leave most as it is and when you send/ or display the values divide the pulses by two and double the Watt values in the routines "LCD_local_display" and "sendPowerUpdate"

                                        or: make the necessary calculations when the data comes in. This is a little more complicated in routine "storeMeterJSON" but if you understand the logic (including error corrrection) should be not too hard.

                                        I don't have the time at this moment to do it for you...

                                        J 1 Reply Last reply
                                        0
                                        • AWIA AWI

                                          @jeti as mentioned in a previous post..

                                          There are a few ways of getting it changed:

                                          You can keep/ leave most as it is and when you send/ or display the values divide the pulses by two and double the Watt values in the routines "LCD_local_display" and "sendPowerUpdate"

                                          or: make the necessary calculations when the data comes in. This is a little more complicated in routine "storeMeterJSON" but if you understand the logic (including error corrrection) should be not too hard.

                                          I don't have the time at this moment to do it for you...

                                          J Offline
                                          J Offline
                                          jeti
                                          wrote on last edited by
                                          #25

                                          @AWI: :smiley: nevermind I will start workin on it
                                          Thanks again for the great work!

                                          J 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          16

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.1k

                                          Posts


                                          Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

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