YASSD: chainable, UART controlled, 7 segment displays

For a few projects I like to use 7 segment displays to indicate a value like voltage, current or temperature. 7 segment displays are cheap, easy to read and easy to control. The biggest downside is that it can cost a lot of IO pins on a microcontroller to control a handful of 7 segment displays. One option is to buy finished 7 segment displays on Ebay that can read in a voltage. The downside of these is that the accuracy is not great and they can only be used if a certain range in voltage is what you want to display.

So time to design my own, yet another seven segment display, or YASSD for short. They have a 4 digit 7 segment display on one side and a STM32F031 and a 74HC595 on the other. Other features are:

  • UART controlled
  • Maximum of 8 on one UART bus, 3 solder bridges determine the ID of the display
  • Software updatable via UART
  • Easy to mount on a frontpanel

They look like this:

The hardware is simple, an ARM M0 microcontroller translates the UART messages to data for the 74HC595, some NPN transistors are used to select the digit. The reason for the, somewhat overkill, STM32F031 ARM M0 microcontroller is that it’s cheap, with a bit more then 1 euro per IC, it contains a UART bootloader, so other people that want to build this display only need a PC with a USB to UART converter and that it’s a microcontroller I’ve used often before. There is one bodge wire, I forgot to connect the GND from the 3.3V regulator to the rest of the PCB. In the files uploaded on my github this is fixed.

The 8 resistors of 100 Ohm close to the 74HC595 limit the current for the display. With the red 7 segment display used the current is a bit less then 10mA per segment, but these need to be recalculated for a different color display and on how bright the display has to be.

Controlling them is easy, connect them to a PC or microcontoller, setup UART to use a 19200 baudrate and send a string formatted like this: “ID,VALUE\n”. For example: “07,1234\n” would make it display 1234 if the YASSD has 7 as it’s ID. Adding a dot is no problem: “07,20.01” will display 20.01.

The ID is determined via the 3 solder bridges using the following formula: ID = (SB1 * 1) + (SB2 * 2) + (SB3 * 4). If a solder bridge is not present, SB is 1, if the bridge is present, SB is 0. This means that if there are no solder bridges present, the ID of the board is 7. By having YASSD’s with a different ID it is possible to connect a maximum of 8 on one UART bus.

The hardware and software are both open source and can be found on my github.

Abusing DMA for fun and LEDs

This blog post assumes you know the basics of multiplexing and how an LED matrix works. The end result looks like this:

Let’s say you want to control an LED matrix. A plain boring 8*8 LED matrix you bought on Ebay a long time ago and is still somewhere in your desk. It’s pretty simple, after figuring out how multiplexing works you’ll have a smiley drawn on the LED matrix in no time at all. But it’s much prettier if the brightness of an LED matrix can be controlled via PWM, maybe make some nice animations as well. For an 8*8 LED matrix, 8 PWM outputs would be needed and you are good to go, something a bigger microcontroller generally has available. But what if you want a bigger LED matrix, 16*16 perhaps. And animations running smoothly at a high frame rate.

For an 8*8 LED matrix, to make it look smoothly, you need to multiplex the screen at about 100 Hertz minimum. So set a column, wait a short time, switch to the next column and set the value for this column, wait a short time etc etc. With 100Hz there is 10ms of time per screen, so about 1.2ms (10ms / 8 columns) per column. More then plenty to set some IO pins to show an image. For a 16*16 LED matrix this time halves to 0.6ms. PWM makes this a bit harder, as a whole PWM cycle must fit in this 1.2 or 0.6ms, meaning the PWM peripheral must run at 833 or 1666Hz minimum. This is all no problem for a PWM peripheral in a modern microcontroller.

But what if you don’t have 8 or 16 PWM pins? For example, an Arduino Mega has 12 PWM pins. ARM M microcontrollers like the STM32F103 have more PWM pins, but those are shared with other peripherals as well, so they might not all be available to use in a project.

