emonTx connecting to arduino IDE using programmer

That’s a matter of copying the section of comment in the source file into emonhub.conf

I too get -ve values on one of my feeds using the TxV3CM firmware, but using the PLL Firmware I get normal values for the same feeds.

I also get totally different readings between the two firmware versions (which I fail to understand).

(Actually I get similar reading on one phase, but not the other two).

What is PLL firmware @G0LGS ?

I’ve now got everything up and running so will test on Tuesday

That is suitable for a single-phase or a N.America split phase system only. The 3-phase PLL sketch is suitable for a 3-phase system only. If you use the wrong sketch on the wrong system, you are bound to get wrong results.

Thanks for Clarification - I’m so confused by the different versions.

You could ask.

Basically, there are two sketches in use. The one factory-installed on the emonTx is the Continuous Monitoring sketch - EmonTxV3CM, which is designed for the UK single phase domestic supply, but it is suitable also for the N.American single-phase split phase system.

If you have a 3 phase system, either 4-wire or the less common 3-wire, then you must use the 3-phase PLL sketch Update to 3-Phase PLL sketch - #21 by Robert.Wall
That download is the complete sketch and documentation. You should not attempt to use the pre-compiled version that has been put on Github as it is almost certain that you will need to adjust the options that are only available by editing the source code.

If you have a 3-phase supply (see the ‘Learn’ pages for how to identify whether you have), then using the single-phase sketch will not only give you negative powers on phases 2 & 3 (phase 1 being the one that the a.c. adapter is on), but those powers will be roughly half the correct value. If you don’t have the a.c. adapter, it will still be wrong, but less wrong, because it will indicate apparent power using a guessed voltage - the value for phase 1 that was previously correct (the real power) will now be wrong because it’s apparent power using the guessed voltage instead of a measured voltage, but probably by not too much (maybe within 20% if you’re lucky) and the ‘powers’ for phases 2 & 3 will improve but still be wrong by roughly the same amount.

Thank you @Robert.Wall

one more question (although i doubt it will be the last). Can I set up the feeds in the same way I would with a single phase, i.e. use and use_kWh, but for each power reading (1-3)

That depends. If you have a 4-wire system, then each power represents the power seen by that c.t; whereas if you have a 3-wire system, the two individual “powers” have no meaning, only the sum - the total power - is meaningful. (In fact, when 3-wire is enabled, the total power is sent as “power1”, and “power2” is always zero.)
Notwithstanding that, once you have a power into emonCMS on the inputs page, it can be handled exactly the same wherever it comes from.

@Robert.Wall, do you know if its possible to amalgamate the power figures so that i can have just one feed being posted via the api?

Very easily.

The line/statement you need will look a bit like
Serial.print((int)(realPower1+realPower2+realPower3+0.5));
if you’re using the serial port & programmer. (+realPower4 if you wish)

Then don’t send, or don’t use, the individual powers. If you choose not to send them, then you might need to change emonHub and exclude those from that Node. (If the output disappears when you remove the unwanted data, you need to change emonhub.conf.)

hmmm. Is this going into the ‘emonTx_3Phase_PLL’ tab? I’m not sure how to include that. Is it in this section:

In terms of sending the individual powers, i’ll try to just select the node_id linked to the combined power output and leave the rest.

Yes - into the main file, that’s the one that has the same name as the directory it’s in.

I think I’ve lost the plot - I don’t understand that. The Node ID refers to the identity of the emonTx and “ALL” the data you’re sending from it.

