EmonTX to Rpi - Direct Serial Connection

So the final step on my odyssey (possibly)

3D printed case (link above), a right angle header and a short cable made up with a crimp tool makes for a very clean setup. Pi is then powered off the 5V DC to the emonTX (it works the other way as well).

End cost is slightly more than the emonESP, but far more flexible, can update firmware and no need for emoncms on a second machine/Pi. My aim is to install this at a friend’s house for a month and see if Agile will save him money. If it does the £50 referral will more than cover the cost of the Pi & case!

1 Like

Nice work. Very clean, indeed! thumbsup

1 Like

Some time ago I sought some advice re direct serial connection - thanks for all the input. Background was that I was planning to co-locate and number of pieces of kit - and preferred a “wired” approach where possible.

The direct serial link is the last item to be completed - the unterminated cables showing in the photo - but interesting to learn that the emonTx->emonPI wireless link seems to have no problem operating even when in close proximity (saturation of the receiver could have been an issue). Its been working reliably for some weeks now. RSSI reporting as -30dbm so reasonably strong but clearly not so much to cause an issue - still well within the receiver spec. The RFM69C was clearly an excellent choice!

1 Like

Nice neat setup :grin:.

Is the emonPi receiving anything other than the emonTX? If not it will be redundant with the direct serial link. Is the Pi doing anything else? If not, just install emoncms onto the Pi.

Look at my photos above. You will need a wired link between the emonTX UART and the GPIO on the Pi. As that is a Pi 4 do not power it off the Tx (so no power or ground wires).

I note you are only powering the emonTX via the VT/ AC/AC supply.

What is the USB power supply you have there?

[edit]
What is the box below the TX?

1 Like

Thanks Brian! I had received “local feedback” that it would look even neater when i fix a cover over it all…:slight_smile:

Good question - yes it is, the emonPi also captures stats from a Powerwall. At this stage i’m keeping key functions separate - once its all working as I want it to there will be some integration/consolidation. At present, the boxes do the following… (anti-clockwise from the emonTX top left).

emonTX - CTs on the two PV arrays, grid incomer and Powerwall connection.

Little Black Box - Pi Zero with ethernet HAT - designed as the “always on” control - collects Solcast forecasts, provides generation “actuals” to Solcast for tuning. Also downloads tariff data from Octopus. Controls Powerwall charging based on predicted use and “next day” generation forecast (very much “work in progress”).

USB power supply is a RAVpower one - find them very reliable.

Grey box is Netgear router - spare port for the rainwater harvesting control (next on the list!)

Pi 4 in the middle is my development box, with a SSD under. Not intended to be “always on” Also holds master database, sync’ing from emoncms & the PiZero local databases as and when.

Code is primarily Python/Mysql at the moment…mainly as a learning curve to understand how integration needs to work, then I will migrate to NodeRed (another learning curve!) for longer term simplicity.

Re your comment re power supply to emonTX - I thought I had read that in this config, the 9V ac could provide the sample waveform & power the unit - do I have that wrong? (or if not wrong, is adding USB supply “preferred”?)

I think so @Robert.Wall can give a definitive answer.

Re serial connection, you can only really do that to a Pi not an emonPi.

[edit]
https://www.ravpower.com 44 cookies, no cookie notice - straight in the block list! Had a look on Amazon instead :laughing:.

If you intend to add the ESP8266 Wi-Fi module, then a 5 V d.c. supply is necessary. If you operate the RFM69CW transmitter at maximum power, or you have more than 3 DS18B20 temperature sensors, or you use the 3.3 V for something else, or your mains voltage is low, then you probably need a 5 V d.c. supply. Otherwise, the supply derived from the 9 V a.c. voltage monitor might actually be better because it appears to be cleaner than the “Shop” 5 V d.c. USB adapter.

1 Like

Just for my reference really, if you use my method for connecting, you need to change the rst Pin specified.

I used it as it was easy to create a header that just plugged in and prevented accidental overwriting.

The change to be made is found in the file /opt/openenergymonitor/avrdude-rpi/autoreset

Change to pin 12.

@borpin - Brian, can I ask where you found the 90 degree female > female header adapter? I can only find male > male, or male > female. The latter would require starting with a Zero without header pins.

TIA

ThePiHut - ordered with the PiZ.

Oh it isn’t an adapter. It needs to be soldered.

1 Like

@borpin is your emonTx connected using the 9V AC and the 5V USB DC per my photo below:

image

I am running the emonTx_3Phase_PLL sketch (with node id 17) and have edited emonhub per the below:

### This interfacer manages the EmonTx3 ESP format serial
[[SerialTx3e]]
 Type = EmonHubTx3eInterfacer
  [[[init_settings]]]
       # Un-comment line below if using RS485 adapter
       com_port = /dev/serial0
     #com_port = /dev/ttyRS485-0
     # default com port if using USB to UART adapter
     #com_port= /dev/ttyUSB0
       com_baud = 115200
  [[[runtimesettings]]]
       pubchannels = ToEmonCMS,

[nodes]
## See config user guide: https://github.com/openenergymonitor/emonhub/blob/emon- 
pi/conf/emonhub.conf

[[17]]
    nodename = emonTx_three_phase17
    firmware = three_phase
    hardware = emonTx V3.2/V3.4/Shield
[[[rx]]]
    names = power1, power2, power3, power4, sumPower, Vrms, temp1, temp2, temp3, temp4, 
    temp5, temp6, pulsecount
    datacodes = h, h, h, h, h, h, h, h, h, h, h, h, L
    scales = 1,1,1,1,1,0.01,0.01,0.01,0.01,0.01,0.01,0.01,1
    units = W,W,W,W,W,V,C,C,C,C,C,C,p

I have the following in the sketch:

[[17]]
    nodename = emonTx_three_phase17
    firmware = three_phase
    hardware = emonTx V3.2/V3.4/Shield
[[[rx]]]
    names = power1, power2, power3, power4, sumPower, Vrms, temp1, temp2, temp3, temp4, 
    temp5, temp6, pulsecount
    datacodes = h, h, h, h, h, h, h, h, h, h, h, h, L
    scales = 1,1,1,1,1,0.01,0.01,0.01,0.01,0.01,0.01,0.01,1
    units = W,W,W,W,W,V,C,C,C,C,C,C,p

I’m not getting anything through on emonhub though:

I’m currently testing this on a Pi4 as my Ethernet dongle stopped working yesterday so can’t connect my PiZero until a new one arrives. So I have the Pi4 powered up using the USB-C port and the emonTx powered up using the 9V AC. I then have the 3x jumper leads connecting the two (with Rx from the emonTx into the RXD on the Pi4). I don’t have the 5V DC plugged into the emonTx. If I do plug in the 5V DC and take out the USB-C from the Pi4, it doesn’t have enough power to run the Ethernet port.

You need to connect to the Pi to the UART on the other end. You also will get nothing unless the CTs are connected before powering on.

As per EmonTX to Rpi - Direct Serial Connection - #61 by borpin

If using the serial output, you don’t need to worry about the node definition as you will get text. The Node definition is needed to decode the wireless RFM packets.

Oh ignore that I was working off the photo.

3 leads connected to what? If you power the Pi4 separately, then just connect TX & RX (2 leads).

If you connect the PiZero with 5V and Gnd as well, you can power it from the EmonTX.

[edit]
Check the actual serial received by the Pi using

$ miniterm /dev/ttyAMA0 115200

Thanks @borpin I got the following when using miniterm:

This is with GND, 5V and Rx going to the Pi4 GND, 5V and RXD. I don’t intend to send information back to the emonTx so only using a single lead

If I change the baud rate to 9600 then i get the following:

@Robert.Wall - looks like the sumPower you helped me with isn’t coming through. Do I need tp change anything with the interfacer for this?

I’ve changed the Interfacer settings in emonhub, but still not getting any data through to the inputs screen

[[SerialTx3e]]
 Type = EmonHubTx3eInterfacer
  [[[init_settings]]]
   com_port = /dev/ttyAMA0
   com_baud = 9600
  [[[runtimesettings]]]
   pubchannels = ToEmonCMS,

I don’t have anything to connect the CT clamps as i’m trying to get it set up at home and then install on location. I’m only looking to see that there is a connection even if the values are all zero

emonTx - GND / 5V / Rx going to Pi4 - GND / 5V / RXD

If you open up the c.t. and put it on or close to the a.c. adapter, you’ll see enough current to know it’s working. It’s when it is not plugged in that the input is shut down and displays a solid zero; when it’s plugged in, you should see something.

If the data is going as key:value pairs, it should show up. If it isn’t, then you need the node definition to match the data that’s being sent.

sorry @Robert.Wall I don’t understand what you mean. I have the same config in the sketch and in the emonhub config. I tried deleting the additional sumPower value, but that didn’t have an effect.

Sketch:

  [[17]]
    nodename = emonTx_three_phase17
    firmware = three_phase
    hardware = emonTx V3.2/V3.4/Shield
  [[[rx]]]
    names = power1, power2, power3, power4, sumPower, Vrms, temp1, temp2, temp3, temp4, 
    temp5, temp6, pulsecount
    datacode = 0
    scales = 1,1,1,1,1,0.01,0.01,0.01,0.01,0.01,0.01,0.01,1
    units = W,W,W,W,W,V,C,C,C,C,C,C,p

Emonhub:

[[17]]
    nodename = emonTx_three_phase17
    firmware = three_phase
    hardware = emonTx V3.2/V3.4/Shield
  [[[rx]]]
    names = power1, power2, power3, power4, sumPower, Vrms, temp1, temp2, temp3, temp4, 
    temp5, temp6, pulsecount
    datacode = 0
    scales = 1,1,1,1,1,0.01,0.01,0.01,0.01,0.01,0.01,0.01,1
    units = W,W,W,W,W,V,C,C,C,C,C,C,p

Its showing something. I still don’t get the 5th power value (sumPower) though

How is it getting assigned a value in your sketch? Because it looks as if it isn’t. That’s where you need to look.

@Robert.Wall - this is what you advised me to do when I was connecting over RF. I can’t see where this needs to be edited for Serialout in the sketch though

Do I need to add a row to this section to add in the sumPower?:

  #if defined SERIALOUT && !defined EMONESP
  Serial.print(nodeID);     Serial.print(' ');
  #if WIRES == 3-WIRE
  Serial.print((int)(realPower1+0.5) + (int)(realPower2+0.5));   // These for compatibility, but whatever 
  you need if emonHub is configured to suit. 
  Serial.print(F(" 0.0 "));
  #else
  Serial.print((int)(realPower1+0.5)); Serial.print(F(" "));   // These for compatibility, but whatever you 
  need if emonHub is configured to suit. 
  Serial.print((int)(realPower2+0.5)); Serial.print(F(" "));
  #endif
  Serial.print((int)(realPower3+0.5)); Serial.print(F(" "));
  Serial.print((int)(realPower4+0.5)); Serial.print(F(" "));
  Serial.print((int)(Vrms*100));
  Serial.print(F(" "));

I would suggest that, as you are modifying the sketch, you create the serial output to match the EmonHubTx3eInterfacer data format and you can then ignore the node definition etc.
e.g.

MSG:1,Vrms:244.74,P1:116,E1:0,pulse:1

Key:Value pairs, separated by commas, start with the MSG: counter.