An option is to bitbang PWM, toggle an IO pin quick enough to act as an PWM pin. This has the major downside of costing a massive number of CPU cycles. To get just 6 bit PWM, so 64 different levels of brightness, in the 0.6ms for an 16*16 LED matrix, the CPU must check 64 times if that IO has to be set high or not. This means that every ~10us the CPU has to handle IO. If you also want to calculate some animation to display, the CPU will be very busy.

This is where the DMA comes in. The DMA, or Direct Memory Access, is a peripheral available in many modern microcontrollers. Simply said, it’s a co-processor that can copy data from one place in the microcontroller to a different place without the CPU having to do a thing. It can be used to transfer an ADC value to a buffer in RAM and give a sign to the CPU when the buffer is full. The microcontroller I’ve used for this blog, the STM32F103, can transfer memory to memory, peripheral to memory and memory to a peripheral without the CPU doing a thing apart from setting up the DMA. Transferring data to a peripheral without costing CPU cycles. That sounds like a nice way of driving an LED matrix.

Continue Reading

Numican, a small numitron clock

I wanted a numitron clock on my desk. As, in my opinion, a decent looking enclosure is one of the hardest things to make I made the clock in the size of an altoids can so just a few holes should be made for an enclosure that looks not too ugly. It’s almost fully in SMD and can be powered using a USB port, making it a lovely clock for almost every desk.

In the end I ordered a custom enclosure from Schaeffer in Germany for a nicer looking clock.

The build process, design files and such can be found on hackaday.io as I used the project to try out hackaday io and see if it worked for me.The link is: https://hackaday.io/project/18166-numican


Quick GUI for MBED projects, part 2

The previous post I explained the code for the dear ImGui part of the GUI. In this part the code for the serial connection will be discussed.

This code is made up of 2 parts, the MBED code and the PC side code. The MBED code will be discussed first. The MBED code uses the excellent MODSERIAL library. The MBED code after stripping away the initialization and such looks like this:

Continue Reading

Quick GUI for MBED projects using Dear ImGui and Serial

A lot of microcontroller projects communicate with a computer using a serial connection as this is still a very simple and cheap way of communicating. Making a program on the PC to communicate with a microcontroller can however be a bit tricky. On accident I stumbled on the Dear ImGui library, a C++ library to quickly make a GUI, for debugging a C++ project for example. I really liked the look of it, it looked really simple, with a lot of usable gui objects. Dear ImGui can use OpenGL, DirectX, Vulcan and more. It is cross platform as well, as long as OpenGL is used.

A gui is just half of the issues solved, a good library for serial communication is also needed. After a quick look Serial popped up. Except for the annoyingly generic name it is a very nice looking library. Cross platform and simple to use, being made to look and feel like PySerial.

With these two libraries it is possible to make a C++ cross platform GUI for all kinds of microcontroller projects. I decided to make a simple project first that can read and write to some IO ports, set the DAC and read in two ADC’s.

And the result looks like this:


Continue Reading

Ebay headphone amplifier kit

A while ago I bought the following headphone amp on Ebay as it looked like a nice small project. The included case and battery are also quite nice and the price was very affordable. A few weeks later the parts arrived in a very recognizable china envelope. In the package I found, exactly as pictured on Ebay, A nice looking PCB, a bunch of parts, a battery and a case. The first downside is the lack of documentation. There are no build instructions, making it a bit less nice for beginners.

All the values of the parts are printed on the PCB silkscreen and written on the parts whenever needed. So building it takes a bit of figuring out but is very doable. 2 issues arise fairly quickly though. The diodes have no anode or cathode marked on the PCB and the IC that is surrounded with diodes has the marking removed. I think it’s clear where this is going, I soldered all three diodes incorrectly and after correcting the IC got insanely hot in less then a second. Lovely.

WP_20160123_15_48_37_Raw_LI WP_20160123_15_09_23_Raw_LI

The rest of the PCB went OK to build, the parts are from a good quality brand and the PCB looks nice with the gold plating on it. The only issue where the diodes.


