Resistive touch screen based wireless mouse

Hi, after a long time I am updating my blog again. I bought few nokia color LCDs and resistive touchpad last month, all are chinese clones and very cheap. Then I thought of doing some thing with the touchpad at first. My previous blogpost  was a TV remote based computer mouse. So I decided to make a similar stuff using the touchpad and bluetooth...
         I have used a cheap ATtiny13 (8pins) microcontroller which runs at internal 9.6MHz clock. It samples two channel analog voltage from the touchpad. One of the GPIO pin is configured as a software uart TX (bit banging) which will stream the mouse data at a baudrate of 115200 (may need to calibrate by changing OCR0A little bit up or down) to a PC via bluetooth (HC_05 bluetooth module). Apart from the mouse cursor movement, I have implemented left click, right click and wheels on the same touch screen.
       A python script running on the pc will accept the mouse data and it will process the data and apply a smoothing filter to make the cursor movement more efficient. Right now I did the code for linux but will be easily portable by small modification in the python code.
        The only demerit is that we cannot do any multi-touch since it is a resistive touchpad.... Also it is not so easy to use with naked finger, instead a stylus is recommended for smooth operation. But any way in the video demo you can see its working fine with my finger........(I am using my fingernail ;-) ).....
       The bottom left part of the touchpad is configured as left click, bottom right as right click and 1 thickness from the right is for mouse wheel ...

TV remote controlled computer mouse (an avr VUSB project)

 


 Hi,
    While laying in bed and watching movies on my laptop, I used to think if there is a remote control, it will be easy to pause, play, fwd, rev, adjust volume, play next etc etc without going near to the system. Then I planned to make a remote control. I don't have a bluetooth mouse. There are many options infront of me. We can do it easily using AVR microcontroller because there is a great VUSB project :-). Using vusb library, we can implement a low speed software usb port(slave) on avr microcontroller. In the vusb library, there is an example of hid-mouse implementation in which the author used the usb report descriptor same as that observed on a logitech usb mouse. I then added few more lines of code to it to make it receive and decode RC5 signal from a philips tv remote and to send the corresponding mouse events to the system using vusb library. I believe this is the best method because it doesn't require any special driver in pc since it is a HID device. Also it works on almost all avr microcontroller(tiny, mega etc) and it doesn't require any usb to serial converter or any special hardware and it is cheaper. Also it is platform independent. It will work similar to that of a usb mouse in windows, linux & mac . I used obdev's shared VID/PID pair(0x16c0/0x5dc). The same pair is used in usbasp, so the usbasp driver should be uninstalled(if it is installed earlier) and deleted otherwise it will not work in windows.
       Hope all avr lovers have heard the famous USBASP AVR ISP programmer and most of them might have used/still using this VUSB based stuff. I then made the circuit design almost similar to that of the usbasp so that any one can try this easily on the same USBASP hardware just by replacing the atmega8 with another atmega8 programmed with the new hex from this project. Also we need to connect a TSOP 1738 IR receiver module to the USBasp hardware and need to connect it's o/p to the INT1 pin of Atmega8. Finished! Hardware is ready... Now we can plug it to usbport and use it is as an RC5-Mouse. We need a philips TV remote with RC5 protocol to test it.
       RC5 decoding is done using external interrupt and a timer. The mouse data consist of 4 bytes. The first byte is the mouse button states, the next two are dx and dy (increment in x and y coordinate, signed value) and the last byte is the wheel displacement which is also signed. We need to set the vaues of this four byte structure and then need to call a vusb function  "usbSetInterrupt" to send the mouse data to system. There is a very good vusb tutorial at codeandlife.com. Also you can check out the vusb home page.

Usage & Features:
  • 8 directional navigation of mouse pointer. (remote buttons - 2,4,6,8, 1,3,7,9)
  • Accelerated mouse movement for intelligent fast movement. ie the mouse pointer speed increases on holding the above mentioned navigation keys.
  • For fine adjusting the position, release the key and press it again step by step.
  • Left click - button 5
  • Right click - button 0
  • Mouse wheel - volume- and volume+ button

Playing video on nokia color LCD just using an 8 bit AVR! [A mad Project ;) ]

A MaD PROjECt....;-)


