August 31, 2013

Tutorial: Create a 3D Printable cube with OpenSCAD

Download, install and launch OpenSCAD.

Type "cube(10);" in the edit box to the left.

In the menu select:
Design-> Compile and Render (CGAL) or press F6

and then:
Design-> Export as .STL

Give your file a suitable name e.g." my_cube.stl"

Print the file on your 3D Printer by loading the .stl file in you printer software.

Here is a good source to learn more about OpenSCAD:

August 1, 2013

[SWE] BankID hänger webbläsaren

BankID is an electronic identification and signings system used only by Swedish banks and governmental agencies therefore this post is in Swedish.

Jag har på senare tid haft stora problem med mitt BankID som använder kortläsare. Det som händer är att webläsaren hänger sig när man ska logga in och det blir bara ett vitt fönster. Det händer både i Firefox och Internet Explorer. Det verkar oftast hända när man byter användare.

Lösningen verkar vara att stoppa den process som kör BankID. Gör så här. Stäng ner webbläsaren och öppna aktivitetshanteraren (ctrl+alt+del). Välj processer och letaupp "Personal.exe" och avsluta den. Starta sen webbläsaren på nytt och logga in.

June 13, 2013

Random numbers with Arduino

I was looking for a good random numbers function for Arduino. Here is a summary of what i found so far.

Pseudo-random algorithm

An algorithm that produce a sequence of numbers. It will generate the same sequence every time it is used. The built in Arduino library uses this method.

Sampling an unconnected analog input

The TrueRandom library used this approach. Seems to producing more 0s than 1s.

Independent Counter

The probably_random libray uses two counters with independent sources. Seems promising.

TRNG (True Random Number Generator) module

The Atmel SAM3X8E on Arduino DUE has a dedicated block for random numbers. There is a library available for this: advancedFunctions.

May 17, 2013

Electronics Home Lab

I have built my home lab inside a computer cabinet (IKEA Husar). It has a pull-out keyboard shelf that I use it as an extension of the workspace when the doors are open. My inspiration came from a friend that had built his lab in a two door closet. The main idea is to have a workspace that can be closed when not used and to be able to resume my work later. I have used this lab for nearly ten years and I am still happy with it!

In the upper part of the cabinet I keep commonly used tools and instruments. On the top shelf are two PSUs, a signal generator, assortment boxes with components, the SMD component kit and shelf trays with cables and small tools. On the lower shelves are things like multimeter, callipers and a power drill. At the bottom is the work space with a soldering station. On the left wall are screwdrivers, wrenches and pliers. To the left are cables hanging on hooks.The thing hanging under the shelf is an old radio scanner. You can also see a small vise hanging on the front of the workspace.

The lower part of the cabinet is used for storage of less commoly used things and toolboxes. To easily find what I looking for I use stackable clear plastic boxes.

When the doors are closed it blends nicely in to the rest of the apartment so that the muggles don't find it ;-)

May 7, 2013

Follow me on Twitter

I will start post my blog updates and other interesting things on twitter. My user name is @pthalin.  Follow me by clicking the Follow button to the right on top of this page.

April 26, 2013

Stop motion with Pentax K5 and Arduino

Sebastian Setz has created an Arduino library that can emulate an IR remote for a system camera. It supports all major brands. I created a sketch that takes a picture when i push a button. I used it to create a stop motion movie where it is important not to move the camera between shots. This library could also be used to make time laps shots where the camera takes pictures at a defined interval.

Below you can see my set up for the stop motion. To make a video of the jpg images i used MakeAVI.

Here is the video.

April 16, 2013

Develop for Arduino on Android - ArduinoDroid

ArduinoDroid is an Arduino development environment (IDE) for Android providing (almost) the same functionality as the computer version. Almost since not all boards and functions are supported yet. An OTG cable and Android device capable of OTG are needed to upload code to the board.

I loaded the app on my Sony Xperia V and compiled the blinker example.Then I connected the Arduino UNO and upload it without problems! A great job done by Anton Smirnov that develops this.

My set up.


April 12, 2013

Fixing slow and not responding Firefox

After the latest updates of Firefox it has started run extremely slow both at startup and when surfing. I often got "not responding" and freeze of Firefox for several seconds when loading a web page. I have also seen this on other computers. Finally I have found the magic cure. What you need to do is a reset that will rebuild your profile while keeping the most important settings (bookmarks, passwords, etc) and removing old junk.

