Saturday, June 22, 2019

Nairobi 2nd OSHW meetup

After a many month hiatus we finally put together the 2nd Nairobi Open-source hardware meetup. This time we were at the Tav Irish Pub near Nairobi Garage on Waiyaki way. The pub was chosen due to proximility to Nairobi garage and possible use of that venue. As it turned out none of us were memebers paying the $60 per-month fee so we ended up co-opting the pub in Chicago 3H fashion.
PCB Lineup
PCB Lineup
I had collected PCB's over the last few month from Aisler, OSHPark and PCBWay all shipped to Kenya from Germany, US and China respectively. So we lined up to try various soldering techniques on 0603 Jellybeans and some 20pin TSSOP IC's.
Soldering demo
Soldering Demo
The techniques we we tried were the tack, finish and reflow one using the iron and an experimental one with paste and dry-iron I had picked up recently. I didn't have a temperature profile controller for the dry-iron method. So we were just going to wing it by the eye.
Part Placement
Part Placement
We pasted up the boards using screwdrivers and tweezers. Started the reflow till the parts settled. Then simply turned off the iron. I am sourcing a K-Type thermocouple and SSR from KTechnics to get a better handle on this for next time. However the dry-iron does reach sufficient temperature for leaded solder reflow.
Dry iron reflow
Dry iron reflow
By the end of the session we had assembled x2 CS5464 Breakouts. Next step from here will be suitable MicroPython and Arduino drivers to ensure these things actually work. We had a lot of fun over the meetup and I hope to continue having these sessions. Next time one of the participants has promised to bring his Weighbridge Automation and IoT set-up.
Scavenging Coffee Machine
Scavenging a Coffee Machine
Following the meetup I have been hunting for accessories to make the dry-iron reflow less of a fire hazard and more controllable. (Un)fortunately the coffee machine at work has been fried by the spikes prevalent in the grid in Kenya (especially during the rainy season), so I have a spare K-type thermocouple I can work into the build. I have also co-opted a tissue holder we had on our dining table to stabilize the inverted iron during reflow.
A stand of opportunity
Stand of opportunity
Onwards to the next Meetup.

Sunday, March 3, 2019

Kogan Energy Monitor Teardown - Sonoff-Pow in a wall plug

After doing a tear-down on the TPLink Wall Plug energy monitor I found mentions in Australia of the much cheaper Kogan Alternative. So I decided to get a couple of them see what makes them tick as well.
General Assembly of the whole unit

TL;DR - The Kogan one is cheaper because it uses a bare metal (non-linux capable) CPU and a PWM output type energy monitor (without intricacies of a SPI protocol and calibration). It is essentially a repackaged Sonoff Pow.

The details of the build are packages in sections as I discovered them.

LV and Buck converter

The LV section consists of two separate cricuits:
  1. Relay to switch the load
  2. Buck converter to rectify and convert 240v to 5v to power electronics
The diagram below presents both of these sections. The Buck converter is basically the toplogy found in many aliexpress products. Perhaps with the difference of being unisolated (notice no slots). The relay is rated at 15A which is nice compared the TPLink product which uses x2 - 5A relays in parallel to achieve 10A.

Low Voltage (240v) Circuitry

Energy Monitor and LDO

This a 3.3v operated section which uses the super low-cost PWM output energy monitor IC made popular by the Sonoff the measure instantaneous voltage, current and hence power. The pulses are channeled to the main processor for forwarding to whatever backend Kogan has put together.

Metering and LDO

Main Processor

The design seems to have taken a standard ESP module and planted it on a basic PCB to fit in the power-plug form factor, sideways. The carries board has lots of markings and test-points making the task of reverse engineering and putting new firmware on this board almost too easy.
Processor module adapter
Marked bottom test pads of processor carrier PCB
Over all this looks like a nice certified unit which you can run your own firmware on thanks with the help of the right triangular security bit.

Wednesday, January 23, 2019

Around Kenya in 4 days and a year ( part 1)

2018 was a year on making impromptu decisions and hopping on random flights heading for adventure. In the beginning of the year I left Aerometrex to explore new opportunities at Lori.

It turned out I finished the year in similar markovian motion travelling around Kenya with a couple of high school friends. Thank you so much Eric for driving and showing us the beautiful country.

I received a call late on the 29th December proposing the trip. I booked a ticket of Safarilink and went to bed.  Flying out of Wilson Airport is magnitudes easier than flying out of Jomo Kenyatta International. I almost missed the flight, but the empty Christmas streets in Nairobi and low access overheads in Wilson meant I flew into Kisumu with zero dramas. I hopped in a Probox from Kisumu to catch up with the other 2 in Kericho. The Probox are known for being death machines, but is a super cheap and fast way to get around. There is another article somewhere revolving around the impact of the Probox on transport in Kenya.
Tiny Kisumu Airport
Safarilink Flight (Turboprop)

