Saturday, March 18, 2017

Piezo Activated Drumlights - The PCB

I feel like once you have learnt one software tool in a particular domain to an intermediate level, you can pick up another in the same domain without much fuss. Only if you are too new or too entrenched with a tool do you feel the sunk-cost fallacy and have a higher barrier to switching to something new when circumstances change.

Nightly build I am currently using
I started my adventures in ECAD using Eagle and built up quite a bit of familiarity with it, I would like to say to an intermediate to advanced level. I also built up some assets i.e. libraries and projects. To unlock more features I spent a few hundred dollars on the maker edition. However as with all software, there were niggling bugs and gripes. One of them was lack of proper 3D support, another was lack of proper slots when exporting gerbers, well slots/mills that hackvana would accept. On the hackvana IRC channel KiCAD was mentioned often and I was encouraged to switch to it. The final straw was the acquisition of Eagle by Autodesk and subsequent switch to subscription based pricing.

Eeschema of Arduino Nano drumlights
So finally after much dithering, I decided to switch to KiCAD as my main ECAD tool in the beginning of February 2017. It has been a fun couple of month translating my Eagle knowledge to KiCAD and dealing with the vagaries of a rapidly evolving tool. So far I am loving it. The first PCB I designed using KiCAD was an Arduino Nano Shield using the template provided to work with my Drumlights project. I took the PCB design as an opportunity to add a battery charger and piezo charge amplifier using a TLV2771 opamp.

KiCost in action as a BOM tool
One of the Eagle features I miss is the forward-back annotation between the PCB and the schematic. In KiCAD the association between a schematic symbol and associated footprint and nets is done using a third tool. This way there is no need for duplicate footprints per device for commonly used pad patterns e.g. SOT-23 or TSSOP-16. All devices using this footprint can share a common PCB element and only differ in schematic element. However this also means that changes in the PCB and are not automatically propagated back to the schematic. The backward link will be coming soon according to a recent roadmap. So I am living nightly-to-nightly in anticipation.

PCBNew view of Arduino Nano Drumlights
The other feature I like about KiCAD is the seamless 3D support, especially in the recent builds.There is dual support for usual VRML for pretty rendering and associated STEP files for export to other CAD files particularly FreeCAD. I downloaded step files for parts not already in the library from Molex, JST of GrabCAD and populated them with some scaling and rotation onto the PCB. You can see the resulting internal KiCAD render below. Next came sending the boards to Fab, a lot of hackerfriendly fabs directly support Eagle .brd files, now there is increasing support for KiCAD as well.

KiCAD Ray trace render of Drumlights PCB
Oshpark can directly process KiCAD - kicad_pcb files to associated gerbers and board orders. This reduces the number of clicks to ordering a prototype and eliminates potential errors and filenaming issues when creating Gerbers, since KiCAD does not really have detailed DRC and CAM job settings like Eagle.
.kicad_pcb file directly imported in Oshpark
One of the valuable lessons I learnt which I have had issues with Eagle in the past as well (obviously I trusted community review of KiCAD libraries too much) was to always double check library footprints against the datasheet. The N-channel Mosfet schematic symbol was meant for a through hole part and when paired with a SOT-23 footprint things were not in the right place. So when testing I ended up with turned on mosfets being fed with 3.3V from the microcontroller from drain-to-source essentially shorting the output. Luckily no magic smoke escaped before I spotted it and pulled the power. You can see the picture here of my hack to salvage the erroneous PCB's using the SOT-23 at 45degrees. I have tested this board with LED strips and it works as expected.

Diagonal mosfets to correct for footprint mix-up
PCBs.io is another cheap option for getting good quality prototype PCB's if you are prepared to wait. However they do not support direct KiCAD upload. If you follow the Oshpark's Gerber generation guide to create gerbers and drill files they should work in PCBs.io as well. This is what I did when ordering my test boards, after a couple of revisions via Oshpark. Overall my experience with KiCAD has been very positive. The community is fun and responsive. There are some great ancillary tools like StepUp mentioned above and KiCost which I used to instantly generate BOM for my board and order all parts from Mouser in minutes.
KiCAD Gerbers rendered in PCBs.io

If you are interested in my KiCAD experience and general principle of piezo activated drumlights you can keep tabs of my hardware and software via github.

Saturday, February 25, 2017

Piezo activated Drumlights - The Prototype

One of my colleagues is member of the Adelaide Samba drumming club - SaSamba. I guess he was a bit jealous of the feathered samba dancers getting all the attention during a gig. So he brought up the idea of a sound/drumming activated light system for the band.

We aimed to get the set-up ready for the Adelaide Fringe parade. The parade takes place at night with plenty of opportunity to show off different sorts of lights.
Prototypes in assembly
For the first prototype I used an electret microphone with a pre-amplifier. With the right threshold tap and claps would activate the LED strips I had hooked up to it. It was only 5 RGB Led's on the test strip, but I was pushing my luck driving them directly from an Arduino Nano GPIO. An n-channel Mosfet is needed for safely sinking the current required for meter long strips.
The other trouble with this approach was the cross-talk between drums. Without fancy FIR filters identifying particular drums there was no reliable way of lighting only the drum being hit. In a band surrounded by screaming crowds an omni-directional electret microphone is definitely not the way to go.

