PlatformIO and EmonTH2 (getting started and issues)

Calibration of EmonTH
I recently bought four EmonTHs with the aim of using them in house heating tests.

I did a calibration run checking their output between 6-40C? (30-80%RH?) against a SENSIRON SHT31 I bought from RS Electronics. Although it has its own errors to think about it, the SHT31 is my new standard against which I calibrate the EMONTHs.

Surprisingly little re-calibration is actually needed and I am pleased that the sensor in the EmonTHs are quite accurate. The only recalibration needed is to scale the humidity result by 0.95 on one of the EmonTH sensors.
For this I will need to adjust the Arduino Sketch that runs the EmonTH.

PlatformIO and EmonTH2
The openenergymonitor website gives a guide to using PlatformIO as a code editor.

However, support for PlatformIO from Emon team might be hard to get.

You may be better off sticking to the Arduino IDE code editor if support is key, although at this point I have battled through the PlatformIO environment using Google for support and it seems to be OK for me.
Here is my experience with PlatformIO and compiling and Uploading an updated sketch to an EmonTH2 with my new scaling factors.

Get PlatformIO
It will download updates, if in doubt updates have been applied restart it

I clone the EmonTH folder onto my harddrive.

$ git clone

PlatformIO (PIO for short) uses a directory tree on the LHS and opens files into Projects. PIO uses workspaces and has a Platformio.ini file to organise folders in the directory according to function.

You can open from PIO using the Import Arduino Project function, however I chose Open and directed to the …emonth2 folder and all files were brought in successfully.

There are some problems that need to be resolved before use.
The workspace file has a reference to emontx3 instead of emonth2. I assume that should be changed so I changed it(?)
PIO wont resolve library dependencies when you hit Compile. That is because the current library dependencies found in PIO.ini file looks like this;

lib_deps_external = 
	DallasTemperature @3.7.7
	JeeLib @c057b5f4c0
	SI7021 @c5ce0922ef

However, the JeeLib library wont be found because @c057b5f4c0 is invalid
Likewise [email protected] has the same problem
Without these libraries and their dependents you cant compile.

To fix this I reached into the EmonTX3 folder and stripped out the libraries there as replacements.

lib_deps_external = 
	DallasTemperature @3.7.7

With these new library references I can compile successfully and all library dependencies are pulled.

Finally I had an error saying that PIO couldnt find the src code directory. This requires a reference in the PIO.ini file to be added;

default_envs = emonth2
src_dir = src  

Changing the src code for calibration results
The lines of code you need to change are 405,406

emonth.temp = (data.celsiusHundredths*0.1);
      emonth.humidity = (data.humidityBasisPoints*0.1);

Here I change the 0.1 to 0.095 in Line 406 to scale my humidity reading following my calibration results.

Compile is successful (forget the best practice warnings and errors) and then go to Upload. You can use Serial Monitor in PIO to monitor the EmonTH output.
(tip: first time I changed the scaling to 0.05 just to make sure I was uploading successfully and having an effect on the output, before finally setting it to 0.95).

I will now finally check to see that the EmonTH does work with the EmonBase I have and post again down below. If it doesnt work I am going to be upset.

1 Like

There was quite a lot of work to decide on the sensor to use so I’m not surprised.

The simple method will be to scale it in EmonCMS as part of the Input processing. Much less effort :slight_smile:

As a matter of interest, what was the host hardware you ran PIO on?

I’d agree there. I downloaded it with an open mind, as it had been recommended as “the best thing since sliced bread”. I found my script for updating my libraries etc from Github wasn’t working - and the reason was, plaftormio had MOVED directories around without so much as a by-your-leave.

It hit the bit bucket pretty fast as soon as I discovered that, and it took me hours to recover the situation.

So I am unable to recommend it nor support anyone who cares to try to use it.

For info, I use an external editor (Notepad++ running under Wine) with the Arduino IDE. It integrates well enough.

Old Apple MacBook Pro from 2011 running Ubuntu 20.04

[email protected]:~$ uname -v
#45~20.04.1-Ubuntu SMP Fri Jan 15 11:35:04 UTC 2021

Couldnt trust myself not to swap around emonTHs with differing emonpi and forget to change the calibration. If I calibrate the emonTH then wherever that unit goes its got the correct calibration.

That is above my paygrade (sadly). I respect your opinion, and I think that the Arduino IDE would actually be enough for this type of work (I also like Notepad++ as a general text editor). Anyway, if I use PIO in future I will keep it in mind.

The new EmonTH sketch seems to be working fine (and with an adjusted humidity level). I will keep an eye on it for future problems (NodeID20).

I’ve used a fair few compilers, linkers and IDEs in my time, in various languages and various OSs, and I’ve never encountered anything like that before - ever (and I started in the late 1970s)

For what it’s worth, there are salt solutions that will give a reference humidity.