We then travelled via some roads still being built from the tea-gardens of Kericho to the lush sugarcame farms of Awendo. In sections the road meandered into farms and cars had to go in a single file and often backup into fields when a truck came by from the other side.
Road through Kisii
It was a great night of going out to watch football match in Ulanda town and staying at Owuor's Simba. The road from Awendo to Ulanda is awesome. The sugar cane is a mass scale project and produces a lot of bagasse which can be recycled into paper tissue and other products with the right infrastructure.

Mercury laden waters used to extract gold nodules

Sheds housing diesel engines and rock crushers for mining

Next day we took a side trip to Macalder gold mines. It was in interesting experience what people will do to earn a living in far flung places in the country. Migori county is known for its high concentration of mercury in water. The operations here clearly explain why. Rocks are dug up from underground gold mine and manually broken up into smaller chunks and ground into dust using diesel operated octagonal drum crushers. The whole place is noisy. The dust is then filtered to remove solubles and then mixed with mercury to form gold amalgam nodule, women (some of whom were pregnant) then stir the mixture by hand to find gold bits. Mercury is then recovered by retorting in small ovens and reused. At least some work is being done to raise awareness of the harm from Mercury, hopefully sanity will prevail over economic incentives.

We then continued our trip south towards Kenya Tanzania border and I will continue the story in another post.

Sunday, January 13, 2019

Making PCB protos in Kenya

In Adelaide I made a lot of prototypes PCB's and filled up filing cabinets and shelves with them. Some had value to others and I sold them on Tindie and CrowdSupply. For the last year I have been hanging out in Kenya working at Lori. The output in terms of open-source hardware has taken a back seat compared to proprietary company code (we did release one open-source piece of ETL code).

This is near the end of my 3-month stint in Kenya and I decided to run an experiment in the feasibility of designing and assembling prototype batches of PCB's for an energy monitor ASIC I have been meaning to try out - the CS5490. This is a super low bar for a test run. The IC has very few dependent components and large pin pitch making it ideal of teaching manual SMD soldering.

PCB Design

Once the goal was set I broke out KiCAD and spent a night and a Sunday churning out a basic breakout board. The PCB Design and BOM are published here.

Order PCB

The harder part begins once the PCB design is done. Actually making this a physical reality in Kenya. I placed the usual order via PCBWay. A few days before Christmas before I went off to a round a country drive with some friends ( awesome content for another post). The shipping would be from Shenzhen via DHL. The logistics promises arrival by the 28th December.
Order Parts

The BOM for the design is not super complex either. Mouser covers the Kenya region. However there is no option for free DHL for orders over $60 which I get in Australia. I will be in Kenya only till the 20th January and the streets have no numbers or postcodes, which makes ordering via snail mail for any international shipping simply not fit the address template most places have. Perhaps global addressing via plus codes will become reality in future eCommerce systems. Mouser shipped the parts out of Texas immediately, I ended up paying more on shipping than for parts. The customs magic was yet to come.

Clear customs

Any packages with value below $1000 sail through customs in Australia. The Kenyan government will lose out on significant revenues if they followed this practice. On the flipside young engineers with limited resources are being stifled in self-driven learning and experimentation by this practice. I got a detailed/itemized bill from customs via DHL which ended up being the same cost as PCB + shipping for PCB's and around 20% of the cost of the parts. See file here for details and breakdown.

Source tools and materials

Thankfully this bit was much easier with a couple of local soldering iron , jumper wire and tweezers suppliers filling the gap. The ball was dropped by Fargo in delivering the stuff I ordered online again due to the addressing snafu, they attempted 5 deliveries to the wrong place before I had to redirect to the office address where a lot of parcels are received. I can recommend Nerokas and Ktechnics for getting parts in without hassle. Again better last mile logistics would have made things faster. I ended up attending the assembly meetup without the proper tools.

Find assembly space

To avoid annoying my landlord with solder fumes and messy paste workbench I started looking for a place to get together with a few interested parties and assemble the boards (at least one). I ended up starting an open-source hardware meetup and getting some Mang'u engineers together to hand solder the parts. 

Test and publish drivers

Finally this Sunday I have put together some basic micropython code to read registers from the CS5490 over serial and display them in a micropython notebook. Nothing production ready but proof that the PCB design and assembly worked as expected and we can achieve custom products here, with a lot of bureaucracy and false starts.

I am happy to meet more people designing and building open-source hardware in Nairobi and hear about their experience.

Sunday, November 25, 2018

Onion IoT module Python SPI

Some say China is the country of 80-20, things are complete and great to 80% , the remaining 20% of polish is left hanging. The Mediatek CPU used in the Onion IoT modules suffers from a similar shortcoming. There is an working SPI bus, but it is simplex ( OUCH!!) . Simplex means only receive and transmit can take place at a time.

For interfacing the Onion Module with Energy Monitor IC's this is a huge blocker since the typical communication flow with this IC's runs as:

  1. Write a 8 or 16 bit register address to the SPI bus
  2. Immediately read-back a 16bit value over the SPI bus while the chip-select is held low.
