Matchbox Car – could it work?

All the parts were lying around so with a bit of solder and hot glue this is what happened:

matchbox car overhead view



This was done to test if the motors were powerful enough to push the weight of the matchbox. The answer is yes they can but a change in battery type is needed pretty badly. The motors only run for about 10 seconds before the battery voltage drops too low for them to run. A cr2032 battery is used here and they probably aren’t made for high current uses such as this. Each motor can draw 100ma from 3V so that is 200ma draw total from the battery. A small LiPo would be a good match (lol) for the job. The next question is could you fit in a tiny pcb with a small battery, a microcontroller, transistors to drive the motors and maybe a tiny reflective sensor (IR led + phototransistor) poking out the front to detect obstacles? The two tiny DC motors were ripped from a pair of broken 9g mini servos.

made a very quick video of it doing donuts, realised afterwords that it’s at a funny angle but oh well you get the idea:

Tiva C launchpad FFT with real time plotting using pyQtGraph

Circuit Diagram:

Circuit Diagram

Circuit Diagram

The biased signal generator signal is connected to AnalogIn 1 on the Tiva C which is pin PE_2. Signal Gen and Tiva C ground is common. The two 10k resistors from a voltage divider which will halve the 3v input to give a 1.5 v bias. The signal from the signal generator will be 3V peak to peak meaning that now the signal will vary from 0v to 3v using all of the ADCs available range. It’s probably a good idea to add a small capacitor in between the signal generator and the voltage divider to prevent the DC flowing through the signal gen. A 1Khz sample rate means that the highest frequency that we can reliably analyse is 500Hz. This comes from the the nyquist sampling theorem.


The Energia IDE was used to write and compile the code which runs on the Tiva C. See below for the code:

The reason the code is so short is because all of the fft code is contained in fix_fft.h which is a c implementation on the fft which has been around for over two decades. It was first written by a person called Tom Roberts in 1989 and a google search of “fix_fft.c” will return many mirrors of this code available for download. the fix in “fix_fft.c” refers to the fact that it uses fixed point short integers as opposed to floating point numbers which will result in a loss of accuracy in the fft but a faster execution time.

Here is the python script used to plot the fft data:

#python script to read 64 bytes of data from tiva C and plot them 
#using pyQtGraph on a loop. As soon as 64 bytes arrive plot is updated

from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
import pyqtgraph.exporters
import numpy as np

import serial

ser = serial.Serial(

print (ser.isOpen())

data = np.zeros(64)

app = QtGui.QApplication([])

p = pg.plot()
p.setLabel('bottom', 'Index', units='B')
curve = p.plot()

def update():
	global curve, data, 
	if(ser.readline() == b'*\n'):   # "*" indicates start of transmission from tiva c
		for h in range(63):
				data[h] = int(ser.readline())  #get 64 bytes from tiva c and plot them
		app.processEvents()  ## force complete redraw for every plot
timer = QtCore.QTimer()

## Start Qt event loop unless running in interactive mode.
if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):

Displaying Inkscape images on the LEGO NXT brick with LeJOS

If you are new to using inkscape then maybe check out their tutorial page to get started drawing basic shapes.

This is what it looks like when you open up inkscape:

The default page size when Inkscape is started up is a4. To make our lives easier, we can change the page size to match the screen size on the lego NXT brick. The bricks LCD is 100×64 (100 pixels wide, 64 high). To change the page size click File > Document Properties. This will open up a new window. Under the ‘page’ tab enter the custom width and height as shown below. Check to make sure that the units are px and not something else like mm.

Now the page should look something like this:

Everything is now set up to start drawing so fill the page with whatever you want! Hopefully it’s better than what I did :

Before exporting the picture there is an important step to ensure that the image displays correctly on the NXT brick. The background colour of the image looks white but it is actually undefined or blank. This will cause it to be displayed as black on the NXT brick resulting in just a black square being displayed. To make the background white click File > Document Properties and once again a window will pop up. Under the page tab, click the rectangle beside “Background Colour” and under the RGB tab, make sure all values are 255.

We are now ready to export the image as a PNG file. To do this click File > Export PNG Image. To display this image on the NXT using lejos we first have to convert it to a format it can work with. Lejos comes with a tool called nxjimage. This is a little gui that will let you import an image and export it in the proper lejos format. The nxjimage tool can be found in the lejos installation directory in the bin folder.

This is what the nxjimage gui looks like:

To import the png file created in Inkscape click Image > Import Image. Then navigate to wherever you saved the file.
The export the file in the native lejos format click Image > Export LeJOS NXT Image File

Now to upload the image to the NXT brick. This can be done in terminal presuming you have lejos added to your path.
The following command can be used to upload the image. (the image name is test.lni)

nxjupload test.lni

Now all that’s needed is a LeJOS program that will run on the NXT and display the image file we just transferred. See below for some example code:

//lejos program to display images stored on nxt brick
//will display image until button is pressed
//wattnotions 31/5/2015

import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import lejos.nxt.*;

import lejos.nxt.Button;


public class GraphicsSample {
	final int DELAY = 4000;
	Graphics g = new Graphics();
	final int SW = LCD.SCREEN_WIDTH;
	final int SH = LCD.SCREEN_HEIGHT;
	void fileImage(String picname) throws Exception
        Image img = Image.createImage(new FileInputStream(new File(picname)));
        g.drawRegion(img, 0, 0, SW, SH, Sprite.TRANS_NONE, SW / 2, SH / 2, Graphics.HCENTER | Graphics.VCENTER);

	public static void main(String[] args) throws Exception {
		GraphicsSample sample = new GraphicsSample();

This LeJOS program can be compiled using this command:


to upload it to the NXT:

nxj -r GraphicsSample

The Result:


Bonus Pics:





sure electronics LED dot matrix HT1632c Energia example

32x8 LED dot matrix display

32×8 LED dot matrix display

This LED array has been sitting in my room for months now so I decided to hook it up to an msp430g2553 and get it displaying stuff. I bought it from ebay from a chinese supplier called sure electronics. The array is controlled by a ht1632c led matrix driver chip and the interface required is clocked serial data which I wrote in software for the msp430. There are arduino libraries out there for interfacing with this driver chip and I used them as a reference when putting this together. Right now all I have working is initialising the driver chip and writing data to its ram to display various patterns. The leds are mapped directly to the ht1632c ram. i.e. if you write a ‘1’ to a certain memory address that led will come on and writing a ‘0’ will turn it off. The chip has some other cool features like 16 level PWM dimming also. Only 4 wires (plus Vcc and GND) are needed to interface with the led array. The four wires are DATA, WR(clock), CS (this pin is pulsed to switch between read,write and command modes on the ht1632c) and the RD pin which is the data out from the ht1632c. This data out could be the contents of the RAM so you could find out which leds are on. I didn’t use this pin at all so it’s really only 3 wires which is pretty handy. These LED array boards can be chained together up to a max of 4. Right now I only have one so the code written is meant to just control one chip. That being said it shouldn’t be too much hassle to get it working with several boards at once.

Here is the code I wrote using the Energia IDE :

If you connect the LED array using the same pins I’ve defined for DATA, WR and CS it should work right away displaying the twitter logo scrolling across the screen. Here is a picture of it displaying a speaker of some type:

led array displaying speaker

led array displaying speaker

If you’re interested in displaying text then check out this really extensive arduino library for the ht1632c.