Wednesday, November 25, 2015

Dedicated Energy monitoring with the ADE7763

After building the NodeMCU based energy monitor with an external 16 bit delta-sigma ADC i.e. the ADS1115 I started looking into solutions which were more accurate and cheaper.

I came across some work by Skye Sweeney with the ADE7763. He had built a prototype on breadboard and wanted to monitor lots of channels so the cost of sensors became prohibitive and he set the project on hold. I am attempting to measure only a single phase and disaggregate the data later by post processing, so a single ADE7763 should serve my purpose.

I set about building a breakout board for the sensor using the reference design in the datasheets and ordered it from Oshpark. This is where I made an error in my rush. I did not check the footprint the element14 library provided against the real chip. So I ended up with a board with TSSOP footprint for a SSOP chip. Should have printed the PCB 1:1 and checked with a real chip. At least the error was found while prototyping and not in production. I bent the package pins a tiny bit to squeeze it in and proceeded to assemble the breakout.

I could not quite get the SPI bus to work on the ESP8266 NodeMCU, it kept resetting the Watch dog timer. With the ESP it is often a power issue. So for a quick test I hooked up the breakout to a Teensy 3.1 and loaded Skye's code without the multi-sensor bus stuff. It worked on the first go and started dumping RMS voltage and current registers. The only thing to be careful about is the rather limited 1v peak-to-peak input range. Otherwise this chip is great with dual 16bit d/s ADC's and all the code for RMS and registers for offset removal. At about 1/2 to 1/3 the price of the ADS1115. I have uploaded some standalone  breakout testing code to github - Arduino ADE7763.

For accurate measurements this sensor can be connected to AC line using Shunt resistors for current measurement instead of a CT sensor and a direct volatge divider ladder to measure the voltage waveform instead of an isolation transformer. This makes the chip MCU unfriendly and subject to mains voltages. The SPI bus should be isolated with optocouplers when using this mode.


Meanwhile I have tested the sensor using my basic load bulb and CT clamp and voltage and current waveforms are picked up just great. At some point I will build up the courage to create a high voltage / phase accurate measurement rig.

Tuesday, November 3, 2015

The SeeedStudio ESP8266 Contest and resulting product on Tindie

A few weeks back I participated in the SeeedStudio ESP8266 project design contest with my NodeMCU based Energy Monitor. As in all popularity contests I had to ask my friends to help me out and vote for me as often as possible. I had the most views, but not the most votes. Still I ended up in the second place which I am quite happy with.
Fully assembled NodeMCU Energy Monitor - Sensors plug in at the bottom
With such encouragement I decided to get a PCB fabricated for my Energy Monitor project and put it up for sale on Tindie. This is my first electronics project for sale and apart from some local interest, I have made an export sale to the UK. Deciding how to put the project together for sale is quite new to me. I have a certain skill-set but other electronics enthusiasts may not share them. Should I just offer blank PCB's, which other's might as well get from OSHPark or DirtyPCB ? Should I offer a through-hole kit along with the PCB and take the interested party through the soldering order ? Should I put everything together as SMD in my oven and offer the kaboodle including NodeMCU and the rather expensive ADS1115 ? What about the current and voltage sensors ?
NodeMCU Energy Monitor "mostly" Through-hole Kit

There are also component and PCB sourcing issues as outlined in a previous post. Tindie offers some flexibility in this regard letting me set-up various tiers and options. My single product listing becomes effectively a stratified listing catering for buyers with multiple electronics proficiency levels. I might start offering the 100A clamp of current sensor and 12V transformers from YHDC as part of my kit, to make gathering of all the components easier. With bulk manufacture in SMD, cheap mass produced NodeMCU modules and knock-off ADS1115's I might be able to get the total cost down to USD20 unshipped. Which will put the design at par with these non-web connected versions of the same. The design will also be far cheaper than the custom web-connected offerings from Efergy and Wattcost, mainly because these consumer grade products also provide a data hosting service complete with apps and websites. The NodeMCU Energy Monitor leaves the user in charge of their own data and requires certain knowledge of IoT platforms to take full advantage of it. The number of players (AWS, Thingspeak, Bluemix etc.) in the IoT data hosting arena is increasing daily and I am sure people automating and sensorising their homes will appreciate the choice, rather than be locked in with the server hosted by the hardware vendor.

The remaining hurdle is of course shipping, it cost me about USD14 to ship 2 units to UK from Australia as small parcels. Where as China post shipping costs are minimal. Logistics - another hurdle holding back small scale production in Australia. The only long term sensible thing to do will be to manufacture in China and exploit the logistics there. All said and done I am pretty happy with my $50 sale, at least it has paid for the electrician who installed the energy monitor.
Fully installed NodeMCU Energy Monitor - Black YHDC transformer, current sensor inside the enclosure

Monday, November 2, 2015

Making MBed and Arduino compatible Xadow Modules (in Reflow Oven)

I have designed a long chain of Xadow modules by now, including right angled side chains. These include:
  1. Xadow SD (CD4050) - Which allows using upto 32GB Micro SD Card and good read/write speeds due to the driver IC.
  2. Xadow Serial (SC16IS750) - Which adds 1 UART and 8 GPIO ports, with jumpers to allow upto 4 modules in chain.
  3. Xadow MultiSerial (SC16IS752) - Which adds 2 UART's (theres is not enough space for the GPIO's)
  4. Xadow IO (PCA0539) - Which adds upto 16 GPIO ports using I2C
