mcp30XX chip for esp8266 ( wemos D1 adaptor board for emontx shield)

For those who might be interested, here is a custom emonlib using mcp3008 (or other mcp30XX chips 10-16bit)
It works well though if only doing current, you have to sample ~30000 times to get accurate results with a wemos D1. If using voltage and current then it works very well as is.
I did mine as an adaptor board for emontx shield and wemos D1. I also used the esp 8266 built in analog pin to calculate the voltage. So it gives me 8 CT ports.
You can use a wemos D1 and have 8 CT ports but it should also be stackable on top of an emonTx shield and an Arduino base to give you 12 ports (though i have not updated the firmware to support it. (I will do so in a few days) (13.3 KB)

you will also need the mcp3008 library . (3.2 KB)

example board image


With 8 CT stackable with emontx shield, and a wemos D1 or Arduino - the four on the same side work in conjunction with enmontx and the Wemos D1. If no emontx, then it can be use as 8 CTs and current only. If stacked on an arduino and emontx shield it will give you 12 CTs.

At some point I might include multiple stacking of the adaptor board. It should not be too hard to do. Each stack will add 8 more CTs, possibly 40 more CTs on a Wemos or 72 more on an Arduino or whatever the functional support might be.

There is sample software included in the package.
I will fritz out the base design in a couple days or sometime next week if someone wants to build thier own adaptor board for the Wemos D1 or other esp8266. (suitable candidates include ESPtoy, Wemos, NodeMCU as they have built in 5V support)

Good luck. Have fun!


i forgot to mention as i have not quite figured out the correct method to import setting in the emomlibmcp… from the main sketch when it wants to call from another secondary library you need to edit emonlib.ccp with your pin # - maybe someone could give an example of how to and I will update the emonlibmcp library

1 Like

Nice work @stephen thanks for sharing, and great to see the emontx shield used in this way!

glad you like it. not one for reinventing the wheel, and I wanted to keep it compatible with the emontx . so I can stack with my pre-existing shields and software very easily.

Hope this is an understandable frittz layout.

There are two header blocks to disable the rear CTs if using it with Wemos D1 and emonTx shield - probably could’ve gotten away with just one

okay i looked at the code it was very easy to get analog and spi analog CT to work together ( took me less then 5 minutes to get it working) here is the updated firmware if you wish to stack on top of arduino base
basically to use a digital analog pin just add a D to the end
onboard analog pin
if (CT6) {
emontx.power6 = ct6.realPower;

to use a spi analog pin add D
to the end
if (CT7) {
emontx.power7 = ct7.realPower;

the same applies to only current

double Irms = emon1.calcIrms(1480); // arduino analog
double Irms = emon1.calcIrmsD(29600); //mcp3008 analog (13.4 KB)

okay good luck – have fun

if someone wishes to improve on go right ahead, post your improvement back here if you like. as i am not certain when I will add multiple adaptor board capability it should be fairly easy, all one need is to call with a different CS_PIN . most likely modify mcp3008 code with a few if statement -ie – if >7 use CS_PIN 2 - if >14 use CS_PIN 3

was not planning to do this but last night i dreamt the the entire method of doing a scalable mcp3008. so when i woke up i tested the function and it works fine.( no use wasting all that dream thought)

so if you want a scalable mcp3008
i only scaled it to 4 cs pins more can be easily added if you like

i do not have a multiple mcp3008 to test with but if someone does they can try it out and let me know. (3.8 KB)

@stephen you might want to have a look at what @overeasy is doing with his IotaWatt:

thank you mwalker

I will look at it in a bit if I can not get my current version to work properly or reasonably . currently I made a couple changes today. I notices my current was off… I never notice really when i was testing with lower current sources. now that i upped the current considerably it noticeable. but luckily it was a fixed variable. I am guessing the timing between the built in analog pin that I use to calculate the volts it throwing off the current calculation via the SPI analog . ( though it seams fairly reasonable now as it only 5 - 10 watt difference between it and my tester but we will see if it can maintain that accuracy as I add in more CTs which I do not have currently)

but anyways here the latest incantation if anyone wants to try. it use the scalable MCP3008 library. so now I believe it should be fully stackable to a max of 32 CTs if using a esp8266 and 36 CTs if using an Arduino. (13.8 KB)

okay I tested it functionality on a arduino the current error is most likely due to timing difference between arduino and esp8266 . my original test base was on arduino as it a bit more of stable base then esp to work with . hence why I never noticed the current being off- as I needed to adjust the timing difference by ~0.95 where as the timing difference on the ESP was ~1.515. but once adjusted it seams to remain accurate . plus you also need to calibrate your voltage … for me my voltage is 124 in my province so 144 works on arduino ( instead of the 130 emonlib recommends) on the esp I adjust that number to 149 for my needs
okay good luck have fun

well that’s a pleasant surprise :smiley:

the advantage of the adjust feature I just add in my previous software package . it works nicely to recalibrate for various anomalies. ie: resistors and even crack faulty CTs.
I have one emontx sheild that has faulty or wrong size resistor on it from factory that I never got around to changing and it always registered 10% higher then all the other CT ports - was easily corrected using the adjust feature just lower it 10% less then what ever the other CTs were set at. and it maintained the same accuracy as the the other CTs.
so I thought i try it on a cracked CT that was registering 20% lower then a normal functioning CT - adjust it up 20% - and it maintained the same accuracy – :slight_smile:
I think I will add the adjust feature to my normal emonlib since it so handy

here a sample: the first one is the cracked CT the second is the normal CT the third is the bad resistor on CT port- the last is the volts -my tester bounces between 884 and 891 on my resistant load also I am testing on a light extension cord so I get variable voltage drops. to see it it maintains the same accuracy under different loading conditions - which it does :slight_smile:
893 882 892 118
882 884 890 119
887 883 882 119
883 884 880 118
886 882 886 118
883 885 891 118
888 886 885 119
885 888 883 118
897 884 885 118
893 887 894 118

I would be very interested to see what the phase error of your cracked c.t. is like. When I tested one (admittedly an old ‘grey lead’ one) with only a 0.004" air gap, it showed an amplitude change of 7% (drop) and, from memory, a phase error change of around 15°.

I would do that for you. but I would need a scope as i do not think one can determine it with out one. unless you know how to then sure no problem

If you can use a p.c. sound card at 44.1kHz to sample the waveforms (see my test reports for circuit details), then you can do it with a software oscilloscope or (probably more accurately) record the input and output waveforms for 1 cycle, put the numbers into a spreadsheet and use a Fourier Transform.

Phase error won’t matter much if your loads have a power factor close to unity, but as the power factor gets smaller, the measurement error becomes much more significant. I think it would be unwise to rely on a damaged c.t. for meaningful measurements, because it would only take a small change to the air gap to make a large change in the output, both in amplitude and phase.

okay I will give it try not guaranteeing I will get it to work, but this seam interesting LXARDOSCOPE using an arduino instead of a sound card I see if I get that to work - as to the cracked CT. I doubt it air space will move I secured it in place… but one can always use a cracked CT as a current trigger sensor…

With only 2350 samples per second per channel, you might find the scope is introducing quite a bit of phase shift itself. You could wrap your CT around a feed to a purely resistive load and then see if your monitor reports a PF of 1.

okay got the LXARDOSCOPE - had 0.95 did not want to work so I downloaded the oldest version and then updated the sketch . and it works fine with the newest version LXARDOSCOPE.
the green line is the build in analog on doing the voltage the esp8266 and the read line is mcp3008 and the CTs
the good CT

the cracked CT - seams to peak slightly later from the image

dBC not sure what you mean here
“You could wrap your CT around a feed to a purely resistive load and then see if your monitor reports a PF of 1.”

okay figure out how to overlay the two waves-
good ct on top of voltage sinwave

crack ct on top voltage sin wave

slightly out of sync with the voltage sine wave

lxardoscope ( to make it easier for others at some point)
download lxardoscope download |
and use this sketch for simple scope (1.4 KB)

Yep, that looks to be about 24° of phase error. So your purely resistive load will appear to have a power factor of 0.91.