First let me say thanks for an awesome product (EmonPi) and all the information in the guides, etc.
I am pretty new to Arduino and RaspberryPi in general so bear with me if that’s OK.
So I received a complete EmonPi system yesterday and I managed to set it up, power it up and connect it to an appliance AC power cord line I’d like to monitor. I currently get a power and voltage measurement but as I am in the USA I get an incorrect reading out of the box. I red all the thread about USA use but it’s more about house setup and usage. I don’t want to measure a whole house power, just measure the power used by an appliance (I’m tapping the power cord for the current probe), for an industrial/professional application.
I am trying to figure out how to change the .ino file and upload it to my EmonPi. I am a bit of a loss here. I know how to program a separate arduino board but can’t figure out how to program the EmonPi.
Do I need the programmer and open the EmonPi enclosure to reprogram?
This instruction is in the wiki. .hex file upload command: $ avrdude -v -c arduino -p ATMEGA328P -P /dev/ttyAMA0 -b 115200 -U flash:w:sketch_name.hex
I just have no idea how to use this. Can’t I just connect via the USB cable and program with the default arduino software (working in Windows 7) with the .ino file I found on github here? I seem way off here…
I will also want to speed up the reading to at least one per second (or faster?) and be able to read the power, current and voltage data on USB, Ethernet or wifi directly from a custom application that will reside on a separate PC.
Any guidance or direction on how to start by changing and reprogramming the .ino file to work properly for the USA on a single appliance would be very much appreciated.
The Use in the USA page in Resources isn’t only about whole house monitoring, you can apply the principles to a single machine if you wish, but bear in mind that the default current transformers are rated for 100 A, so you might need to choose a CT that’s rated lower to give you better accuracy. (And you see why I suggest not opening several threads - I had to go back to look at the other one to find the load you are trying to measure.)
Programming the ATMega328P inside the Pi is a multi-stage operation. First, you need to get the sketch into an editor and change it. You can do this inside a laptop/desk computer or in the Pi. If you do it inside the Pi, you’ll need to load the Arduino IDE. Then you must compile it and find the result of the compilation. Finally, you transfer the compiler .hex file into the Pi (if it’s not already there) and load it using the inbuilt serial interface to the emonTx board inside the PI. That’s where the “avrdude …” command comes in.
So no, you can’t open up the Pi and connect a programmer via USB because there isn’t a FTDI connector inside, and the USB is power only. So you don’t need and can’t use a programmer.
But you can speed up the readings (unless you’re using emoncms.com - that’s rate limited to give everyone a fair share).
So I managed to get all the source files and libraries, make the changes and recompile on my PC to a new set of hex files “emonpi_usa.hex” and “emonpi_usa_bootloader.hex”.
I had to remount the filesystem to be writable with ‘$sudo mount -o remount,rw /dev/mmcblk0p2 /’.
I uploaded the new hex files to the ‘~/emonpi/firmware/compiled directory’ and run a modified ‘update’ script using my file names. It runs through properly without errors. When I run the ‘reset’ script I can then see the correct power reading updating every second.
When I reboot the emonPi though, the power reading is still the previous non-usa reading. If I run the ‘reset’ script only via command line, then I get the correct reading.
Why the need for that ‘reset’ every time I boot? Do I need to fix something else to boot on the correct reading?
Side note, when running the reset command, the LCD screen with go black, come back up and will cycle through the menus. When it gets to the “Raspberry Pi / Booting…”, the first like “Raspberry Pi” will change to the correct power reading but the second line with stay on “Booting…” until I press the LCD button to cycle through.
Secondary question about the sensor. I can work with the default 100A for now but as you mentioned I would probably be better going with a lower rated sensor. I was reading another thread (here) that pointed me to this sensor which is rated up to 25A. This is a voltage output sensor (1V according to datasheet) compared to the 100A one which I believe is a current output sensor. Note that accuracy is not necessarily a huge concern for me at this point and if I need to manipulate the reading from software somehow, if that is possible, that it fine. I have read this page but I am not too sure if sensor would work out of the box of if I had to do some modifications on the resistor as suggested in the other threads. Any direction on this is appreciated.
That script just pulses the reset pin briefly to reset the AVR, it was a debugging tool and shouldn’t be needed for normal use.
If you are saying everytime you reboot you are getting no data until you use that reset script that would suggest something is “locking up” during the boot sequence because the same firmware is running before and after you use the “reset command” it is just re-starting the AVR at that time ie after the boot-up is complete.
Have you updated the emonpi image? you may well need to reload your firmware again afterwards as the updater will overwrite the sketch unless you disable uploading.
This maybe where the confusion is seeping in. Have you set the “USA flag” in emonhub.conf? The flag in the sketch is controlled by emonhub via the serial port, so if emonhub is set for UK it will set the firmware to UK at each reboot and then when you use the reset command the new firmware default of USA will be used until emonhub corrects it at the next reboot.
A quick check to test for this would be to issue a simple “sudo service emonhub restart” command when the system is running in USA mode, (it is slow to restart as it closes all the connections before stopping) if that returns it to UK mode again that is the issue and editing the emonhub.conf should fix it.
I wish I could link you to the guide for this but I couldn’t find it and emonhub doesn’t even appear in the site -navigation.
Thanks for the reply and sorry it took me so long to follow up on this.
I am using the kit with the fully assembled emonPi, the 5V AC:DC and the 9V AC:AC all plugged in on the same circuit my test appliance (an LCD display) is plugged in.
After running in USA mode (after a reset), I ran “sudo service emonhub restart”. This does indeed reset the measurement to the UK values. If I do a reset again, it goes to USA values.
I modified the one line in “emonhub.conf” to “calibration = 110V” but it still reverts to the UK values after the above restart command.
I also tried to change the values in “emonpi.default.emonhub.conf” but the problem is still there, going to UK values.
Note that I did not want to overwrite the “latest.hex” firmware file in the complied directory but added my modified hex files with a new name, which I programmed. I thought this could cause an issue so I tested with renaming my new usa hex files for latest but the problem is still there.
Sorry for not spotting this thread sooner. No firmware change should be required to use the emonPi in the USA. You just need to use a USA AC-AC voltage sensor adapter and set calibration = 110V in [[RFM2Pi]] section of emonhub.conf. Appologies if this was not clear, I have just re-factored and elaborated on emonHub config documentation. I will also add a section on ‘Use in the USA’ to the Setup Guide.
If you do want to change the firmware, it’s best to compile the Arduino sketch on your PC then transfer the .hex to the emonPi and upload directly from the RaspberryPi using avrdude. Emonhub will need to be stopped to free up the serial port. See example script to upload .hex.
If the voltage reading is precisely 110V or 220V it sounds like the AC-AC adapter has not been detected. The AC adter needs to be connected before powering on the unit. You should see “AC wave detected” on the LCD display at power up.
No, the latest version is emonSD-03May16. We switched to the new version on 11th May, see blog post your unit must be one of the last to be shipped with the old image! I apologise for this. We would be happy to send you our an SD card with the new image if you like or you can download yourself.
The AC-AC is detected, it does not read exactly 220V voltage, sorry about the confusion. It varies over times around 218-220V in the screen. I see the AC wave detected at boot-up. Still reads the incorrect voltage though.
I can update the unit if there is a tutorial that can show me how to do that, no problem!
EDIT: Never-mind, I see the links in the blog post. I will check that.
EDIT: I noticed that once logged in on the Emoncms webpage, I could change the conf file there. Interestingly, even though I changed it via command line directly, it would still show the calibration = 230V on the web page. Was I modifying the wrong file in emonhub/conf/emonhub.conf?
In any case, it seems that modifying the file from web interface worked and I do now see the correct Vrms and the correct Power measurements after reboot.
I guess this solve my issue here.
I’d still like to learn how to update the image (see my original message below).
OK, so I tried to update via the web interface Admin > Update emonPi.
I see the message /tmp/emonpiupdate file flag created, update will run on next cron call in: 44s.
I see the Updating message on the screen. It takes about 20s to reboot but then I still see the same version 17Jun2015 after reboot.