To do the reset open the "Troubleshooting Information" window:
Windows XP: Help -> Troubleshooting Information
For later versions of Windows: Firefox > Help -> Troubleshooting Information 

Then press the Reset Firefox button.

For a detailed description see the Mozilla support here.

April 9, 2013

Arduino Pro Mini low power modification

In this post I use an Arduino Pro Mini 5V 16 MHz MEGA328 powered by an external 5 V source. My application will run on a small battery so I need to minimize the power consumption. I measured the board to consume about 16 mA in normal operation.

My application can be in sleep mode until an event occurs. This is how to enter sleep mode:

Make sure to used this include:
#include <avr/sleep.h>

Wake-up from sleep mode is done with an interrupt. That part is not covered in this post. In sleep mode I measured the current consumption to be 476 uA (microampere). To improve this is I did the following:
  1. Disabled the power on LED by removing the current limiting resistor. It got down to 152 uA.
  2. Removed the unused on board 5 Volt regulator to avoid leakage. This resulted in 136 uA.
The picture below shows the positions of the components that I have removed.

The battery that I will use is a 3.7 V 230 mAh Li-Po regulated by a TI TPS61200 Boost Converter. With an assumed efficiency of 90% I get 230 * (3.7 / 5) * 0.9 = 153 mAh. This gives the theoretical time of operation:

Sleep mode before: 476 uA => 321 h (~13days)
Sleep mode after: 136 uA => 1125 h (~46 days)
Normal operation  mode: 16 mA =>9.5 h

Conclusion: The improvement of the modification is about 3.5 times longer standby time in sleep mode. I was hoping for a month of standby time so with the improvements it should be enough for my design.

April 4, 2013

Monochrome 128x32 OLED Display

I purchased a tiny OLED display from the eBay seller that also have a webpage. The dimensions for the module is about 13x34 mm and the interface is I2C.

Here is how to get the display running with Arduino. Download and install both these adafruit libraries:

Hint: use the ZIP button on the github page to get all the files.

For installation instructions see my previous post.

Open the example ssd1306_128x32_i2c in the Arduino software. When compiling you will probably get this error mesage "ssd1306_128x32_i2c.ino:53:2: error: #error ("Height incorrect, please fix Adafruit_SSD1306.h!");"

To fix this open the newly installed library file: Adafruit_SSD1306.h
Find these lines in the file:
   #define SSD1306_128_64
//   #define SSD1306_128_32

change them to:
//   #define SSD1306_128_64
   #define SSD1306_128_32

Save the file and compile again. This time it should complete without errors.
Hint: Use CTRL+R to compile.

Connect your display to the Arduino UNO as follows:
  • ⏚ to GND
  • + to 5V
  • SDA to A4
  • SCL to A5
The library is also using pin 4 as reset. This display does not have a reset terminal so just leave it unconnected.

Upload the code to the Arduino and your display should wake up!
Hint: Use CTRL+U to Upload.

March 25, 2013

MSX emulatation on MK802

In this post i show how to install openMSX on MK802 running running a lubuntu 12.04 image from

Open a terminal and install the openmsx-catapult package by typing:

sudo apt-get install openmsx-catapult

This will install all the needed packages. openMSX Catapult is a GUI to configure and launch the openMSX emulator. Start it by typing:


Select a game ROM file under Cart A then press the Start key to start the emulation. With the default MSX type there is no need for a bios file. But for other types it will be needed. Below i have installed a bios file from Spectravide SVI-728.

If you have an USB game pad connected to your MK802 go to the Misc Controls tab and select joystic1 as Joystic port 1.
 When the emulaton is running you can enter fullscreen mode with the F12 key

March 13, 2013

Energia a port of Arduino IDE for TI MSP430

Energia is a port of the Android software for the TI MSP430 LaunchPad. My LaunchPad with a MSP430G2231 has mostly been collecting dust lately so i decided to give it a try. My first test was the provided blink a LED and serial communication examples and as expected they worked fine. So I decide to try something a little more challenging.

I installed my library from the previous post and hit compile. There was no errors but the pin assignment needed to be updated for the MSP430. I did the changes below and downloaded it to the LaunchPad.
const int loadPin  = P1_4;
const int sdataPin = P1_5;
const int sdclkPin = P1_7;

As you can see in the picture below it worked. Energia is a promising software. The latest version on the web page is a bit old but the git repository seems to be updated lately and the forum is quite active so hopefully the work will continue.

March 6, 2013

Arduino library for Osram SCDQ554xx Displays

