Arduino and Python

Arduino fans take a lot of flack from the “hard core” micro-controller crowd.  The main complaint is that many projects could be accomplished much more simply.  Take “blink” for example.  Why would you use and Arduino to blink an LED when you can accomplish the same with a 555 timer?  This criticism is eerily similar to complaints I’ve heard about the programming language Python.

Now, Python is a well accepted language that has proliferated into every aspect of computation form the Web, to scientific computing, to graphics to … you name it.  But this was not always the case.   I’ve experienced many eye-rolls and many doubters throughout my twelve year experience with Python.  But Python survived them all because of its massive utility.  Programmers are simply more productive with Python and the economics finally won out.  You can do more in less time with Python.

Arduino faces a similar challenge.  It is disruptive to the status quo and enables anyone with even a passing interest to get something working in electronics with no background and very little effort.  With effort, those same people can accomplish amazing things using Arduino.

To say that “Arduino is overkill” misses the point!  It is often a choice between getting something done or not.  The less time something takes, the more you can accomplish.  And, if Arduino is capable of a task then it is the fastest way to get it done (for me at least).

This brings me to à la mode.  If you have not heard, à la mode is an Arduino compatible board that mates with the Raspberry Pi single board computer.  The R. Pi is a computational powerhouse compared to the Arduino, but it lacks the analog interface to interact with the real world that Arduino has.  Better yet the Raspberry Pi à la mode combo will allow me to mix my two favorite programming languages: Python and Arduino!

I am planning to write a program for à la mode that provides an I2C interface to all of the functionality that the à la mode has to offer.  When both sides of the interface are complete, it will be very simple to read and write analog or digital pins, read the real time clock, and get GPS position (optional).

I can’t wait to get my hands on the hardware!

p.u.l.s.e. – fader control for Motorcycle parking Lamp

My brother is a Mechanical Engineer who loves his KTM Duke 200 bike. He asked me to build this circuit : for a ‘heartbeat’ lamp controller for the parking light. A Neutral Detect (ND) signal controls the lamp pulsing. When ND is HIGH, the Lamp is fully lit. When ND goes LOW, the lamp starts pulsing.

I’m not familiar with PIC microcontrollers, and didn’t want to dabble in “C” code. I’d be comfortable with an Arduino, but even the smallest ATMega seemed too big (and overkill) for this simple requirement. How about an ATTiny ? A bit of Googling, and I found this excellent resource for running the Arduino environment on the ATTiny :

Time to churn out a circuit. I selected the ATTiny45 which has 6 I/O pins, with two of them being PWM, and three Analog. The schematic and board layout (in KiCad) can be found on the wyolum code repository at Google Code. The idea was to have a board that plugs in to the existing lamp socket. The board size is about the same as a T10 lamp. A new socket is wired to the p.u.l.s.e. board which then attaches to the lamp. A third wire from the p.u.l.s.e board goes to the Neutral Detect (ND) signal in the bike. This makes the installation clean and simple.

3D render of the p.u.l.s.e. board

3D render of the p.u.l.s.e. board

3D render of the p.u.l.s.e. board

The 6 way header is ICSP for programming the ATTiny.

p.u.l.s.e boards

p.u.l.s.e. boards

p.u.l.s.e. boards

Assembled p.u.l.s.e board

Assembled p.u.l.s.e board

Assembled p.u.l.s.e board

Green wire is for ND signal. Red and Black go to a Lamp socket. The p.u.l.s.e board plugs in to the original lamp socket.

Now for the Important bits – getting Arduino to run on the ATTiny. These are the steps :

PHASE I – Get the ATTiny boards.txt files
1. Download ATtiny hardware description files for the Arduino environment from here :
2. Create a sub-folder called “


” in the Arduino sketchbook folder (find its location from preferences dialog in Arduino IDE)
3. Copy attiny folder from inside the downloaded .zip to the hardware folder. You should end up with folder structure like

Documents > Arduino > hardware > attiny

that contains the file boards.txt and another folder called variants.
4. Restart the Arduino IDE.
5. You should see ATtiny entries in the