But now I’m stuck with a non working PCB as the IC that generates the voltages for the opamps is well, dead. After emailing the seller they couldn’t give me the schematic. So well, time to reverse engineer the schematic :)

Continue Reading

Tinycortex, part 3. Offline compiling

The MBED IDE is an online IDE, which is less pleasant if you want to work without internet or prefer your own editor. Luckily it is possible to export an MBED project and use an offline compiler. It can export to KEIL, GCC and a few others.

KEIL is a well known IDE now owned by ARM. They offer a free 32KB limited version and with the Tinycortex having 32KB of flash memory that limit is no issue. KEIL is Windows only and the unlimited version is quite expensive. A guide on exporting to KEIL can be found here. Because KEIL just works it’s the recommended way for offline compiling.

It is also possible to export to a GCC makefile which is especially nice for people using Linux or OS X.  An ARM compiler is required, the most used and free one being GCC ARM Embedded, which is being maintained by ARM employees. On a Linux system with make and the ARM compiler installed compiling the code is just typing “make” in the terminal. After a few seconds the output for the Blinkaled project you can find on my github is:

Sadly enough it’s not possible to just copy the generated .bin file on the tinycortex. With just the makefile the binary file isn’t checksummed. A small script in the “Tools” folder called checksum is used to checksum the file. Place it in the folder with the binary and run it with the command “./checksum filename.bin”. The checksum script is compiled for Linux, OS-X or Windows users need to recompile it using the command “gcc -o checksum checksum.c”.

Linux and OS-X users have to use the dd command to place the binary on the Tinycortex.

Tinycortex, part 2.

The last post described the dev board now called the Tinycortex. In this post I’m going to explain how to use it. All files can be found on the following github page. On this page you can find the hardware design files, a few scripts to make using them in Linux easier, a blink a led project that can be compiled offline and the pinout. The pinout of the Tinycortex is the following:


It has 32 IO pins, 3 UART, 2 SPI, 1 I2C and 8 analog inputs. It also has 1 LED and 1 button on the PCB for small tests and projects.

To use the Tinycortex in the MBED online compiler the MBED LPC11U24 can be selected. One header file needs to be included. It can be found on the github page or in the example blink a led project on the MBED website. After the header is added the pin names IC1 to IC33 and LED1 can be used in the code. Or you can import the blink a led example and modify that.

After compiling the MBED environment will generate a .bin file. To place this file on the Tinycortex connect it to the USB port with the ISP button pressed. Release the button after plugging it in and you should see a 32KB flash drive with one file, firmware.bin, on it. Remove this file and place the new .bin file on it. After that press the reset button (labeled RST) and the new code will be executed.

A tiny MBED compatible dev board

I like the MBED boards, they are small, fast and the libraries and community are great. The only downside is the price. The cheapest official MBED board is around 50 euro’s and some cheaper supported boards like the ST nucleo boards don’t fit in a breadboard. I wanted to make a small MBED compatible dev board that fits in my breadboard and costs a lot less then the real MBED boards so I can just leave them in a project without caring too much.

I decided to use the LPC11U24 as this is one of the two microcontrollers that is also used for the real MBED boards. I have had some bad experiences with the MBED libraries for the ST microcontrollers so I’ll stick to the well supported NXP one.  For the rest a SMPS 5V to 3.3V was something I’d wanted. A linear regulator would get a little bit too hot if more then 250mA of current would be requested from the 3.3V line. I also made everything SMD, including the pinheaders. It just feels a bit cleaner for me to have zero through hole parts :)

The end product looks like this and I shall call it: the Tinycortex, because I suck at making names:


It is even a bit smaller then the real MBED, has 32 IO pins and looks cute. What more to wish for :)

In the next post I will show the pinout and how to use it in case anyone makes one and for the people I gave one as a reference.

Measurement gear

After building a few project and with some of them actually working, always a pleasant suprise, I though it was time to invest in some gear to measure the stuff I build. Just listening is only so good of an indication if a project works like it should. After some searching online I found a second hand Creative E-mu Tracker pre USB sound interface.


Continue Reading