SD CARD + ATMEGA32 + NOKIA COLOR LCD = VIDEO PLAYER!!!
Hi,
I am introducing my new video player made using an atmega32 microcontroller and nokia color LCD. I got a 65K color LCD from an old nokia 6030 mobile phone.  I directly soldered 10 thin enamelled coper wire from the 0.5 cm square area of the thin flexible pcb of the LCD to a berg strip fixed on another board. For me it was the most difficult part of this project because I don't have any tiny tip soldering iron and an lcd connector (5x2) socket with me.
   After that I interfaced the lcd with atmega32 via SPI. Then initialized the lcd and displayed some color patterns and confirmed the LCD is working.
    Now my next step is to display a still image on the LCD. I used python image library to extract pixel information from any image file (jpeg, png etc) and I streamed it to avr via uart using pyserial and displayed the image successfully on the LCD with 16bit color depth. 
    After that I used an SD card to store the converted pixel information (132x132*2) bytes/picture. Then I interfaced the SD card with same SPI of atmega32 and displayed the image stored on it. I used FAT16 filesystem. The sd card part is not a problem for me because I have already done more projects on SD/MMC cards and I copied my previous code for that. 
    So after displaying the still image, I thought of making a slide show on the lcd. For that I wrote a python script to convert all images in a folder (on my pc) to a 132x132x2 byte files which is nothing but the uncompressed pixel information stored as new files. Then I copied all these converted files to SD card (file.lcd) and displayed them as an image slide show with 1 second time gap between each image.
    Since I successfully did the image slide show, then suddenly the idea of making a video player came to my mind. Because video is nothing but a slide show at high frame rate. 
   Then I used ffmpeg to convert a sample video to frames at 15 frames/second & 132x65 resolution. Then I used my python script to convert each still images to pixel information at 16 bit/pixel. Here instead of making small small files, I just collected all the picture information of adjacent frames into a single file and named  as my_video.lcd. Then I copied that file to memory card and modified the avr program to display it on the LCD. It access the FAT16 file system, then search for *.lcd files and if found, it returns the starting cluster address of that file and then stream that cluster to the LCD very fast. NOW VIDEO IS PLAYED (without audio)!!!!! ....Almost half of the project is finished....
Next half: (audio mixing)
       I played 15 fps 16bit/pixel on the lcd. Now comes the next headache. Video should have audio. :-(.... Then I started thinking how to include audio. I used ffmpeg(in pc) to extract audio from the video file to 8 bit mono wav. Since wav is uncompressed audio, it is easy to handle it using a microcontroller with hardware PWM. Then I modified my python script. I just opened the wav file and discarded the first 44 bytes (wav header) and then after that, I read the audio sample byte by byte and injected it in between the video information after some calculations(see the math below) related to the bit rate of both audio and video to decide the mixing ratio.
         For the perfect audio video synchronization, I implemented an error correction code in the converter, which monitors the synchronization error while mixing the audio-video bytes and when the error reaches a threshold value equivalent, it writes a dummy audio sample instead of real audio sample and thus prevents the accumulation of error and thus perfect audio video synchronization is achieved for hours of continuous video playback..
  Now in avr, i need to extract the audio and video and need to send the audio to an audio circular buffer which will be send to PWM using a timer interrupt and video directly to LCD. If any single byte mismatch occurred between the video and audio byte, every thing will get collapsed. I then modified the avr code to do as above and finally I played video with audio! :-) 

Getting started with ARM Cortex-M3 on GNU/Linux



STM32VLDiscovery is one of the three[2][3] cheap ARM Cortex-M3/M4 boards from ST. It contains an STM32F100RB microcontroller and an on-board ST-Link. Also it is designed to be powered with usb or external 3.3v or 5v. It seems to be a nice board for beginners. We can easily get started with stm32 on linux.

We need to build the toolchain for the bare metal arm ie the binary is to be executed on the arm without any linux/os. Summon-arm-toolchain is a shell script which will download the source of bintutils, gcc/gdb and two or three other packages (newlib, openocd and libopencm3) and compiles them (after applying some patches) to get executables for a "bare-metal" arm toolchain. After cloning the git repo, we need to read the README file, it says we need to install some essential packages before running the shell script. After that we just need to run the sheel "./summon-arm-toolchain" and it will do the remaining job. Finally we will get a new folder ~/sat in which we could see the library files and binary of arm-non-eabi-gcc and and many other required tools.
   Now we need a program to burn the binary to the hardware. For that we can use stlink. A simple make will generate the st-flash program...