After a conversation with Pix at the Adelaide Hackerspace I decided to switch to a contact-mic based approach, using a piezo as a knock sensor. Piezos can produce very large voltages in open circuit conditions, so I loaded this one with a 1MOhm resistor tacked directly onto the disk. Soldering on piezos is tricky, have to use flux, a hot iron and be quick. The disk acts as a heat sink and cools down pretty fast.

The piezo outputs only a few millivolts with this load (16-20 out of the 1024 max on the Arduino ADC range). This could be improved with pre-amp (opamp configured as a charge amplifier), however it is sufficient for thresholding and briefly flashing the LED's on drum hits.
Heatshrink as enclosures
My drummer colleague tested this with the whole band and it shows pretty good isolation as well. We went on to make 10 of these on protoboard and incorporated an overkill DPAK Mosfet (30V, 58A). These were covered in heatshrink and used with a lipo at the fringe parade in front of around 70,000 people. I wonder how many appreciated the fudging that went into making them.


Wednesday, December 7, 2016

Aliexpress DIN Rail Energy Meter teardown

The best way to learn is often by looking at solutions others have come up with. "Monkey see - monkey do" is pretty much part of the engineering process. While at University we wrote a top-scoring piece on how Apple scooped Creative in making a portable digital hard drive backed music player with great design and even greater marketing. When doing a tear down for inspiration and copying ideas always be wary of patents.

I am planning to move my ATM90E26 + Wireless Stack Energy monitor into a more industrial DIN rail format. To get an idea about how things are packaged inside a DIN rail energy monitor I ordered a no-patents cheap energy monitor with pulse output from AliExpress. The brand is Eastron, they also make quite affordable 3-phase versions which I am going to look at next.
DIN rail enclosure including wiring diagram
Once the meter arrived I did not even plug it in (in Australia an electrician will be required to properly install it due to the cutting of the live line to place a shunt and other modifications). I put a screw driver through the QC sticker, popped open the clipped on enclosure and proceeded to have a peek inside. What I found was a house of PCB's stacked around a transformer to make best use of the place inside the enclosure. The following labelled photos show the various parts.
Profile view with stacking

The stacking places the main processor board with AFE + MCU and LCD display on top, the transformer and associated carrier and high voltage safety stuff (Varistor and PPTC) at the base. The base PCB also carries the Live/Neutral connectors and a bulky current shunt. One vertical PCB is the power supply, voltage and current waveform sampler and the other is an isolated pulse and modbus output board (Modbus chip is unpopulated in my pulse only version).
Bottom view with safety components and current shunt
The voltage sampler uses a resistor ladder of 4x270K resistors in series with a relatively small voltage sampling resistor. The PCB is not heavy on expensive board to board connectors, which allows a modular system and swapping of boards, instead it relies of solder fingers on board edge to link the boxy shape together. The same board also carries the power supply module derived from a regulated full wave rectified output from the transformer. I am not sure if the transformer is isolating, it does not need to be since the isolation occurs at the end stage with a couple of optocouplers. The voltage sampler and the current shunt are obviously non-isolated.
LDO for dual voltage level output and 4 pads for 2 waveform signals
All the magic of actual energy monitoring then happens in the Vangotech V9811S with includes a 8052 MCU for driving the LCD and other functions such as Modbus support. I am planning to power it up with a 3.3V/5V supply and feed it waveforms from my low voltage AC test rig and observe the readings. I also have 3 phase version from Eastron on order and a few engineering samples from Vangotech for their 3 phase ASIC to build a low cost/ low voltage Dev kit like I did with the ATM90E26 Featherwing.
Anatomy of the head, MCU + AFE, EEPROM and an old school LCD

Wednesday, November 30, 2016

Adelaide Maker Faire 2016

Last Sunday (6th of November 2016) I spent almost the whole day on my feet talking to people at the Adelaide Maker Faire. It was a great event and I have been looking forward to it for almost a full year.

It took a bit of preparation in putting together a demo that would pass the electrical safety requirements and be tested and tagged. I chose to use a compact fluroscent lamp and a halogen lamp as my demo loads to illustrate the impact of power factor on energy measurements. The modern CFL's have notoriously low power-factor due to the uncompensated choke in them. I ended up making an earthed and a double insulated enclosure for my demo.
Earthed Test lamp box
Double insulated test lamp box


Earthed lamp fixture with Perspex lid

