Wednesday, 22 May 2019

Soldering Kata

7x7 LED Matrix
When I were a lad, LEDs were a big deal, literally: £1 each. Now someone in China manages to make a living selling them for £1 for 100. With inspiration provided by an Instructable, a rainy afternoon and the need for some soldering practice I set to work.

The Instructable's, err, instructions were clear enough:

  • take a piece of protoboard (the sort with pads instead of strips)
  • solder each row of LEDs anode (longer) first to hold them in place
  • cut the cathodes to size and bend them through 90 to connect each row's together
  • test each row after soldering!
  • I then cut a piece of stripboard ("veroboard") into single strips and connected each column's anodes together in a sort of DIY dual-layer PCB arrangement, see below.

Rear view: anodes connected in columns

The last step was the only point where I deviated from the instructions. (I first attempted to fit a single piece of veroboard over all of the anodes but found this impossible: there was too much variation in their positions. Perhaps aligning each row of LEDs as it is soldered using veroboard might work?)

Next: mount vertically on breadboard, add a handful of resistors (470R) and connect to an Arduino!

I wrote an Arduino library for it, available on Github. It contains a couple of examples, the simplest can be seen running below. (The moving light makes keeping the camera focussed impossible, sorry.)

The disadvantages of this bit-banging approach to driving an LED matrix are fairly well-known:
  • it uses an excessive number of GPIOs (14 here)
  • the GPIOs themselves can't supply very much current, so the more LEDs lit, the dimmer they are
  • PWM-style dimming is not practical
  • timing is tricky: since it relies on persistence of vision to work, each refresh cycle must take no more than 40ms
For all of these reasons, using a dedicated driver chip is recommended. More when my MAX7221 (another £1) arrives on the ship from China in a couple of weeks!

Friday, 1 June 2018

It speaks!

Porting TTS to the ESP8266 processor has been on my to-do list for a while now, prompted by a comment on an issue I'd created to remind me. To do this, I realised that I'd have to reacquaint myself with PWM on the ATmega328p.

At its most basic, a PWM waveform is a square-wave with a varying duty-cycle. Both the frequency of the square-wave and the duty-cycle are determined on an AVR by the its built-in timers. PWM on Arduino pin 9 (hardware pin 15, OC1A), for example, is driven by Timer-1, a 16-bit timer.

Several PWM modes are available; TTS chooses the "phase and frequency corrected" option.

The diagram shows how this works to change the duty-cycle of the output pin:
  • the timer counts from BOTTOM to TOP and back down again
  • when it crosses the OCR1 threshold going up, it sets the OC1A output high,
  • when it crosses this threshold on the way down again, it sets the OC1A output low. 
Therefore by dynamically changing OCR1, we can change the "volume" on the output pin.

The final piece of the puzzle is how the frequency of the square wave is determined. Since the timer ticks on every clock cycle, it will take 2*TOP cycles to cycle from BOTTOM to TOP and back. The AVR has a clock frequency of 16MHz and PWM_TOP in the TTS library is defined as 1200/2. This gives a frequency of about 13kHz.

By default PWM on Arduino/ESP8266 has a range of 1023 and frequency of 1kHz. However it provides APIs to change these values. By setting them appropriately, the ESP8266 speaks!