This is a description of my Arduino library for Osram SCDQ554xx Displays. The library is available for
download here. For installation instructions see my older post Installing newping library.

The device that I have used is the SCDQ5542Q. But the following devices should also be supported:
  • SCDQ5541X (Yellow)
  • SCDQ5542X (Super-red)
  • SCDQ5543X (Green)
  • SCDQ5544X (High Efficiency Green)
The display is a tiny LED display with 4 characters with a 5x5 Dot Matrix. The device has no built-in character definition instead each dot is individually programmed to be on or off.

My libray has an example with the numbers 0-9 and decimal point defined. Other symbols can easily be added. For character sets and other details see the Data sheet. 

March 3, 2013

Review of Arduino Ethernet Shield W5100

You have probably seen the non official low cost Arduino Ethernet Shield from China or Hong Kong with the WIZnet W5100 chip that you can get for about $10. So are they any good? I ordered one to see. It arrived intact after a month packed in a solid cardboard box but without any ESD protection.The build quality seems to be good.

I loaded the WebServer example and hooked it up to my network and it worked immediately without any problems.

I also tested the SD card interface with two of the examples provided by the Arduino software. The first test was with the SD card basic file example (files).
The second test was SD listfiles example. Note that you need to edit this example to run it with the Ethernet shield since it is written for usage of pin 10 instead of pin 4. Simply search for "SD.begin(10)" and replace it with  "SD.begin(4)". Below is the result with a card from an old Android phone.
When buying the Shield it is advertised to have the MAC address: 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED (Note the hacker humor "dead beef feed") but this is not true since it set by your Arduino code. Sure this is the default value for MAC address in the examples but you can set it to whatever you like. If you have multiple devices on the same network it is probably a good idea to set it unique for each devices since the router might be confused otherwise.

+ Low cost.
+ Works with the SD and Ethernet examples in the Arduino software (Tested with 1.0.3).

- You are not supporting the creators of Arduino but the design is open source so anyone can build and sell them legally.

February 26, 2013

Arduino IR remote library

If you have an Arduino project where you need to handle remote control infrared signals you should have a look at IRremote library by Ken Shirriff. It recognizes many commonly used protocols and can also capture and send raw data for unknown protocols. Download it from his github page:

I used the provided example named IRrecord to receiving and transmitting codes with my Panasonic TV remote. It was recognized as raw and it worked well to learn codes and send it to control my TV. A clever trick to see if you transmitter is working is to use your smart phone camera. Looking at the IR led in the camera viewer enables you to see the IR light.
Here is how to wire the sensor and the IR led, the button is is used to send the last captured code.

By opening the serial terminal the captured code can be viewed. It shows the length of the mark and space in the code.

February 20, 2013

Connecting Arduino to MK802 running Lubuntu

I had an idea of combining a MK802 running Linux with an Arduino UNO to get some I/O pins controllable from the MK802. This post describes how to do serial communication over the USB cable with a terminal application and with Python.

Boot Lubuntu and login then connect the USB cable from the Arduino to the MK802 and open a LXTerminal and type:


It will print of lot of information but look at the end for lines similar to these:

[  217.500000] cdc_acm 3-1:1.0: ttyACM0: USB ACM device
[  217.510000] usbcore: registered new interface driver cdc_acm
[  217.510000] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters

This means that you Arduino is mapped on the device name ttyACM0. To open a serial terminal to this device type:

screen /dev/ttyACM0

If screen is missing install it by typing:
sudo apt-get install screen

Below I have run screen with the example "Communication -> ASCII table" from the Arduino Software. I prepared the Arduino UNO with the code on a Windows computer before  I connected it to the MK802.

The serial communication can also be done with a Python script. Create a file named with the lines below it an run it with:

import serial
ser = serial.Serial('/dev/ttyACM0')
while 1:
  while ser.inWaiting() > 0:
    print ser.readline()
It should result in a something similar to the picture below.

February 15, 2013

Installing NewPing library for Arduino

Just for fun I decided to play with an ultrasonic sensor for distance measurement and an Arduino. The sensor that i used is the HY-SRF05. The included example for Arduino is written for the Parallax PING sensor. The HY-SRF05 is a bit different from the PING in the sense that it uses two pins for communication instead of one. This is not supported by the default example. But luckily there is a good alternative. The NewPing library has many features and support the HY-SRF05. It is available for download from here:

The installation of an Arduino library is easy. Just unzip the library files in your Windows Documents folder in the folder Arduino\libraries\<LibName> as illustrated below.