The main PCB on show was the Energy Monitor Featherwing with the ATM90E26 on-board. This does very quick and accurate measurements and I chose to send the data over serial to a laptop for graphing rather than use the rather crowded wifi and 3G environment at the faire. It also makes a more compelling demo since I can sample and display the power every second rather than every 15s with thingspeak (faster with workarounds still only down to 2s due to 8 channel limitation, must investigate running my personal Blynk or EmonCMS server).
ATM90E26 Low-voltage Energy Monitor (perspective view)

ATM90E26 Energy Monitor top view
My overall display was pretty minimalist since I focused on getting the hardware working rather than producing any marketing material. I ended up handing out notes written on the spot with my details on them. There was fair bit of interest and some people shared ideas with me on how they had solved the same problem themselves. I hardly got time to check out other displays myself. Next time I will make sure I have someone to relieve me. I did manage to have a peek at the Daleks and saw a toddler hop out of a solar car, sights you can only see at a Maker Faire. This was southern hemispheres biggest and the buzz was amazing.

Maker Faire setup with lamps on
At the end of the day the organisers of the Maker Faire handed me a maker of merit badge which I am quite proud of and next year I plan to show up with even more projects.

Monday, October 10, 2016

ATM90E26 + ESP8266 Energy Monitoring

Before I commit a design to a PCB, I usually make a messy jumpers everywhere version on a breadboard. This is not always possible for a full complex design, often sections get committed to PCB and then modules find a home on the overall breadboard prototype.

This has been the fate of my ATM90E26 Breakout. I plan to eventually make it into a single board /accurate wifi enabled Energy Monitor. For now it is living next to a NodeMCU on a breadboard. The ATM90E26 has the flexibility to be accessed both over SPI and UART. However the SPI mode it supports is only Mode 3, which is an unsupported mode of the ESP8266 Arduino stack. So I ported my ATM90E26 Arduino interface code over to UART mode with CRC check and everything worked okay after a few days of head scratching. You can find it on the UART branch in github.

I would like to build a self-powered energy monitor, so I pulled out a venerable 7805 and added it to a half-wave rectifier from the 12V AC-AC transformer used for voltage waveform sampling. When I was using a full-wave rectifier in the past the overall DC voltage was too much for thr 7805 to regulate without a heatsink, however with the 1/2 wave version, the diode takes care of dropping half of the voltage leaving the 7805 functional without a massive heatsink.

I calibrated the set-up with some magic multipliers found using the datasheet, maths and my 116W calibration lamp and it all works like a charm as shown in the video below.

There seems to be some noise leakage onto the UART when AC signals are applied, I will attempt to rectify this with an optoisolator. However a simple reboot of the ESP8266 platform seems to quickly fix any software serial communication issues. Meanwhile I am putting it all together into a featherwing form factor for PCB manufacture.

Sunday, September 11, 2016

Hexiwear based GPS-AHRS for Nikon hotshoe

I have been working on the GPS-AHRS hotshoe for a while. The initial complete prototype was built around the Xadow platform. It is one of those continuous iteration projects, I wish someone puts me out of misery and brings out a COTS solution that is affordable soon.


I put the idea for the GPS-AHRS on the Hexiwear platform and received a free Hexiwear dev kit to built it with, a great deal. The Hexiwear has lots of toolchains for building projects with, including the Kinetis Design Studio from NXP and ARM MBed. This makes development on this platform a breeze. It also comes with a lot of sensors : barometer, gyro, accelerometer and magnetometer are all included. It has built in BLE for communications and a 16bit OLED screen. The only missing links are GPS, Nikon camera interface and a sensor fusion algorithm to obtain Euler angles/quarternions from raw motion data.

I already have working MBed code for sensor fusion and I have successfully tested reading all the motion sensors over I2C, so this should be easy to put together in the next few days.
I also compiled the stock firmware in KDS and did some small changes to show the Magnetometer data as part of the UI. This was relatively simple simply involved attaching a listener to one of the messages already being broadcast in the RTOS and a hacked up page to display the results. The results of this code can be seen below.


Tuesday, August 30, 2016

Counting Pulses with Maxim DS1682

I am often asked about interfacing the Energy Monitoring system with traditional spinning disk meters or blinking LED/Pulse type meters. For this application there used to be a very nice 1-wire pulse counter IC from Dallas/Maxim - DS2423. However it is end-of-life and no longer available. The next best option is the DS1682/83 series of RC oscillator based elapsed time recorders. The elapsed time function is not critical for pulse counting, however it is a nice feature. The lack of crystal makes is slightly inaccurate, but pretty robust and great for outdoor and industrial applications. It also has an EEPROM to store counted pulses, so the counts are retained across power cycles and the main MCU can sleep between long interval reads.



To test out this chips I built a Grove breakout which I am planning to use with a tipping bucket rain gauge. I have tested it on the ESP8266 with some basic Arduino I2C code and theres seems to be already existing Python code I can extend to use with my Udoo Neo Weather station.


Pulse counting can be easily done using a GPIO and an interrupt, however it requires the MCU to be constantly on. The DS1682 has a 17bit event counter giving it 131,072 total event counting ability before a reset is required.