PHASE II – Hook up the ATTiny to the Programmer (Arduino Duemilenove)
6. I used an Arduino Duemilenove board as the Programmer. There are other options (see the original post).
7. Plug the ATTiny in to a prototyping board, and link up wires between the Arduino and the ATTiny as follows :

ATTiny <-> Arduino
Pin 1, RESET <-> Digital Pin 10, SS
Pin 2, NC <-> x
Pin 3, NC <-> x
Pin 4, GND <-> GND
Pin 5, MOSI <-> Digital Pin 11, MOSI
Pin 6, MISO <-> Digital Pin 12, MISO
Pin 7, SCK <-> Digital Pin 13, SCK
Pin 8, VCC <-> 5V

8. Load


sketch in to the Arduino IDE. This sketch can be found under the examples menu.
9. For ARDUINO 1.0, find the line in the

heartbeat() function

which says


and change it to


10. Download this modified ArduinoISP sketch to the Arduino Duemilenove board.
11. Connect a 10uF, 16V electrolytic capacitor on the Arduino Board, between the RESET and GND pins. [+] of cap. goes to RESET and [-] of cap. goes to GND.

PHASE III – Change Fuses on ATtiny and burn Arduino Bootloader
12. ATtiny runs at 1MHz by default, out of the box. To make it compatible with Arduino IDE, it needs to run at 8MHz.
13. Select the 8MHz option for your selected ATtiny chip (“ATtiny45, internal 8MHz” in my case) from the


14. Select


15. Select


16. That’s it – done. You can now load Arduino sketches in to the ATtiny, using the same connections that you have already set up.
17. For the ATtiny45, the Port definitions are as follows :

ATtiny45 Pin No <-> Arduino Pin No
Pin 1, <-> PB5
Pin 2, <-> Pin 3, Analog Input 3 (PB3)
Pin 3, <-> Pin 2, Analog Input 2 (PB2)
Pin 4, <-> GND
Pin 5, <-> Pin 0, PWM (PB0)
Pin 6, <-> Pin 1, PWM (PB1)
Pin 7, <-> Pin 2, Analog Input 1 (PB2)
Pin 8, <-> VCC

For the other ATtiny chips, the table will be different. Check the ATtiny datasheet for details.

18. After Bootloader is burnt to the ATtiny, you can load the BLINK sketch to verify if it all works well. Change Pin 13 to Pin 0 before uploading the sketch, and you should get the blinking LED between PB 0 and GND of ATtiny (Pins 5 and 4)

Connections between Duemilenove Board and p.u.l.s.e for burning bootloader and downloading sketches (note the 10uF capacitor between RESET and GND of Duemilenove)

Connections - Duemilenove to ATtiny

Connections – Duemilenove to ATtiny

Video of p.u.l.s.e

Another video after installation in the Bike

Introducing Carduino BatMon – the arduino for your car

I recently purchased a car black box camera that records HD video and audio as you drive  along with a built-in GPS and accelerometer.  This model also has a parking mode that stays active while your car is parked.  Any motion in front of the car or vibrations trigger the event to be recorded.  Because I live on a narrow street it is only a matter of time till someone comes along and takes off my side mirror and this camera is meant to catch the incident on video.

Unfortuantely, a camera that is active while parked can drain the car’s battery leaving you stranded.  I wanted a device that would continiously monitor the car’s battery and shut off the camera if the voltage dropped too low.  I bought this product from the local electronics shop and installed it.  Three days later my car wouldn’t start. Back to the drawing board.

Introducing Carduino BatMon – the arduino for your car.

Kevin, Anool and I have been working on a little Arduino compatible board that can monitor two voltages (through a precision resister voltage divider) and shut off a solid state relay if the voltage falls below a selectable value. There’s also an optional display board (shown here displaying the supply voltage). If you don’t want to use the display, the row of pins is a handy breakout of many of the unused Arduino pins.

+ Switch a 12V 1A load (larger loads may be switched with a larger external relay)
+ Arduino compatible
+ Power supply compatible with a noisy car electrical environment (8 to 15V)
+ Dual inputs for an always on battery voltage and an ignition switched voltage
+ Ability for the user to easily switch between various low voltage cuttoff points
+ Optional real time battery voltage display
+ Optional timer mode (Switch off load after XX hours)

Drop by the forum for more information of this project as it evolves.