The library integrates well in the Arduino Software and comes complete with examples.

The HY-SRF05 runs from 5 Volts so it is easy to use with the Arduino. The trigger pin is connected to pin 12 and echo pin to pin 11 on the Arduino. This is how it looks when it is running.
The accuracy of the sensor seems to be fairly good but I did not evaluated that throughly.

February 11, 2013

Inkscape - Editor for SVG files

Inkscape is a free and open source vector graphics editor. I have used it for editing of images for Fritzing parts with good results. You should not be fooled by the low version number. This is very capable software. If you looking for a free alternative to Adobe Illustrator this is a good candidate. Below is the SVG file for the Fritzing part for the JY-MCU Bluetooth module that I made. The SVG file is available for download from here.

February 6, 2013

Practical low cost SMD components kit

A couple of months ago I ordered an SMD components kit on ebay. I have used it for some time and I have to say I like it! It is small and has the most common values of the components. In the picture below you can see a size comparison with an Arduino UNO.

The kit is a book with resistors and capacitors in pockets with labels. It has 3025 of resistors in 63 values from 0Ω to 2MΩ and 700 capacitors in 17 values from 15pF to 1uF. The component size is 0805 (2.0x1.25mm).

Search on ebay for "Practical SMD resistor and capacitor components, assorted folder kit" The price is about $32. I am not associated with the seller of this item.

January 30, 2013

Fritzing - Veroboard and Breadboard design software

If you are looking for a free tool to create schematics and documentation for your prototypes, Fritzing may be right for you. It can also be used to created and manufacture PCBs from your design. Frtizing has three views that share and automatically update a netlist so that if a component or connection is made in one of the views it is also added in the other two. The views are called Breadboard, Schematic and PCB.

In the Breadboard view your design look and feel like physical objects. It has regular components like resistors, capacitors, inductors and ICs. It also has cables, Veroboard, Breadboard and blocks like an Arduino, sensors, servos, motors and many more.

The Schematic view is a traditional electronics schematics editor. As mentioned Fritzing has the most commonly used components and modules in the built in library but if your favorite part is missing it can easily be added. I added the JY-MCU Bluetooth module from my previous post by modifying an existing component within minutes.Download it here.

I felt that Fritzing is easy to use and learn. But it was not obvious to me how to cut the lines on a strip board. It turned out that it is quite simple, right click betweens the holes as illustrated with the arrow in the figure below.
I did not try the PCB design part at this time. Fritzing installer package are available for download from:

January 25, 2013

Bluetooth with Arduino

I recently purchased a low cost Bluetooth module with serial interface. I decided to hook it up to my Arduino.

Arduino UNO does only have one UART that is used for the USB serial terminal so it can't be used but there is a Software UART available that uses regular I/O-pins. For details see:

It works well at 9600 baud but when i tried 115200 the reception failed and received characters was corrupted. This worked in my previous test both with an FTDI cable and a Bus Priate.

The baud rate of the module can be changed by sending a AT command before connecting to the module to a Bluetooth device. The command is:


Where <index> is an hexadecimal number from 1 to C. The rates are: 1:1200, 2:2400, 3:4800, 4:9600, 5:19200, 6:38400, 7:57600, 8:115200, 9:230400, A:460800, B:921600, C:138240

WARNING: Do NOT set it higher than your device is capable of since you will need to communicate at the new rate after sending this command. I used an FTDI cable for changing back the configuration. 

The board is marked "JY-MCU BT_BOARD v1.03". The supply voltage is stated to 3.6 - 6 V on the board. But the RX and TX terminals are 3.3 Volt logic. Therefore a voltage divider as shown in the figure below is need for the TX output on the Arduino when connecting it to RX on the module. The TX on the module can be connected directly to the RX on the Arduino. I have put the two resistors on a veroboard.The values are R1=10k and R2=20k.

Below is the Arduino code I used for the tests. It transmits received Bluetooth data to the USB terminal and vice versa.

#include <SoftwareSerial.h>
const int RxPin = 10;
const int TxPin = 11;

SoftwareSerial Bluetooth(RxPin, TxPin); // RX, TX

void setup()
  // Open serial communications and wait for port to open:
  while (!Serial) {
    ; // wait for serial port to connect.
  Serial.println("Init done!");
  // set the data rate for the SoftwareSerial port

void loop() // run over and over
  int data;

  if ((data = != -1)

  if ((data = != -1)