Wemos Mini D1 with TTS amplifier and super-cheap speaker
The picture shows a Wemos Mini D1 connected to a modified version of the simple LM386 amplifier described at the TTS GitHub. (The modifications arose from a Hackaday article on the LM386 and are summarised in the GitHub's README.)

This amplifier sounds surprisingly good, considering its total cost was about €1. Hooking it up to a signal generator and oscilloscope produced the following pretty pictures.

At low volume, the output is a pretty faithful inversion of the input signal (a 1kHz sine wave):

Undistorted Signal
At high volume, the output is clipped by the supply rails (but still sounds pretty good to my untrained ear):
Clipped Signal
These pictures were produced using an Xprotolab Plain, an amazing combination of Oscilloscope, Signal Generator and Protocol Analyzer implemented on an AVR XMEGA. Buy one!
Xprotolab Plain

Tuesday, 29 May 2018


One of the very few downsides of ordering PCBs from Seeed Studio's Fusion service is the shipping cost. While an individual PCB can cost less than $0.50 in multiples of 10, shipping to Western Europe can add another $20.

One way to amortize these costs is to add more PCBs to an order, either from my own "design pipeline" or by searching online for cool projects. One very cool project discovered in this way, was ArduTouch from Cornfield Electronics.

One the hardware side, this is basically a battery-powered Arduino Uno with an LM386 amplifier driving a 4-Ohm mini-speaker, or your HiFi via line-in. The keypad is very nicely integrated into the PCB, see my construction below.
ArduTouch with Batteries and Cheap Speaker

Software-wise its GitHub provides five (at the last count!) different synthesizer sketches and a library for constructing your own. As usual, sketches are compiled in the Arduino IDE and uploaded by FTDI cable. A nice touch is that they uploaded a BOM for Mouser, making ordering the parts a snip!

I have several PCBs left over from this order. If you want one, contact me through the Tip Jar on the right. However I would encourage you to support the guys who made this great project possible by buying one of their kits.

Saturday, 13 January 2018

Web-Configured ESP8266

A unique feature of Internet-enabled "things" is that they often have an Internet connection and little else. First-configuration of these devices therefore presents a challenge, which most solve by creating their own wireless access point, to allow their owner to supply credentials for the local wireless network.

Web-Configured ESP is an attempt to abstract away the boilerplate required for this task, and other related ones. It's a "starter" sketch providing the following basic features:

  • Creation of a temporary Access Point ("MyESP") allowing the configuration at the conventional url,
  • A basic web-server running at this address, serving config.json and storing updates to it
  • An HTTP update server, allowing upload of new sketches "over the air"
  • An mDNS responder allowing access at http://myesp.local
Together, these features allow bootstrapping of sketches without requiring the devices to be tethered to a development machine, and user-provisioning of the finished article in the field.

Wednesday, 8 November 2017


My title will no doubt remind regular readers of 2013's Weather Guy, a weather app which completely maxed out an ATMega328. Well it's had a technology refresh replacing Ethernet with Wifi, XML with JSON and AVR with ESP. A surprising amount of display code survived the upgrade and can be found on GitHub (along with Eagle files and Gerbers).

The hardware has also been simplified and now comprises merely:
The Wemos has been mounted on the underside of the board as can be seen above, because I soldered its pin headers on the wrong side; however this suggests to rotate the display by 180 degrees, making the build more compact.

The software is built on the following fine components:
Perhaps the most interesting aspect of this build is its configuration:
  • Stored in JSON format in the onboard flash filesystem
  • An index.html is served to a browser which loads the configuration file and initialises form input items (via Transparency)
  • Submission of the configuration form transmits the form values in JSON format to the server where it is stored back in the filesystem
  • The index page also supports firmware upgrade
This pattern, where the client assembles a UI for the user out of pieces obtained from the server is finally becoming prevalent in the wider web, but nowhere is it more useful than here where the client has maybe 200x the power of the serving microcontroller.

The Weather Underground API provides current conditions, a 5-day forecast and astronomical information. Two of these can be seen below.

Sunrise and Moon Phase

Current Weather Conditions

Friday, 6 October 2017

Autumn Update

Some recent updates on the Github:

  • Interrupted is now compatible with the Arduino (1.8.4 and above) and Energia (18 and above) IDEs. However you have to cut-and-paste the examples, for now.
  • Tasks is also compatible with the Arduino and Energia IDEs, and (maybe) PlatformIO. Ditto caveat about examples.
  • uC-Makefile has been updated for the latest Arduino and Energia IDEs. Unfortunately Energia has discontinued support for the Stellarpad, so this option is now busted.
  • invaders now compiles under Energia 17, the last release to support Stellarpads.
  • WeatherGuy has had an ESP8266 refresh as WifiWeatherGuy. Stay tuned for more information on that.

Friday, 17 February 2017

ESP12-e Emergency Development Board

Mini-breadboards or DIY ESP Development Board?

What do you do when you can't wait for cheap breadboards to arrive from China? Build a development board of course!

The picture shows the work of an afternoon, to make a dev-board for the ESP-12 "IO Adapter Plate Expansion" (ebaysoldered up last time, which inconveniently didn't fit any breadboards around the house.

The circuit is based on this one except that it's powered from the FTDI cable.

The following week the mini-breadboards arrived. Haven't used them yet!