The proposed remedy to this after a bit of debugging and probing with logic analyzers is to directly use the user-space SPI c-library or to fix the python-spidev library with an xfer3 method which does a special write where the clock keeps going, the first bytes are written and next bytes are read.

I have started on the path for fixing the Python library on my fork. OpenWRT build system seems happy with my efforts so far. It remains to be seen if we can communicate with the energy monitor ASIC's. Contributions are much appreciated.

Nairobi AI Saturdays - Book club with Stanford Videos

Last couple of Saturdays I finally got a chance to do out-of-work activities and I decided to attend the Nairobi AI Meetups in the IBM offices in the Atrium building. It is a great venue for learning and interacting with people in the community.

The meetup can sort of be described as a book club for Stanford NLP AI/DL lectures series. I have encountered 2 possible formats so far, both of them are quite hilarious in execution.
  1. We watch the lecture at x2 or x1.5 speed during the session and have learning and discussions around the topic. This is somewhat limiting since we cannot ask the Stanford lecturer questions. So meetup participants ask each other.
  2. We get one or two of the meetup participant to watch lectures during the week and prepare reformatted slides from the content to present the lecture as a proxy of the Stanford lecturer. While the presenter is standing in for the original, we can ask the proxy questions and clarifications and have more interactive learning. This format is more fun, but requires more prep-work and effort from a couple of people. Increasing the pool of people doing this would be great.
The last set of lectures we watched covered Tree-RNN's and Co-referene . The tree-RNN's are particularly powerfull in capturing the semantics of prose. The meetup could really use more linguists in the mix to clarify some of the linguistic features NN's can learn, this is a multi-disciplinary field after all. I will see if we can convince people from the Nairobi University Department of Linguistics to attend, the lack of recency on their website does not give me much hope.

Sunday, November 18, 2018

The Red Light - Competition entry with BeagleBone Green

Riding in Adelaide especially during night can be a hazardous activity. You have to share the road with cars and pedestrians, staying safe from the former and keeping the latter safe. Avoiding pedestrians requires vigilance from the cyclists, but the attention of cars has to be drawn with bright lights. Often due to circumstances you might need to ride in the middle of the lane or cut across lanes to make a turn. During the day these activities are indicated with a hand signal, I made this project to translate those to bright lights controlled by your motion and muscle activity to obvious signals during the night.

NOTE: This is a cross-post from - 

Various light options tested with data from serial port

The controller used in this project is Myo Armband - it contains a 6 DoF IMU and 8 EMG sensors for muscle activity. The controller communicates to the BeagleBone via a BlueGiga BLE dongle, this appears as /dev/ttyACM0 on debian based images. The raw data from the sensors is processed using Scikits Learn and an NN-classifier to interpret the rider motions. The turn and stop activity is then passed over to a realtime controller (either the BeagleBone's native PRU or an external microcontroller like the Teensy) to drive a WS2812B LED matrix.

Data stream from Myo controlling LED Matrix

The BeagleBone Green is modified to add a JST connector to activate the on-board battery charge management system to use a Lipo for poweing the bike lights according to this how-to. See the images below for details of this modification.

The whole system is wearable and battery powered. The LED matrix is stiched onto a high-vis jacket, a must for any night time riding and the Myo is placed around the fore-arm before starting the ride. Here is a video of the lights in action linked to gestures.

Testing gestures and linked lights

The Details

Install git on BeagleBone Green and sync the date using ntpdate. Then checkout my repository.
Plug the Myo Blue Giga receiver in and check that it is recognised
There should be 3 usb devices. The BeagleBone Green may need to be powered over USB instead of battery for the USB hub to power up and recognise the module.
Install the dependencies for myo-raw.
sudo pip install -r requirments.txt
The myo-raw can also be installed under Windows  or any other desktop environment to stream the data from the BBG and display it remotely.
Run myo_raw_osc with the following command to stream data to remote server, print locally and send results from EMG sensor to external LED panel controller (in my case the Teensy, however I am also experimenting with the PRU's)
screen -dmS myo python -v 1 -s 1 -d [x.x.x.x,7110] -c 2
This will output controller codes to the Grove UART port /dev/ttyO2 to the display driver in sync with arm motion. A bit of looking at the experimental data and tweaking of the classifier may be needed to get it set to you movement patterns.
That's it for the setup on the BeagleBone Green in the non-PRU mode. For the Teensy, clone the git repository as below.
Install the Teensy add-on for the Arduino IDE as described here and upload the code to the controller. The LED matrix data pin is connected to pin 2 of the Teensy and the BeagleBone UART is connected to Hardware UART1. I power the LED matrix from the 3.3V output of the Teensy rated at 100mA, this allows safely connecting the 3.3 output signal to this particular matrix. Larger matrices may require buffer IC's and separate power supply. The BBG 5V system pin is connected to the VIN pin of the Teensy for power supply off the battery/USB OTB connected to the BBG.
That is all for the set-up of this simple but very useful project.