two servo walking robot using TI launchpad


       Hi, I bought two small servo motors last month. I was thinking what I can do with this two servo, since it is only two in number. Then I asked this to my friend Achu Wilson and he suggested me to try a four legged two servo walker and he shown a youtube video in which some one demonstrating it. Then I also got interested to make some thing similar to that. Then I started designing my walker using two servo and msp430 launchpad and at last it turned out even better than I thought it would.(See the video above). The servo controlling techinque used here is a little bit different compared to the usual hardware PWM, I used a circular buffer to save each servo position and o/p pin details. Only a timer compare interrupt is used for this. This is a common technique used for controlling more servo using a cheap microcontroller with limited hardware Timer-pwm modules. Using this software pwm(not a perfect pwm, but still it will work in the servo motors) techinque, I can control more servo motors like 4,5, 6 etc etc depending on the number of I/O pins. 
     Coding for this msp430 launchpad is done in asm just because I also want to refresh the msp430 assembly language programming. I used naken430asm assembler in linux for the purpose.

Photos:

Implementing Discrete Fourier Transform in Atmega32 to make an audio spectrum analyzer


"All waveforms, no matter what you scribble or observe in the universe, are actually just the sum of simple sinusoids of different frequencies."

Hi,
I am just refreshing the basics of fourier transform. I am not an expert. Now I did a small audio spectrum analyzer(0 - 10KHz) on a 16x2 character lcd using an atmega32 microcontroller. Since I am refreshing from the basics, so I started with simple DFT. Also, I believe I should learn to walk before running. So I am not straight away going towads the FFT, which is nothing but the fastest and a bit complicated algorithm to find DFT.(I will try it later, as soon as possible)
        DFT is too slow compared to FFT. My lcd spectum analyzer doesn't need a great speed like that of an FFT, now if it is capable of providing a speed of around 30 frame/second, then it is more than enough for visualizing the audio spectrum on an LCD. But any way, in my case I can roughly achieve around 100 frames/second(any way it is too high refresh rate for a 16x2 lcd, not recommended also :-)). My audio sampling rate is 20KHz for 32 point DFT. Since the transform result is symmetric, I need to use only the first half, ie the first 16 results. So, it means, it can display upto 10KHz spectrum. So the resolution is 10KHz/16 = 625Hz.
         I have tried to improve the speed of DFT computation. If it is an N point DFT, it needs to find (N^2)/2 sin and cos values. For a 32 point DFT, it needs to find 512 sine and cosine. Before finding the sine and cosine, we need to find the angle(degree) which takes some processor time, so I implemented a lookup table for that. Next two tables are for sine and cosine. I didn't used any float or double since it takes more processing time in 8 bit avr, instead I implemented the sine and cosine lookups as 16bit intiger, by multiplying the real sine and cosine values by 10000. Then after finding the transform, finally I need to divide each result by 10000. This eliminates the need of using float or double and makes it more faster. Now I can calculate 120  32-point DFT operation/sec which is more than enough for my small spectrum analyzer.

Generating AUDIO ECHO using Atmega32 microcontroller


(video demo of echo generation using atmega32)
Introduction:
Hi,
While I was studying at 10th standard, I used to play with small electronic circuits mostly based on transistor bc547 - bc557 pair. At that time, I just asked myself, I can amplify audio signals using few transistor combinations, but how can I make an echo effect which I used to hear in almost all loudspeaker announcements? I can't imagine what I can do with few transistors and resistors to make such an effect! I have no answer at that time because it was beyond my limitation..
  But now I can do this very easily by a simple digital signal processing using a microcontroller. It's concept is very simple, ie we need to apply a proper delayed feedback in digital samples with in a circular buffer. I did this using an atmega32 microcontroller and it worked fine. This is simple but really an interesting project. Not only an echo, but we can do a lot of fun with this type of small DSP experiments if we have considerably large RAM in the mcu...

An attempt to mount an SD/MMC connected at parallel port of PC (a linux device driver)

Introduction:

Hi, for the last few days, I was engaged on a mad project, ie I was trying to access as SD card directly via parallel port of my desktop PC with linux. At first, I successfully did the SD/MMC initialization and tested it by reading and writing few sectors. Later I got a simple demo block driver code (kernel module) from net. Then I modified it and used my SD card code along with it and made a driver for the parallel port - SD/MMC card. Then after connecting the card to parallel port and inserting the module, a new device file is generated (/dev/sbd). After that I successfully mounted it and accessed it similar to that of a usb pendrive or any other external memory device. I have tested it with 64MB MMC, 512MB SD and a 1GB MMC and all worked fine.. But the only drawback is the speed of data transfer is around 200kbps only..:-( It takes 1 minute for transferring 1.5MB file to or from the card. Also the entire system may get hanged while the data is transferring...
But any way, it worked, that's enough for me..... :-)

Running PYTHON (pymite-09) on an Arduino MEGA 2560

Hi, I got a new toy from farnell. It is an Arduino mega 2560 board
in.element14.com/atmel


 

Now it is the first time I am using an arduino board. Arduino mega 2560 is really a great product. The chip got a flash of 256KB, RAM of 8KB and EEPROM of 4KB. Also, the data sheet of Atmega2560 says that we can extend the RAM (by external) upto 64KB. Another most important feature of this stuff is that it have 54 Digital I/O pins (of which 14 provide PWM output). It is clocked with a 16MHz crystal osc. Also the board contains another atmega16 (just above the crystal) which is pre-programmed as a USB to UART converter which enables a serial communitation between the atmega2560 and  PC via USB. The product is shipped with a bootloader inside which make it easy to program it via the same USB-UART channel. So the channel got two functions, ie programming the chip and serial communication with PC. From the arduino home page we can download the arduino IDE for appropriate OS.
      I heard arduino makes people lazy. ;-) But now I understood it is true. Because it is so easy to program an arduino using the arduino IDE. It have an arduino language (it is c++) with a great library functions those are very much user friendly and I heard people saying, "if it is arduino, any one can program it". Now I believe statement is almost right because in arduino IDE, we doesn't need to know any thing about the processor, it's registers and even its real port address also... Every thing is grouped and numbered in the board not according to the real PORTA, PORTB etc but according to it's functioning like PWM, ANALOG, DIGITAL, COMMUNICATION etc.
The arduino IDE got a lot of working examples, what we need to do is, we need to select the board first and then set the serial port and later we can open any example and then simply press 'upload'. It is ready!!!!!!!! ;-)
So no need to explain it more because it is so simple..

Running Python (pymite) on Arduino mega 2560
Appart from the arduino IDE, I would like to use the board seperately to try assembly programming and the normal C programming which I normally used to do using avr-gcc. 1 year ago I heard some one ported python for 8 bit devices but I couldn't use it since I didn't have a chip with enough RAM and flash. But since now I have this arduino mega 2560, I just downloaded pymite (p14p) and I could see a port for arduino mega there. It is nothing but the same "python" programming language written for microcontrollers. It have many limitations but still its interesting to see the python running on this 8 bit chip. I just build it for arduino mega 2560 and was successful (a small trouble was there in building, but any way it's okay).

Drawing geometric figures on a PAL TV using ATmega32 (128x64 resolution)


Photos of my TV screen:





Introduction:
    I am interested to draw lines, square, rectangle, circle etc on my TV screen. At first I was confused where to start. While thinking about it, a pencil and an eraser came to my mind. If we have a good pencil, eraser and a paper, then we can draw on it according to our own logic. If we use the pencil with compass and scale, we can draw circle, line, box etc on the paper. This is the basic idea I implemented in this small hobby project.

AVR based monochrome signal generation for a PAL TV


Introduction:
       I have learned some thing about TV in one of my B.tech semester but I forgot most of them. Now I refreshed a few basics and tried to implement a monochrome PAL TV signal generator using an AVR micrcontroller. I was using PIC earlier but later I jumped to AVR because I loves the USBASP programmer, the free avr-gcc compiler and the user friendly architecture of AVR microcontroller .Also at any time, if I feel little bit lazy, they I can try arduino also..;-)

An attempt to show grayscale images on an LED dot matrix display with software PWM

Introduction:
      This is just a time pass hobby project, I am trying to display some pictures (JPEG/PNG/BMP etc) on my 8x8 led dotmatrix display.  You can see photos of my 8x8 led dotmatrix display showing some grayscale pictures. The main thing which you may notice is that the brightness of each led depends on the picture information respective to the scaled(8x8) pixel of the original picture.
