EmonTX to Rpi - Direct Serial Connection

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.

He doesn’t need to CREATE one - there’s one already there:

 #if defined EMONESP && !defined SERIALOUT

because as I understand it, emonESP and EmonHubTx3eInterfacer are effectively synonymous.

So if @rdc-Green wants to add it in that section, just below

    Serial.print(F(",ct4:")); Serial.print(realPower4);

then it’s roughly as he did for the r.f. output

    Serial.print(F(",sumPower:")); Serial.print(realPower1+realPower2+realPower3realPower4);

By default, that will come as the sum to 2 decimal places.

Thank you again for your help @Robert.Wall. Unfortunately your suggestion above didn’t work, but it did show me what i needed to do.

I went to the set of code above and added the following:

Serial.print((int)(realPower1+realPower2+realPower3+realPower4+0.5)); Serial.print(F(" "));

This now gives me this output in miniterm, which is what I would expect:

Even though i can see output in miniterm, its still not coming through on the inputs screen. My config file is:

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

and

[[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

This is the code from 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
    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

It looks as if you put it in the wrong place, you should not have any spaces in the string for the ESP format. If you look at all the other variables and their print statements that make up the string, the format I gave you is exactly the same.

I can’t help you any more with the interfacer, I don’t know the inner workings and I’ve never found where it is properly documented.

I think that is the wrong interfacer (the text string is in the wrong format - it expects the format I mentioned above). Not sure what the right interfacer is though.

[edit]
It may be this one (you do need spaces)

If that’s the case, then you need to do much the same in the

#if defined SERIALOUT && !defined EMONESP

section, copying the format of the lines around it. There’s no need to remove it from the unused sections - they don’t even get compiled. (That’s what the #ifdef ... does.)

As I understand it:

The “normal data” output (from the radio) is a byte stream that needs a Node Definition in emonhub.conf to tell emonhub how to parse out the values, scale them, and their names in order to pass this on to emoncms.

The “normal” serial output (“SERIALOUT”) is space-separated integer values only without their names, thus you need a Node Definition in emonhub.conf to scale the values and tell emoncms what the names of the variables are.

The “key:value pairs” serial output (“EMONESP”) is comma-separated pairs of the variable name and value separated by a colon. The values can be floating-point values and no Node Definition is therefore required.

If I get time later, I’ll try to run a definitive test to check the accuracy of the above.

Hi @Robert.Wall and @borpin Thank you again for your help with this. I now have values coming through emonhub per the screen shot below:

I’ll create a post shortly that details the steps I went through to get this working. Hopefully it will make sense for the next person to use.

1 Like

Please see steps below to enable emonTx 3P to RPi4 over serial using the emonTx_3Phase_PLL sketch. Thank you to @Robert.Wall and @borpin for your help with this.

The sketch has been edited to include a sum of the 3 phases to pull through a single kWh figure (sumPower).

I have edited the sketch as follows:

  • edited the emonhub.conf node decoder:

    [[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
    
  • changed ‘//Output Settings’ on row 82 to ‘SERIALOUT’

  • added ‘sumPower’ to row 300

  • added the following below row 838:
    emontx.sumPower=(int)(realPower1+realPower2+realPower3+realPower4+0.5);

  • added the following below row 930:
    Serial.print((int)(realPower1+realPower2+realPower3+realPower4+0.5)); Serial.print(F(" "));

In emonhub I added the following interfacer:

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

I finally added the the node below:

[[99]]
    nodename = my-serial-device
    [[[rx]]]
       names = power1, power2, power3, power4, sumPower, vrms
       datacode = 0      
       scale = 1        
       units =W,W,W,W,W,V

The emonTx is connected to the RPi4 over serial per the diagram here:

Direct connection emonTx V3 > Raspberry Pi GPIO

The RPi4 is powered using a USB-C PSU and is connected via Ethernet. The emonTx is powered by the 9V AC PSU.

I have also connected a RPiZero W to the emonTx using the jump leads per the diagram above. The RPiZero W is powered directly by the emonTx, with the emonTx being powered by the 9V AC and the 5V USB DC PSUs. I added wifi to the SD card before putting it in the RPiZero W

1 Like

Thanks rdc-Green (and Robert and Brian) for the info on configuring the three phase sketch with direct serial connection to a rpi running emoncms. As a first time user of this equipment (but some experience with other Arduino and RPi projects), the documentation available for this process seems quite scattered across countless pages and forum posts with possibly crucial details missing. There is also a lot of conflicting info relating to ostensibly similar configurations which makes it more confusing than it probably needs to be. Can I suggest a definitive step-by-step guide be included somewhere as a Guide or on the Learn section of the website? Once I get this sorted I’ll be writing it up for my own purposes (memory like a sieve) so happy to contribute…

From lots of reading on the forums, guides and docs etc I formed the interpretation that the EmonHubSerialInterfacer [SerialDirect] was an older/less ideal/supported method than the EmonHubTx3eInterfacer [SerialTx3e] (eg: @glyn.hudson Direct connection emonTx V3 3-phase to RaspberryPi - #11 by glyn.hudson). There’s another explanation of the difference between the two by either @glyn.hudson or @TrystanLea somewhere (that currently I can’t find across the 64,000 OEM browser tabs I currently have open…) which I think suggests that for the current emonTx/firmware we should really go with the [SerialTx3e] option.

rdc-Green - it looks like you’ve just kept the [SerialTx3e] title for the interfacer but changed it to match the [SerialDirect] way of doing it…?

I too cannot get EmonCMS to receive any Input from the [SerialTx3e] interfacer over /dev/ttyAMA0, but it is received just fine in the EmonHub log. I’d like to make sure I set this up in the most optimal way - is there any downside to reverting to the [SerialDirect] interfacer instead of sticking with [SerialTx3e]?

My setup is functionally identical to the one described by rdc-Green.

(As a new user I’m only allowed to 'mention two users in a message - hope all the relevant people see this anyway…)

Many thanks!

I’ve cured that for you.

The problem I think is there’s a great reluctance to mark data as “obsolete”, and an equal reluctance to fully and properly document anything added, so it’s really hard to steer people like you to the correct, up-to-date information.

The 3-phase sketch actually contains all three output formats I mentioned above https://community.openenergymonitor.org/t/re-rs485-and-other-sensor-cabling/17676/2 - you choose the one that suits your needs. (I’ve yet to run those tests - I can’t find my jumper wires and had to order some more.)

Thanks Robert!

The EmonCMS code is the one area I haven’t looked at (that seems like a rabbithole best avoided given my available time at present!), so I have no idea why the [SerialTx3e] interfacer does not work as it apparently(?) should in this application. I’ve been through the three phase sketch you wrote Robert and whilst it would probably have taken me a thousand years to write I do understand most of it (I think)…

Just noticed in the emonhub log that it claims to be receiving the [SerialTx3e] data from “Node : 0”, despite the fact that the EEPROM and firmware Node are both set to 11… what’s that all about?

2021-05-04 16:37:56,225 DEBUG SerialTx3e 1363 NEW FRAME : ct1:7.74,ct2:-0.36,ct3:-0.12,ct4:0.00,vrms:250.29,t1:300.00,t2:300.00,t3:300.00,t4:300.00,t5:300.00,t6:300.00,pulses:1
2021-05-04 16:37:56,227 DEBUG SerialTx3e 1363 Timestamp : 1620142676.2238631
2021-05-04 16:37:56,240 DEBUG SerialTx3e 1363 From Node : 0
2021-05-04 16:37:56,242 DEBUG SerialTx3e 1363 Values : [7.74, -0.36, -0.12, 0, 250.29, 300, 300, 300, 300, 300, 300, 1]
2021-05-04 16:37:56,244 DEBUG SerialTx3e 1363 Sent to channel(start)’ : ToEmonCMS
2021-05-04 16:37:56,245 DEBUG SerialTx3e 1363 Sent to channel(end)’ : ToEmonCMS

Also the CT1 output there is (consistently) garbage - all three CTs are currently clipped around the same wire with zero load attached… when I change the sketch to SERIALPRINT output and look at the Arduino IDE serial monitor it gives the correct output for CT1, so why is the EMONESP output going haywire… am I missing something obvious here?

That’s because it doesn’t send the NodeID. So you need an extra line in emonhub.conf to give it a node number - or write a definition for Node 0. Just don’t ask me to explain why.

I want to go and cook my tea, meantime here’s my cryptic crib that might explain a little:

EmonESP

also

NodeOffset: So when the emonhub interfacer was written for that emonESP format serial output with no node id (aka node id is None) we could use the nodeoffset to add a “offset” to that absent node id ie your node is currently 0 offset by 1 = 1. So using nodeoffset is how you define the node id for each emonTx using the (emonesp format) serial output.

Under this section
[[RFM2Pi]]
Type = EmonHubJeeInterfacer

you need to add under runtimesettings

  [[[runtimesettings]]]
       nodeoffset = 17

An offset of 0 (default) + 17 = 17.

Thanks Robert - Bon appetit!

I’ve commented out the whole [[RFM2Pi]] section (in frustration) as I’m only using a direct serial wired connection… did you mean to correct this node offset under the [[SerialTx3e]] section or do I still need the [[RFM2Pi]] section even if I don’t want to use the radio at all?

When I change the node offset in the [[SerialTx3e]] runtimesettings I now get the following log entries (which I’m sure has a bleedingly obvious cause but by now I’ve gone completely cross-eyed):

2021-05-04 18:18:39,871 DEBUG SerialTx3e 1 NEW FRAME : ct1:6.40,ct2:-0.99,ct3:0.24,ct4:0.00,vrms:248.74,t1:300.00,t2:300.00,t3:300.00,t4:300.00,t5:300.00,t6:300.00,pulses:1
2021-05-04 18:18:39,875 WARNING SerialTx3e 1 RX data length: 12 is not valid for datacodes [‘h’, ‘h’, ‘h’, ‘h’, ‘h’, ‘h’, ‘h’, ‘h’, ‘h’, ‘h’, ‘h’, ‘L’]

Is this a complete waste of time? Is there any advantage to trying to use [SerialTx3e] vs [SerialDirect] interfacer for wired serial connection to a locally hosted emoncms?