KuttyPy - Connect to the outside world using Python

     Computer programmers and hobbyists at times come across situations where they need to switch a light bulb, rotate a motor or measure a temperature under software control. Generally these things are done by connecting some extra hardware to the computer and coding it in C language. KuttyPy is a USB interfaced board that gives you an option to do those things in pure Python.
       Playing with LEDs, motors, switches etc. is the primary objective of this hardware, but the experience gained in manipulating the 32 Input/Output pins of this board will gradually make you familiar with the ATMega32 micro-controller. That is only the secondary objective for a "kutty" (means child in some languages).
The hardware, firmware and software resources are HERE.

The board provides 32 terminals that are organized in to 4 groups, each having 8 terminals, namely A, B,C and D.  The individual terminals are marked as PA0 -- PA7 for port A, PB0 -- PB7 for port B etc. They can be controlled/monitored as a group or as individual pins.

For more details on the hardware click HERE.

Example Programs

It is possible to use some GUI toolkit like PyQt to make interactive control programs. Code samples are HERE.






The simplest thing to start with is to control LEDs connected to any of the terminals. Connect an LED from PB0 to Ground with 5k resistor in series, for current limiting. The LED should blink when you run the Python program blink.py.

Let us examine the code line by line:
from kuttyPy import *
This line imports the kuttyPy module ( kuttyPy.py should be in your working directory). This module gives you  functions that can read/write the Registers of the micro-controller connected to the USB port.  This line also searches for the hardware on the available USB ports. If nothing found, the program is terminated.

setReg(DDRB,255)
DDRB is an 8bit Register that decides the direction of the terminals PB0 -- PB7. If a bit is 1, the corresponding terminal becomes an output. If it is zero, the terminal becomes an input. DDR stands for Data Direction Register. The last letter represents the port, for example DDRA decides the direction of port A.

time.sleep(1)   , for a one second wait

setReg(PORTB,255)
PORTB is an 8bit Register where you set the output level of the terminals PB0 -- PB7. If a bit is 1, the voltage at the corresponding terminal becomes HIGH, else it becomes LOW. Here we are making all the terminals HIGH, means LED conected to any of them will glow.  In a similar manner you can use PORTA, PORTC and PORTD.

setReg(PORTB, 0)
As explained above, PB0 to PB7 will be set to LOW.

Running this loop makes the LEDs connected to any of the terminals PB0 to PB7 will blink. The frequency will be decided by the delay specified in time.sleep()

More Examples
RGB LED  : Watch the video at https://www.youtube.com/watch?v=5Mh4F4Z5cv4

stepper.py  :  Rotate a stepper motor by controlling the coils from PA0 -- PA3


More examples to be added soon.

bpajith at gmail.com