The original pictures are drawn using GIMP image editor in linux and saved as png. The scaled pictue is sent from the PC to PIC via UART.
 Any way, this will be the worst monochrome display showing pictures:-)
 
Photos: 
 Here you could see the led display showing few pictures opened in gimp editor... You could compare the pictures and observe the PWM effect on the led matrix.


Multitasking in AVR (A demo to run 7 tasks on an atmega32)

Hi,
Here I am introducing a simple task switching on an AVR as a demo... I did this just to get familiarized with the AVR assembly language programming.. Now I believe I learned it to an extent. Also I loves assembly language because it offers a great deal of power to use all of the features of the processor.

Introduction:
     Switching multiple tasks on a same CPU is the one of the major function of an operating system. What I did now is a time sharing multitasking (time multiplexing) on an AVR. Here an atmega32 is configured to use Round-Robin Multitasking. Round-Robin allows quasi-parallel execution of several tasks. Tasks are not really executed concurrently but are time-sliced (the available CPU time is divided into time slices). 
         Here, in my code below, it consist of 7 independent tasks and those are switched from one to another on a timer interrupt. 'May be' this could be considered as a simple & very very basic RTOS demo. Here I am mainly focusing on the core part ie the "task switching". 

Scheduling algorithm used: Round-robin (RR)
(one of the simplest scheduling algorithm)

Video demo:

Each led on the demo represents a task. Task1 (right most led, WHITE) is a software PWM task. All other tasks (2 to 7 from right to left) are toggling tasks. If you concentrate on a single LED, U may notice that the particular LED is toggling with a constant delay and is independent of others.

Working: 
 Here, total RAM (2KB) is divided among 7 tasks almost equally in such a way that each one get around 300 bytes of RAM space... This 300 bytes is considered

TV remote controller 160KHz High Quality Stereo MMC WAV player using ATMEGA32



(updated the complete source code + makefile + hex + asm + .out files on bitbucket repository) 
link is provided below the source code
Introduction:
This is my first AVR based hobby project and the most successful one compared to my all previous stuff. I am 100% satisfied with this work.. Few months ago, I tried to make a wav player using a PIC16F877A. It worked anyway, but the audio quality was not so good for higher sampling rate because that chip doens't have enough ram and thus I couldn't implement a good data buffer. But when I bought an atmega32 microcontroller, the first thing came to my mind is to make a good wav player...Now, I have completed my work and the audio quality is really amazing...

 NOW I can say that, my wav player IS ABLE TO PLAY 8 BIT MONO/STEREO with maximum bitrate of 1300kbps for mono and 1600kbps for stereo ... ie it can play an 8 bit mono wav of sampling frequency upto 160KHz and stereo upto 96KHz  without any noise or trouble!!!!! (at OSC 16.450MHz).

LINUX DEVICE DRIVER FOR A 16x2 LCD MODULE CONNECTED AT PARALLEL PORT

This is a small parallel port char driver for printing text on a 16x2 lcd module connected at parallel port of a PC. I did this as a part of learning linux kernel-module programming. May be this could be considered as a hello world device driver.

INTRODUCTION:

 As we know, everything in Linux is treated as a file, even hardware devices like serial ports, hard disks, and scanners. In order to access these devices, a special file called a device node has to be present. All device nodes are stored in the /dev directory. Here, my 16x2 lcd connected to parallel port is also treated as a file and is accessed via a device node....
    Now, after connecting the 16x2 lcd to parallel port (as in my circuit diagram), and then inserting the driver module, a message "DRIVER INSERTED" is displayed on the 16x2 LCD. Later, if we make a character special file (node) with major number as 61, and if we write any string to it (echo HELLO > file), then it will be displayed on the 16x2 LCD. Now, if we write a long string to it, then it is displayed on the lcd by scrolling it from bottom to top until the string is displayed completely ...



My own AVR ISP programmer using PIC16f877a and python!

Introduction: 