I have tried various suppliers to gather all the components, various PCB manufacturers as well as solder stencils from OSHStencils. Here is the breakdown of my experience so far in prototyping some very small single boards using SMD only components.
Chain of Xadow modules - GPS, Oled, 9-DOF IMU, Barometer, Dual-I2C Uart (Bluetooth), Xadow-M0, Xadow-SD (Left to Right)

PCB Manufacture:

DirtyPCB - They use SeeedStudio for manufacture and fulfilment, but get bulk discounts and I love the Gerber preview option, no extra charge black PCB's and option to get extra PCB's in a batch. I have got gold finished PCB's from them as well these look rather good.

SeeedStudio - My first test PCB's were made here.They also provide an assembly service and a library of commonly used parts. In most cases I have managed to get 80% of the PCB assembled in China with 20% hand soldered at home, mainly crystals and main IC's.

OSHPark - This is the made in the USA solution to Hobbyist PCB's. They produce PCB's in a signature purple colour, which I guess is a soldermask colour no serious industrial PCB maker wants. The ENIG finish PCB's look rather good. The preview function is also handy. However the DRU for checking PCB's is a bit strict in terms of clearance at the board edges, vias are not automatically tented and signals require greater separation leading to a low density PCB overall.

I am yet to try PCBPool and local Australian and New Zealand options, but they are beyond the budget of hobbyists. Once I start manufacturing my designs I shall surely give them a go. Local hackerspace recommended #hackvana and I had a great chat with them as well.

Component Sourcing:

AliExpress - Components are a bit hit and miss, had the wrong ones sent at one point. All the ones tested work.

EBay - Probably same sellers as AliExpress. Similar performance, no bad shipments so far.

Element14 - Next day delivery is amazing for quick prototyping. The part search system has improved a lot and they even have an Eagle library for most of the common parts.

Samples from TI, Maxim and ON Semi - Nothing is as good as free stuff delivered express. All parts are detailed with CAD models (albeit in .bxl).

Stencil:

OSHStencil - The holes are a bit too big, probably because I did not shrink the solder mask enough. Great otherwise.
Homecut - Cut on a Trotec laser Speedy 100 from Mylar and Kapton. The laser has a bi
t too much power, so pads need to be shrunk even more.

Overall it has been a great learning experience and I have probably spent more on research than I would have spent buying a hotshoe IMU like the solmeta off the shelf. However in the end the product does exactly what I would like it to do. Next step - find a suitable 3D printer on 3D Hubs and get an enclosure built, also complete the MBed code to make it all work.

Wednesday, September 9, 2015

Experimenting with Energy Monitors

After a spate of high electricity bills and trying to save energy by turning things off randomly I decided to do it the proper and scientific way by experimenting and collecting plenty of data.

In the days of bitcoin mining high energy bills were the norm. Now they miners have all moved to better homes and I am left with myriads of run of the mill appliances. Identifying the energy hungry beasts is not trivial.
Initial attempt at current measurement with DSO-Nano
The Open Energy monitor site has a plethora of ideas and some quite good Arduino and Raspberry Pi based designs for energy monitoring. SeeedStudio also has a couple of designs intended for energy monitoring use with an option to use an LCD or Oled screen, which I quite like. The downside of both these options however is the wireless component. The EmonTx option uses the RFM12/69 as the wireless transciever and the SeeedStudio option uses the nRF24L01+, both options require custom and expensive receiver hardware attached to an always on data-logging system.

Seeedstudio Energy monitor with nRF24
So after a bit of research I decided to roll my own on a breadboard using the ESP8266-12E based NodeMCU module. I started with a basic version is for apparent power only. To keep component count low and the circuit as simple as possible I used an ADS1115 breakout in differential mode eliminating the need for bias resistors. The hard part is getting a licensed electrician to wire up the clamp on current sensor to the main wire coming into the premises. Since we have only 1 channel we are going to monitor overall power rather than power per circuit.
Apparent power energy monitor with ESP8266
After the fact I made a Fritzing diagram showing how-to wire up the prototype on a breadboard. Powering the NodeMCU near the switchboard might be an issue as well, so I installed a DIN rail power socket, this will come in handy for real power measurement later on.
Fritzing diagram of apparent power energy monitor
One of the downsides of the ESP8266 approach however is the high current consumption (300mA or so) of the module and the fact that small block transformers used for voltage sensing will experience power factor shift under this load. This makes powering the system and measuring real power using the same transformer difficult, it can however be done with proper calibration.
NodeMCU Energy Monitor including power supply and voltage sensing
 The next bit is getting proper code to run on the NodeMCU. I chose to use the module in Arduino mode with the excellent work done here. For code inspiration I used Emonlib from the OpenEnergyMonitor project. I made some changes to read the current via the ADS1115 instead of directly via the inbuilt ADC, increased the integration period and patched in a square-root approximation method. The resulting code can be seen below.

The data from the monitor gets uploaded every 20seconds or so to Thingspeak. This makes it easy to plot graphs and analyse the data for appliance specific spikes, at the expense of losing control over it and some privacy. If you want to keep it all in house it is better to use something like EmonCMS.
Multi-day energy use graph(uncalibrated)