By the way, is emonTH able to connect to open collector? It is powered with an atmega328 and have the same GND and IRQ1. But i couldn’t find about the resistor.
The emonTH V2 has the pulse input on screw terminals. If you look at the sketch, you’ll find exactly the same line:
That turns on the internal pull-up resistor inside the ATMega 328P.
I got it installed today and working just fine!
Thanks for the help!
If i install emoncms to a simple raspberry pi and connect the SO open collector, wich pins should i connect?
(Raspberry pi model B)
My brother has a raspberry pi and since i don’t know much of it, i am afraid to mess it up.
I think you need to look here: Pulse monitoring on a Pi
Paul’s script there appears to be using pins 13 & 15.
If the software is applying a pull-down, you connect the SO output between the GPIO pin and the 3.3 V power.
Thanks for the quick response!
I see, but as i could read here: https://github.com/ondrej1024/emond
"emond is being developed and tested with this type of simple energy meter that was installed in addition to the one provided by the energy company:
The cabling has to be done as follows:
S0- output on energy meter to GND on RaspberryPi S0+ output on energy meter to GPIO[x] on RaspberryPi
No external pullup resistor for the S0+ line is required as the RPi internal pullup will be enabled by the software."
So, its confusing me at connecting the wires, as it don’t talk about the 3.3v.
And searching on the web, as i dont have much knowledge of electronics, i couldn’t find any “simple” explanation for my lack of knowledge.
And shouldn’t emoncms detect the input, once its connected?
Sorry bothering you about this.
I think the explanation is simple. One chose one way, the other person chose the other way. Both are valid ways of getting almost the same result.
Paul Burnell has chosen to connect between +3.3 V and GPIO pin 13 (for his 1st input) and has specified “pull down” in software
pull_up_down=GPIO.PUD_DOWN; and the GitHub contributor has chosen to connect betwween the GPIO pin and GND, and has chose “pull up” in software.
The choice is yours. The difference is what the ‘contact closed’ means in software. In Paul’s case, it is a logic 1 (true), in the Github case it is a logic 0 (false).
Now that you explain that, i can see how it works.
How did i miss this(???):
“So if you wire the switch between input and ground, so the switch pulls the input to 0 V when it’s closed, you need a “pull-up” resistor to pull the input up to 3.3 V or 5 V when the switch is open. And vice versa”
I really need to read carefully this Directly connecting to Optical Pulse Counter with RPi?
Robert, i am very grateful for you help!
You might need to choose based on how your logic works - or change your logic.
Personally, normally, I would choose to wire the switch to GND, then a fault to earth on the switch wiring does not burn out the 3.3 V power supply.
Well, the open collector will be the one that i posted at the beginning.
The choice will depend of what emoncms allows me to do without messing up much with the system files but i would like to avoid burning anything so, connecting it to gnd is the most safe decision.
Actually, i thought that was just connect the wires to the open collector and emomcms (i installed the latest image provided by openenergymonitor on a sd card) would detect it automaticaly (sorry, not sure if is well translated).
Already have a emonpi connected to the collector, i assumed that was just connect the raspberry pi with the same software and the result would be the same. Didn’t know about the logic and the pins.
It will take some time to learn and see, as i dont want to bothering everyone every 5 min and i want to learn how to do it.
If you want to use the pulses.py script with pull-ups and wire the switch between ground and input, you just edit the 2
pull_up_down=GPIO.PUD_DOWN lines to
The pull-up or pull-down is just to counter the way you wire the switch, the sketch will work the same way, the pulse is just the change of state and the pull-up or pull-down is to ensure the state does change and not hang/float.
Think of the pull-up or pull-down as a spring, if your switch or sensor is “pushing” the switched wire down to ground you want it to spring back to 3.3v when it’s finished ie pull-up (to 3v) If your switch is pushing the switched wire up to 3.3v, you want the “spring” to pull it back down to ground when it’s done ie “pull-down”.
And emoncms will detect when the switch changes its state? Or do i need to change something on emoncms configuration to see the input?
EDIT: Forguet that!
With a little more time to read the pulses.py script, i can now understand more about how it works.
By the way, node-red has a node that receives a state change from digital input on a selected pin. I am exploring it to receive state change on gpio pin 13 since is more easy for me, as i don’t understand much of programing.
Just don’t know what means the “HTTP Issue” and how to acumulate the raw pulse, i don’t know yet how to do it.
Here is some screenshots:
What do you think, Paul?
Sorry you’re asking the wrong person there, I don’t know much about using node-red.
@Paul might be able to help you.
Regards accumulating pulses in emoncms you should look at using a “whaccumulator” or a “total pulse count to pulse increment” process if there is any chance of the pulsecount ever resetting eg a reboot or power outage or variable rollover. These 2 processes have a “ratchet” type input so that the difference between the current and last pulsecount is added to the persisted running total rather than using the live running total.
Ah I see that you are using the ‘node-red emoncms’ node!
I personally do not use it as it doesn’t work well at the moment, and others are finding the same problem as you, see Node-red error with update
You could log an issue in the git repo for that node if you wish.
I change it to a whaccumulator now.
Regarding the script, how do i install it on the rpi? Since i don’t know how to transfer it to the rpi i tryied to login by ssh, create a file pulses.sh and running it but i got some errors.
Then i login by ssh on my ubuntu files manager but don’t know where to put the script and i don’t find any reference about the place where i shall put the script and run it.
I can login as ssh on my pc file manager and see the rpi folders but don’t know where to put the script.
Appart from the http issue, i still get the input info to emoncms localhost and emoncms.org, so, for now, everything is fine, from what i can see.
I must say, its way more easy to use node red from a newbie perspective but i would like to try it from the both ways.
Thank you both for the help!
Sorry @pb66 but i have been trying to use the script but really don’t know how to install it.
Can you tell me what commands do i need to use?
Sorry bothering you again with this.
The pulses.py file is Python not Bash/Shell. so it needs the “.py” extension, not “.sh”.
wget download the file from the forum to your home folder and rename it
pulses.py, then make it and executable file with
wget -O ~/pulses.py https://community.openenergymonitor.org/uploads/default/original/2X/b/b7b150dec028e86f25d5a6e4b0a959e4a774448f.txt chmod +x ~/pulses.py
You can edit the script with
nano if you need to change pin numbers etc
Then you should have a working
pulses.py script that can be run with
To stop the script use CTRL-C
In the script there are some
In the above instance, closing your shell console (ssh or login screen) will terminate the script. You can as a temporary thing start the script will
make a note of the PID number that command gives you as you need that to terminate the script at a later date with a command like
sudo pkill -9 123
where “123” is the PID number of
Eventually you will want to start this as a daemon service so that the OS manages it’s start up at boot time etc.
I will try to write a post on that in the coming days I do not have anything prepared and you are not the first to ask so I will try and find the time to put something together. But the above should get you started at least.
A few weeks i was able to make it work but now , on a new installation, it guives this error on terminal:
File “/home/pi/pulses.py”, line 118, in
File “/home/pi/pulses.py”, line 103, in main
GPIO.add_event_detect(pulse_pin1, GPIO.BOTH, callback=eventHandler1, bouncetime=bounce)
RuntimeError: Failed to add edge detection
Any idea why?
Note: I didn’t edited the script.
No sorry I don’t, i just had a quick web search and found nothing that stands out. You check you do not have other stuff trying to use the same gpio pins and check the pin numbers you are using are correct.
I already search it too and couldn’t find anything either.
I will try to find out why and will report it here.