(don't skip to read the note below)
I recently purchased few AVR microcontrollers. I don't know much about AVR since I am using it for first time. Any way, I have some experience on working with PIC and MSP430. To program AVR using USB, I came to know that USBASP is the best and cheap choice. But any way, I thought of making my own ISP programmer (both PC software and burning hardware) for AVR using my fav PIC (PIC16f877A) microcontroller just for getting familiarised with the process of loading the binary into the AVR flash.
      From PC side, coding is done on python. In short words, the python script reads the hex file (intel hex format) and make some ascii conversion on it and then send it to the PIC16F877A line by line. Now by using some commands for isp programming, the PIC communicate with AVR and transfer the data to it via SPI. I have tested my programmer on atmega8, atmega16 and atmega32.

Note:
 I did this just for learning some thing about the burning process, please don't consider this seriously because this may have many bugs , I don't know and I didn't tested much.. Also I am not interested to continue this because it will be time wasting as there are already many cheap and efficient avr programmers available now. So please don't complain about bugs and don't use this for any important purpose ;-)


 Intel hex format:

Intel hex format is well explained in wikipedia. I learned about it from there. Here is the link towards the wikipedia page. An intel hex file contains the binary information about the flash address and data. It is a text file format. Each line of intel hex file consist of 6 parts. See below picture.

Python maps mouse movements to an led matrix display controlled by a PIC


Introduction:

This is a small "toy paint" on an LED dot matrix display which is controlled by a mouse connected to a PC... We have seen the MS PAINT in windows. This is a small 'TOY PAINT' for my small 8x10 LED dot matrix display :-) Here, using a PC mouse, I could draw and erase picture on a small 80 pixel display made by LEDs. At first I thought of making a mouse controlled robotic arm but due to lack of few mechanical parts, I just postponed that and now made this toy paint as a part of familiarizing  two python modules named pygame and pyserial. The heart of the display is a PIC16F877A micro controller. Now, from the PC side, every thing is done on python. Now, if I am using an RF module in between the PIC and USB to UART converter, I can do the same process remotely... The same idea could be applied in robotics for smooth control of activities remotely using a computer mouse...

MULTITASKING IN MSP430

Task switching is one of the main function of an operating system. We could 'feel' a computer is doing multiple tasks at a time. The OS is actually switching the tasks one by one in a circular manner and executing each one for a small period of time and we feel it is doing all tasks at a time.... 

A small demo of multitasking in MSP430G2231 microcontroller:

     Here, three independent tasks are to be switched on every timer interrupt.  The CPU registers used in previous task is to be stored some where and the register values of the task to which it is switched is to be retained as before. Also, the switched task should run from where it is paused earlier.
Below is my asm code for running three independent tasks in an MSP430G2231 microcontroller. (just a demo, stack depth is very limited due to the limited RAM)

DS89C430 development with linux (SDCC compiler and pyserial based hex loader )

I got an 8051 mini board containing DS89C430 mcu from a junk.. Then I started collecting some information about it's development in linux. I came to know that the burning of DS89C430 is very easy since it have a built in UART bootloader.. So I had written a small python code (based on pyserial) to make it more easier.....


INTRODUCTION:

The DS89C430, DS89C440, and DS89C450 offer the highest performance available in 8051-compatible microcontrollers. They feature newly designed processor cores that execute instructions up to 12 times faster than the original 8051 at the same crystal speed. Typical applications will experience a speed improvement up to 10x. At 1 million instructions per second (MIPS) per megahertz, the microcontrollers achieve 33 MIPS performance from a maximum 33MHz clock rate. Almost all programs written for the original 8051 will be working in the DS89C430, similar to that of 8051 , with improved execution speed. The reverse may not be possible because it have many extra features which is not there in the traditional 8051 microcontroller......

Bulk file name encoder using python

Python is really an interesting and user friendly scripting language. It is easy to write codes in python compared to C and some other high level languages..
     It will be much difficult to rename or encode all the file names manually to a particular pattern if the number of files in a folder are too large... For example, If we want to rename all files (for example 1000 files) in a folder to just numbers ,say, 1,2,3 etc with in seconds, this could be easily done using python.
     Below code could be used for the purpose. Also, we could easily rename it back to the original file names using the same script (just double on the rename.py).  A backup file containing the original file names is created in the same folder so that we could rename the numbered files back to its original file names at any time... The renaming to numbers and the reverse could be done just by clicking the same  "rename.py" script copied in the folder containing the files to be bulk renamed and this is very simple and easy process...