Counter node with gpio

#1

I use a counter node to measure rain fall at my home. It sends a pulse every 0.2 mm but the node reads the value twice. Is there anyone who knows how this block counts i.e. on a rising edge falling edge both ?

0 Likes

#2

I would guess the counter counts any input it sees - and the gpio will be producing a 1 and 0 - so as you said both edges... - You can either divide the count by 2 ... or use a switch node to only let (say) the 1 value through to the counter.

1 Like

#3

Which counter node, I see from flows.nodered.org that there are several. It may be node-red-contrib-counter for example, or it may be one of the others.

0 Likes

#4

Try a RBE node?

0 Likes

#5

RBE won't help... the gpio will send 1 then 0 - so will go through RBE... - the counter will count any input so will count the 1 and then the 0 ... - so you just want to send the 1 (or the 0) .

0 Likes

#6

Oops, didn't think that one through at all Dave!

0 Likes

#7

Just filter with a switch if msg.payload = 1 so you eliminate the zeros..

0 Likes

#8

The node I use is
https://www.npmjs.com/package/node-red-contrib-counter

0 Likes

#9

The first line of the Usage section in the readme of nod-red-contrib-counter reads "By default the counter will be incremented for every inbound message ". It takes no notice of the contents. If you only want it to count when the value is now 1, for example, then you can use a Switch node to only pass on those messages to the counter, as has already been suggested I think.

1 Like

#10

Finally with a switch node everything is fine. It counts exactly as expected. I also learn how to work with the switch node! Thanks for the help!

0 Likes

#11

A bit late to the party, I know -- but for future reference, you could use https://flows.nodered.org/node/node-red-contrib-statistics to calculate a "sum" of the payloads received. Since half of your msg.payload values are 0, I believe it would give you the same answer without having to use a switch node to filter out half of the msgs...

0 Likes

#12

I am not certain, but I think that will retain all previous values received in order to perform the statistical calculations. If that is correct then it is not appropriate for a situation like this as the size of the array will grow without bounds. Also the time taken to calculate the average may well get longer and longer.

1 Like