Category Archives: HW/SW project

Raspberry Pi Project 1: Bitcoin value ticker

With the recent explosion of the Bitcoin value, I decided to do to build a display with the current value shown in Dollar and Euros.

The Bitcoin Exchange MtGox offers an API to get the current value (And much more). One line of python is sufficient to get the last value in Dollar or Euros (borrowed from here):

 euro = float(json.loads(urllib2.urlopen('').read())['return']['last']['value'])

Now we need to get it on the screen. I noticed a directory “python_games” on the Raspberry: a collection of simple games that appeared to use  pygame, a really easy to use SDL based module mainly intended to write games. This makes it possible to create a full screen application without the need of an X Server and more complicated graphical toolkits.

So, all I need to do is create a scheduler which triggers the retrieval of the BTC value, format string and blit them on the screen.

Finally, I added a line to /etc/rc.local, so the application starts automatically after booting:

python /home/pi/btctracker/ &> /dev/null &

The Result


The decision to use python and pygames was definitely right for this application. Any other tool I could think of would have taken me much more time and lines of code.

Is it useful? It definitely triggered some interesting discussions on Bitcoins and it current valuation. Shops accepting Bitcoins could use the ticker to display the current exchange rate, but in for that use case I would add the possibility to pay (camera to scan the wallet QR, numeric keypad to enter the amount).

Small Raspberry Pi projects

Another batch of raspberies arrived yesterday. Why have one RPi when you can have two? The new one has a transparant housing this time. Nice and nerdy.

I have many ideas already, but an idea is nothing without execution. So I have decided to do couple of small Raspberry Pi projects in the coming weeks.

The idea is really to get something up an running as soon as possible (MVP in hipster speak) which means:

  • Quick and Dirty (TM) coding
  • Copy/borrow as much code from my or other’s project (and
  • Only the main functionality, no nice to have features

Stay tuned for the first project!

LED G-force meter project

G-Force Meter Project

The aim is to build a meter which measures the lateral acceleration force in car, also called g-force or centrifugal force. This is the force which pushes the driver or passenger to the left in a fast right hand turn. The force is normally expressed in g, 1 g (9.8 m/s/s) corresponds to the acceleration due to gravity.
A normal car can handle approximately 0.8 g, above this values, the tires cannot handle the sideways force anymore and the car will move sideways. The best sports cars can handle up to approximately 1 g. A very interesting discussion on the forces in a car can be found here.

The idea

The g-force will be measured with an accelerometer mounted with its sensitive axis perpendicular to the driving direction. The sensor will be read out using a microcontroller. 30 LEDs are used to indicate the current g-force.

I have chosen the Atmel ATtiny26 microcontroller. It has some interesting features for this project:

  • small and cheap
  • 10 bit ADC
  • sufficient IO pins, which can source and sink 20mA; LEDs can be driven directly
  • Possibility to use the internal oscillator, no Crystal needed
  • Free development tools (C compiler) available for windows, Linux, OS X etc.
  • Programming can be done using inexpensive hardware and free programming software

To measure the G-force, I use the Analog Devices ADXL103. This is a high accuracy accelerometer, which is not really necessary for this project. The ADXL311 seems pin compatible to the ADXL103 and is cheaper. Furthermore, I designed the board such that also a Freescale accelerometer can be used (not tested).


The board

This is version 2 of the board made using Eagle, the first version had the option to use a Freescale accelerometer also, but I needed the space for the logo :-):

top  bottom

The following parts are can be seen:

  • The 30 LED array. Because I do not have 30 IO pins available on the ATtiny26, I decided to create 6 groups of 5 LEDs. 6 pins are needed to indicate the group, and 5 to indicate which LED in the group should be turned on (I hope you get the idea).  Extra bonus: only 5 resistors are needed. As a result only 1 LED can be turned on at the same time. This is not a real problem; The impression of multiple burning LEDs can be given by turning them on sequentially quickly.
  • Voltage regulator, needed because I want to run the meter from a car battery.
  • 10 pin header for In System Programming

Of course the board could be improved with a proper ground plane etc., but this is the first board that I ever made. Also a very good accuracy is not needed.

Part list:

  • ADXL103
  • ATtiny26
  • 3x 10 LED bar
  • 4x 0.1uF Ceramic Capcitor
  • 5x 360 Ohm Resistor (exact value not so important)
  • 10uF Capacitor.
  • 5x double male header (for ISP)
  • Voltage regulator regultor 7805, this size is probably an overkill

Building is straightforward. All parts are through hole components except for the accelerometer, but soldering it is not a real problem. Even I could do it with my huge (relatively) iron.

The eagle brd file can be found here

The Software

The software for the ATtiny26 was written in C and is rather straightforward. There is a lookup table which indicate the needed values of P1 and P2 to light one of the 30 LEDs. In the main loop the ADC is read out and the value is converted to a LED number. LED 1 corresponds to 1 g to the left, LED 30 to 1 g to the right. The maximum and minimum LEDs are remembered and also lit.

The hex file can be found here

The result


This is Version 1 of the board (without Hack A Day logo). The middle LED indicates the current G-force, the left and right the maximum values to the left and right.
In the car, the G-force meter functioned well. You do not need to keep an eye on the meter all the time because the maximum values are kept. It is a lot of fun, trying to improve the maximum values.

Possible improvements:

  • Reduction of noise due to vibrations by filtering the ADC output over a longer time (in software).
  • Reset button to reset the maximum values.
  • Non-linear scaling. The first part of the scale is not so important. Maybe it is interesting to let the first 5 LEDs cover the first 0.5 g, the next 10 LEDs from 0.5 till 1 g.


  • This design, or a similar design with more LEDS could be used as a Spoke POV. The accelerometer can detect the orientation of the wheel.