Amending TX4 Firmware to add more than 3 temp sensors

Hi All

I would appreciate a bit of help please in adding more than 3 temperature sensors to the EMONTX4 unit. Last week I went ahead and purchased the TX4 unit, as well as a base, a breakout board and 5 temperature sensors.
I have connected everything up and I now have 3 temperature readings for my Heat Pump – logging both at home and also on the EmonCMS site. This is great, and I love the ability to understand what is going on, however I want to add the other 2 sensors.

I note from the literature, that the only way to do this is to amend the firmware. Given this, I have downloaded the Arduino IDE editor plus associated libraries (as per documentation) and have opened up the EmonTxV4.ino file to see where to make the amendments. I can see where the T1, T2 etc values are and also #define Max_Temps – is it just a function of amending Max_Temps to 5 and adding T4, T5 to all the necessary lines?

Apologies, it has been 25 years since I worked on any code, so I am bit rusty.

Many thanks for the help


Until Trystan comes along (he’s changed my original emonTx V3 sketch, and I’m not totally familiar with all his changes), that should be all that’s necessary - plus of course the corresponding change in emonhub.conf in your emonBase.

But if you experience problems with the power readings, it’s likely that the time it takes to fetch the extra temperature readings might be the problem. This was the prime reason for limiting it to 3 sensors for the emonTx V3.

Yes that’s it. Noting Roberts tip to check the power readings.

Thankyou Robert. I haven’t connected any power sensors yet, but I shall make a note of your comments. Thanks

Thankyou Trystan for confirming what I need to do. I will give it a go, hopefully I can reload the original firmware if I get into trouble.

Thanks for your help, I have managed to edit the EmonTxV4.ino file, made all the necessary changes, compiled it and that seemed to go ok. However I am now struggling as to how to upload this back into the EmonTxV4.
I followed the very helpful documents on firmware but under the section “How to compile and upload firmware” it stops short on the upload section. The compile section worked perfectly.

I note there is this line: avrdude -Cavrdude.conf -v -pavr128db48 -carduino -D -P/dev/ttyUSB0 -b115200 -Uflash:w:EmonTxV4_LPL.hex:i which points to uploading the file. If this is the case, how then do I tell that line to point to my altered version of the EmonTxV4 file on my PC?.

Having looked through as many of the community pages as I could search for on this issue, the best I could find was around using a USB to serial UART programmer. Is this the only solution?
I can see in the Admin section there is a serial config tool as well as a way to update the firmware - I assume this appears to be the base unit connecting to github, downloading the firmware and then uploading the firmware over the USB connection to the EmonTX. So it looks like it is possible to upload the file.

Many thanks for your continuing help


Do you have/are you using the Arduino IDE, and which OS?

If you’re using the Arduino IDE under one of the Linuxes, the emonTx V4 plugs into a USB socket directly using an ordinary USB-C Smartphone cable (the right way up - flip it over if it doesn’t show up in ‘Tools →Port’ - mine is “/dev/ttyUSB0”) and upload then with Sketch → Upload (which automatically compiles as well as uploads).

If you have Windows, (I have WIn10 running inside a Virtualbox VM) – mine shows up as COM5, but I haven’t loaded the extra libraries in the VM so I can’t prove it.

The installation instructions have yet to be written for all the OSes.

Hi Robert,
thanks for the reply.

Yes, I am using Arduino IDE 2.0.3 with Windows 10. So in theory I would connect the laptop to the emon Tx using the USB cable that is currently connect to the base and essentially do Sketch - Upload. I will look into that.

Many thanks


Are you uploading by serial data to an emonBase?

If so, yes. Just plug your PC into the TX4 via the USB (no need for any other connections).

In the bottom window you should see some output.

If not, turn the USB C connection on the TX4 over (USB C can go in the wrong way for data).

Thanks Brian for this.

After installing the drivers for UART device on my PC, I could indeed see the connection via USB in Arduino IDE.
Sketch - upload worked nicely and file uploaded without a problem - only issue now is that I am seeing the value of 300 against all 5 temp nodes. I have rebooted the Emon as indicated by other comments when this number appears, but to no avail.

Tonight I think I will try and just upload the original program without any modifications to see if there is something wrong with my PC - missing files or something.

Kind regards


1 Like

300 is an error condition. Are these shop sensors or AliExpress sensors?

Specifically - if you read the documentation - it means the sensor has never been detected.

Error values:
300.00 : Sensor has never been detected since power-up/reset.
302.00 : Sensor returned an out-of-range value.
304.00 : Faulty sensor, sensor broken or disconnected.
85.00 : Although within the valid range, if it is not close to the expected value, this could
represent an error, and might indicate that the sensor has been powered but not
commanded to measure (‘convert’) the temperature. It might be a symptom of an
intermittent power supply to the sensor.
1 Like

Hi Brian,

sensors are all shop bought. I know they work fine as they work well with the original TX4 firmware and work again when I re-download the firmware from the Admin/Update page.



So I downloaded the original firmware and performed Sketch - Upload, with this to see if it is my setup that is the problem and I again the get the 300 value for Temperature. When I tried Verify/Compile I get the following message:

c:\Users\latho\OneDrive\Documents\Arduino\libraries\EmonLibCMavrdb\emonLibCM.cpp: In function 'void EmonLibCM_TemperatureEnable(bool)':

c:\Users\latho\OneDrive\Documents\Arduino\libraries\EmonLibCMavrdb\emonLibCM.cpp:1312:28: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
     if (temperatureEnabled = _enable)

not sure if this is an issue or just a warning message.

Any help is appreciated as not sure why the original firmware when I upload it does not work.

Many thanks


Just a warning.

Odd, so they don’t work with the original firmware now?

You shouldn’t be changing anything in emonLibCM, the only changes needed to add sensors are in your sketch.

“300 °C” is pre-loaded when emonLibCM starts up. If no temperatures are read, that is the value reported. So my initial assumptions would be that no sensors are connected - or they are wrongly connected, or the library hasn’t been told to enable monitoring the temperatures, or power to the sensors isn’t there. I can’t say more than that, because I’ve not looked at the V4 sketch - and there might well be a mistake in that (either yours or Trystan’s).

is C shorthand. First, the value of _enable is assigned to temperatureEnabled, then that in turn is tested for logical truth - zero being false and anything else being true. A common misconception (or misreading, or presumption of an error by those who don’t know the language) is the test is equality of temperatureEnabled and _enable which it isn’t - this would be if (temperatureEnabled == _enable) and that’s not what is intended.

Thanks Robert for this.

The message appeared in the Output section when I complied EmonTxV4.ino in Arduino - definitely haven’t touched the library files. This file is from emontx4 firmware directory on GitHub.

The three temp sensors are plugged in, and work fine when running the firmware file I get when using the update firmware option in the Admin section on emoncms, just not when compiled and upload the underlying ino file in Arduino.

Thanks for your comments


@TrystanLea any thoughts?