I use the api to pull the data through in Node-Red. So i’ll just use the node id (https://emoncms.org/feed/aget.json?id=1 - in this case ‘1’) for the feed that has all 3 powers combined.

I think i meant to say ‘Feed ID’, not ‘Node ID’

That makes sense now.
You can of course add the inputs in the input processing in emonCMS and save to a feed, but doing it in the sketch guarantees that all three powers come from the same sampling interval. That might not be the case when summing in emonCMS.

I’ve not had a need to set up NodeRed, so I’ve no idea what it needs.

Hello again @Robert.Wall Would you mind just clarifying how I need to edit the code. Is it from:

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 "));

To

Serial.print((int)(realPower1+realPower2+realPower3+0.5) );   // These for compatibility, but whatever you need if emonHub is configured to suit. 
Serial.print(F(" 0.0 "));

Can I just leave the rest of the section as it is?

Thanks again

I’ve lost track of what you have.

You need to put it in the correct section for the output format and the mains system have you selected.
(The sketch works for pretty much all combinations - set up by the choices you made at the top of the sketch, which then select which bits to use.)

If you’ve asked for SERIALOUT (space-separated values) then it needs to go in the section selected by

but if you’ve asked for EMONESP (Key:value pairs) then it needs to go in the section selected by

#if defined EMONESP && !defined SERIALOUT

As you’re not too far from me, I presume you have a 3-phase, 4-wire system. So inside that selection, you need to put (or edit) that line NOT in the 3-wires section.
(What you have there is a straightforward if – then – else, the “if” being if you’ve got a 3-wire system, which I think you won’t have, therefore you want the ‘else’ case or put it in past the end, which means ‘both’.)
So you can put it in the #else clause, or you can put it after the #endif
You can leave the variables you don’t need (especially if you’re likely to need the individual values in the future, or if you’ll never need those on their own, you can safely delete them.

Now i’m really confused!

I haven’t made any changes to the PLL sketch that you suggested I use. It seems to be working ok whereby i’m getting values for the three phases that look about right. I have gone through the options and them seem ok for my system.

I haven’t selected SERIALOUT or EMONESP. I’m using RFM69CW. Does this mean I can’t request the values to be added together?

Now it’s my turn to be confused. The thread is titled " emonTx connecting to arduino IDE using programmer" and that implies a serial wired connection via the programmer. Are you saying that isn’t what you’re doing, and haven’t been doing throughout?

Either way, if you want, you can change ALL the outputs to send only the sum, or the sum as well as the individual numbers. The reason behind doing the sum in the emonTx and sending it as one value, and not doing the sum in emonCMS, is (and I think I mentioned this earlier), you can have the situation where the Pi takes its time doing the maths in between doing other stuff, and ends up adding readings from two sets of results - 10 s apart. If you can live with that, there’s nothing you need to do. The ‘proper’ way is to add the numbers from a set of readings all done over the same period, which is what adding them in the emonTx does.

Sorry Robert, you are right i have connected the emonTx to arduino to get the right Sketch on there. I’m now using the emonTx with an emonbase to record data. This is over RF.

I’m now trying to figure out how to combine the three phases into a single output, but was lazy and didn’t start a new thread for this discussion. Sorry about that.

I can’t figure out how to change the outputs to send only the sum. I think i’ll just sum them either in emoncms or in node-red

Actually, it’s probably easier for me that you kept the same thread, but I wish you’d said “Now I want to do it with the RFM” (or something like that).

It’s still the same principle, but slightly more involved. I’m assuming you want both the individual values and the sum of the powers.

At the top, at line 49 for emonhub.conf, you’re going to want this:

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

Line 306, add the extra power:

typedef struct { int power1, power2, power3, power4, sumPower, Vrms, temp[MAXONEWIRE] = {UNUSED_TEMPERATURE,UNUSED_TEMPERATURE,
                  UNUSED_TEMPERATURE,UNUSED_TEMPERATURE,UNUSED_TEMPERATURE,UNUSED_TEMPERATURE};
                  unsigned long pulseCount; } PayloadTx; 

At lines 842-3, where you have

  emontx.power4=(int)(realPower4+0.5);
  emontx.Vrms=(int)(Vrms*100+0.5);

you need to insert (before, after or in between, it doesn’t matter)

  emontx.sumPower=(int)(realPower1+realPower2+realPower3+realPower4+0.5);

(OK, you can leave off realPower4 if you don’t want it in the sum.)

Don’t be too alarmed if the individual powers don’t add to the sum - it’s rounding. The individual powers are rounded on their own, but summed before rounding and the sum is separately rounded.