Search This Blog

Monday, June 19, 2017

Bot, my personal pet robot

It has been about a two months since I started writing to my blog again after may be 2-3 years. I wish to continue writing from now on. So, today I post about my personal pet robot, Bot.
I first started working on my personal robot about probably a year and a half ago. I wanted to make a robot which I can use for various experiments and of course I have a dream of having my own pet robot. The picture posted here is the latest revision of the robot. It has undergone three revisions due to various issues and my personal preferences.

Latest revision of Bot. Yeah,its untidy. But I still love it.

The first Bot only had an ESP8266 as a its brain. That was only used for an OpenCV experiement. Later on I bought another chassis with two wheels and encoders. But That platform turned out to be unstable and the motors were of bad quality.
Bot rev. 2.0 had a raspberry pi 2 as its brain and an Arduino UNO for more "realtime" things like controlling the motors,taking battery voltage reading and acquiring data from IMU etc. I also added a Raspberry pi NoIR camera and a dot matrix display as its face. 
Here is a video of that robot smiling when it saw a ball,
This was just a basic color based object tracking demo. After facing numerous stability issues and lack of space, I gave up that platform and finally bought the current chassis you can see in the previous photo. It has two motors built in.
This chassis is great as it doesn't overspeed and both motors rotate almost at the same rate. Now my objective was to make it go in a straight line.As this chassis had no encoder, I had to use an MPU6050 IMU.
This Intertial Measurement UNIT has a 3 axis accelerometer and a 3 axis gyroscope and is an excellent bargain for $2-$3(in my country). Now,in order to move in a straight line, the robot must keep its yaw angle constant. Now we all know that accelerometers can't measure yaw angle and gyros have a drift problem, which means they tend to drift and therefore for the same orientation, their reading changes. So I would need a magnetometer. Fortunately, MPU6050 has a built in digital motion processor which runs some sort of weird and wonderful low pass filtering algorithm that keeps the yaw angle stable enough(note this enough) even without help from a magnetometer. 
The arduino runs a simple nested if...else... to keep itself steady when going straight or steering 90 degrees. I could have used PID there, but this if else seems to be working so didnt.
Then comes another problem. This robot runs on a 7.4V 800mAh lipo battery. Battery voltage is not a constant thing.When you charge it, it goes up to a value. When you use it, the voltage drops. As a result, the minor speed tweaking of the two motors of our differential drive system doesnt work anymore and the robot canoot correct its orientation properly or turn efficiently etc.
Now this issue can be solved in many ways like taking voltage reading and adjusting calibration accordingly in the code. But I did something that is not very efficient but easy. 
I connected a boost converter followed by a buck converter between battery and motor driver. The boost converter boosts the voltage to about 9V and then the buck converter converts it to about 8 volts, at which I did my tweaks.That way the voltage remains pretty much constant but since nothing is free in our world, I lose efficiency that means my battery runs out faster but thats okay for now.
Dusty, very very dusty. On the left are the power input cables for motor driver and on the right are the battery cables 

Now let's take a look at the brain, the raspberry pi 2. It is running raspbian jessie. Its a great sbc for community support etc. but not powerful enough to do anything beyond very basic image processing. So when I work with image processing things with this robot. I usually stream video from the pi over wifi and use opencv on PC to process the stream. 
The following link contains an excellent set of instructions on how to do this.
Reducing image size or 320x240 resulted in a near instant streaming with almost zero lag,but we are using wifi dongle, so sometimes it suffers some lag.
I am working on adding autonomy but for now,I use it as a remote controlled car to test its driving performance etc. This is a very slow project as I work on it maybe once a week or month. But work is progressing and I hope it will be done someday.
I wanted to implement a ROS based control environment for this robot. So I installed ROS in raspberry pi following the instructions at ROS website.
After initializing etc. if you want to connect your pi to your PC,then change the ROS_MASTER_URI environment variable in pi to your PC ip address.
run these commands
nano ~/.bashrc
then at the end of that file. Paste the following,
export ROS_MASTER_URI="http://:11311"
then close nano by pressing Ctrl+x->y->Enter
run source ~/.bashrc
Now, you can run roscore in your pc and the pi will talk to it.  
Right now, I am working on ROS integration. will post more when its done.
My ultimate goal is to make a robot that can move between rooms and find the caller. It may also notify me about important emails and things. It has a speaker. I shall add a microphone. I added one but the audio reception was really bad.
If any of you are wondering about the laser beside the camera, I used it to implement a laser rangefinder using image processing. I shall post it soon.   

Tuesday, April 25, 2017

An attempt to make a minimal busybox rootfs with glibc dropbear and wpa_supplicant on Orange pi zero Part1

This blog post and anything that comes after this and is related to this is probably gonna be less like a tutorial and more like an attempt to keep a record of whatever I am doing/did as I have found the steps forgotten pretty much every time I tried repeating them.

Okay,lets get started. I love single board computers. I have various ones(mostly from China). I was formerly working in an R&D company and I was doing basic linux image building using various build systems there. Now,up untill a few days ago,I was quite happy with the build systems available but then I saw a wonderful video on how someone managed to boot linux with busybox in just 1 frigging second! Here is the video,  

That got me thinking, hmm ,lets try that! First I will try to create a very basic filesystem and boot and will also enable wifi. Fast booting is for later experiments.
I chose Orange pi Zero as my guinea pig as I am playing with that board now.Its a pretty nice board with an Allwinner H2 quad core processor,512MB RAM and 10/100 ethernet and wifi! It costs about $6.99 in aliexpress(mine was twice as much as I bought it from a local source).
Alright,so the first step was to boot obviously.So,I downloaded the latest u-boot source and tried to build it for orange pi zero(u-boot has defconfig for this board so I didnt have to write my own) and volla! it failed. It was a gcc issue.I am running Ubuntu 16.04 and the default gcc version is 5.4.0(same for the arm-linux-gnueabihf-gcc I used) and u-boot and linux build for Allwinner boards doesnt go well with that. 
Then after some other random attempts,I tried another weird idea. I saw this link where they ran OpenWrt on that board using kernel and u-boot from Armbian build system.

So I thought,lets try it this way first.But, my requirement is a very basic filesystem with thing that I need only.For now, that is just wifi and dropbear with scp support.Now I am using u-boot and kernel from Armbian with all the drivers(I will load whatever I want).

For doing most of the steps,a linux system is needed. You can try linux in VirtualBox or VMWare if you are in Windows. For some of the super annoying problems, even I had to switch to a 32bit ubuntu server VM image as my 64 bit Ubuntu was throwing errors during some builds.
Note: use sudo if you see permission denied.
so here are my steps.
  1. Download/build an armbian ubuntu xenial headless image(kernel 3.4.113 for now). Armbian website has very nice download page for each of the single board computers they support.The Legacy one was the choice here.I will try the mainline one too.
  2. Write that to SD card.Now you have a nice Armbian filesystem with u-boot and 3.4.113 legacy kernel.
  3. Now delete everything there except boot and lib folder. Inside lib folder, you can delete everything except modules and firmware folders.
  4. Now time for some build operations. First some prerequisites.Some of them may not even be prerequisites, but I am still including them anyway.Note that these may not contain everything you need.So if an error comes like no such file bla bla bla,feel free to google.Now,open up a terminal and type,
    sudo apt-get install build-essential gawk autoconf libncurses5-dev git libssl-dev crossbuild-essential-armhf
  5. Once we are done with that. its time to build busybox. Its a set of many useful linux tools. Some of the version selections etc might look weird but its basically a compilation of things I scavenged from the internet.
    tar -xjf busybox-1.24.1.tar.bz2
    make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- defconfig
    make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j8
    make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- install
          It then copies the files to _install folder in the busybox directory. Now we copy it to SD card. probably we could have copied it in the last command by specifying CONFIG_PREFIX.
    Now run,
    sudo rsync -a _install/ /path/to/sd/card

    This copies the contents of _install to SD card with proper permission.
  6. We are almost done on that.Now time to do some finishing touches.
    cd /path/to/sd/card
    mkdir proc sys dev etc
    sudo mknod dev/console c 5 1
    (note the missing / before dev.we are not working on our PC filesystem dont put a / before anything unless specified here)
    sudo mknod dev/null c 1 3
    Now we create the inittab file where we specify what to load during boot
    gedit etc/inittab (add sudo if says permission denied)
    copy paste the following
    null::sysinit:/bin/mount -t proc proc /proc
    null::sysinit:/bin/hostname -F /etc/hostname
    null::respawn:/sbin/getty -L ttyS0 115200 vt100
    null::shutdown:/sbin/umount -a -r
    Save and close
    mkdir root
    gedit etc/passwd

    copy paste the following
    Save and exit
    gedit etc/shadow
    copy paste
    Save and exit
    mkdir -p usr/share/udhcpc
    cp /path/to/busybox_src/examples/udhcp/simple.script usr/share/udhcpc/default.script
    gedit etc/hostname
  7. Now we make glibc which is used by various programs.
    tar -xJf glibc-2.22.tar.xz
    mkdir glibc-build
    cd glibc-build/
    ../glibc-2.22/configure arm-linux-gnueabihf --target=arm-linux-gnueabihf --build=x86_64-pc-linux-gnu --prefix= --enable-add-ons
    make install install_root=/path/to/sd/card
    If you get error like LD_LIBRARY_PATH should not contain current directory etc. during configuration, run
    then run configure again. 
  8. Now that everything is done,Open up a terminal in ur sd card folder and type sync.
Now remove the SD card and put it in your Orange pi Zero SD slot. Attach a USB-serial to it and fire up your favorite terminal emulator(picocom in my case). Power the Orange pi and you should see something like this.  
U-Boot SPL 2017.03-armbian (Mar 16 2017 - 14:23:25)
DRAM: 512 MiB
Trying to boot from MMC1

U-Boot 2017.03-armbian (Mar 16 2017 - 14:23:25 +0600) Allwinner Technology

CPU:   Allwinner H3 (SUN8I 1680)
Model: Xunlong Orange Pi Zero
DRAM:  512 MiB
*** Warning - bad CRC, using default environment

Setting up a 720x576i composite-pal console (overscan 32x20)
Error: no valid bmp image at 66000000
In:    serial
Out:   vga
Err:   vga
Net:   phy interface0
eth0: ethernet@1c30000
Hit any key to stop autoboot:  0
6944 bytes read in 159 ms (42 KiB/s)
switch to partitions #0, OK
mmc0 is current device
Scanning mmc 0:1...
Found U-Boot script /boot/boot.scr
1884 bytes read in 147 ms (11.7 KiB/s)
## Executing script at 43100000
115 bytes read in 123 ms (0 Bytes/s)
5156878 bytes read in 633 ms (7.8 MiB/s)
4754656 bytes read in 620 ms (7.3 MiB/s)
Found legacy kernel configuration
35384 bytes read in 487 ms (70.3 KiB/s)
## Loading init Ramdisk from Legacy Image at 43300000 ...
   Image Name:   uInitrd
   Image Type:   ARM Linux RAMDisk Image (gzip compressed)
   Data Size:    5156814 Bytes = 4.9 MiB
   Load Address: 00000000
   Entry Point:  00000000
   Verifying Checksum ... OK
   Loading Ramdisk to 49b15000, end 49ffffce ... OK

Starting kernel ...

[sun8i_fixup]: From boot, get meminfo:
    Start:    0x40000000
    Size:    512MB
ion_carveout reserve: 160m@0 256m@0 130m@1 200m@1
ion_reserve_select: ion chipid  [0x2c00042!
ion_reserve_common: ion reserve: [0x57e00000, 0x60000000]!
Loading, please wait...
starting version 229
Begin: Loading essential drivers ... done.
Begin: Running /scripts/init-premount ... done.
Begin: Mounting root file system ... Begin: Running /scripts/local-top ... done.
Begin: Running /scripts/local-premount ... Scanning for Btrfs filesystems
Begin: Will now check root file system ... fsck from util-linux 2.27.1
[/sbin/fsck.ext4 (1) -- /dev/mmcblk0p1] fsck.ext4 -a -C0 /dev/mmcblk0p1
/dev/mmcblk0p1: recovering journal
/dev/mmcblk0p1: clean, 4787/89584 files, 89637/358144 blocks
Begin: Running /scripts/local-bottom ... done.
Begin: Running /scripts/init-bottom ... done.
mount: mounting /run on /root/run failed: No such file or directory

testboard login: root
login[151]: root login on 'ttyS0'
~ #
Right now some errors are there and we will fix them.Right now the boot time is about 9 seconds from boot to console login.
References used:

Wednesday, September 18, 2013

So,you want to start learning microcontroller and other embedded stuffs?

Hello guys,
Well...this is a post for newbies in microcontroller world.Here,I didnt mean a complete newbie by the term "newbie".I am neither gonna talk about resistor capacitor and transistors nor what is microcontroller etc.This post is for someone who knows at least what a microcontroller is and wants to start learning it and requires a guide line on how to start. know what a microcontroller is...hmm???okay...thats cool.Now lets talk about how to start.Well...the first thing is to choose a microcontroller family.Well...I dont want to hurt the feelings of the fanboys of other families...but AVR from Atmel and PIC from Microchip are the two best families for newbies currently...its because of the gigantic number of tutorials and example projects you are gonna find online. is an excellent site for learning both these families,or the for AVR.One hint for the first site...their tutorials are kept in reverse for getting the basic tutorials...u need to go to the last page of the tutorials.
Now lets come to another very very important thing...availability of microcontroller and tools.Well...u need a microcontroller and a tool to program it.Now if you are  not confident enough to make your own programming tool or if you havent got someone who can do it for you,I recommend you buy one...for PIC,buy Pickkit2 or 3(2nd one isrecommended).If you cant buy them,look for their clones.I am giving a few links here

You can check other sources too.

For AVR,
This little programmer is really cool,but its not their official programmer...but you can use it...In fact,I use it for my work and it works just great
This is the official one.

Now...a million dollar question...which one to choose???PIC or AVR...well....u guys wont even believe that this question can trigger World war 3(u will see someday,trust me)!!!Well...I would say...go for any.See which one you can afford(Talking about tool),which one is available in your country,..or which one your friend or known ones are using(this suggestion has been given so that you might get help from them).
Now...both Microchip PIC and Atmel AVR are families,not a single microcontroller.There are hundreds of different models of PIC and AVR microcontrollers...My advice is,decide which one you are gonna use,get to the market and buy one model,any model.But onw thing you must know...for starting,choose from 8bit PIC or AVRs...For AVR,I would suggest ATmega16 or ATmega32(a good general purpose microcontroller).For PIC,go for PIC16F877...these micros are highly available AFAIK. might have heard about another thing,ARDUINO....right?????If you havent,dont try to know about it for now.If you have and your friend told you its extremely easy bla bla bla,Now,for that,I want to ask you a question,
Why do you want to learn microcontroller???Is it just for some university term project?Are you going to wipe off all you microcontroller lessons after that project???or do you want to learn microcontroller and become a professional embedded systems expert in your future life?If the first one is the reason,you can go for ARDUINO...but if the second is the reason,dont even think of getting near it for now.Its an excellent platform that uses several microcontrollers from Atmel AVR family(or Microchip PICs or ARMs in different but similar platforms).Its like a magical tool for rapid prototyping etc. and its highly tempting for newbies as well since its extremely easy to use...but sometimes shortcuts DO come with their side effects.If Arduino is your first choice for "learning", you wont even scratch the surface of this vast embedded systems world.First,learn the basics of AVR or PIC,then you will be able to use an Arduino to its limit.So, for now,forget the word Arduino.Its not for newbies who want to become professional.First learn AVR/PIC,then move to Arduino....the path wont be smooth,but at the end of it there is a huge reward.

Wednesday, June 19, 2013

Arduino...What are you??? I am again and I am going to take some of your precious time and I am gonna talk about Arduino. Well...there are many people talking about it so you guys might think its another general Arduino project talk where I am gonna show you how easy Arduino is and all that.The answer is a BIG NOOOO!!!
All I am gonna talk about here is what Arduino is and I am gonna answer to some of the common stuffs in a visual way.

Arduino IS NOT A NEW microcontroller...its merely AVR
So...this is the image of an ATmega328P sitting on an ARDUINO board.Now you believe it????If you dont,then I have got nothing to say.


Well...Arduino is a development board.I am talking about the nice blue boards u see or any other board having the name Arduino or usually any "duino".But I should say its a development platform based on AVR microcontroller...THATS ALL...


To be honest...this was my question as well when I was a newbee.But I read about things etc and came to know that the idea of such "Alien Transformation was merely a BULLSHIT".Actually ,this BOOTLOADER STUFF is nothing but a sweet small piece of program which sits in a specified place in the flash memory and its characteristics is....IT STARTS RIGHT AFTER YOU POWER UP YOUR MICROCONTROLLER AND IF THERE IS ANOTHER PROGRAM(YES...I AM NOT INSANE,BOOTLOADER AND SOME OTHER PROGRAM,BOTH CAN FUNCTION WHILE BEING IN THE SAME MICROCONTROLLER FLASH MEMORY),THAT RUNS AFTER THE EXECUITION OF BOOTLOADER. why do we need a bootloader????Well...bootloaders are capable of doing a magical thing.They can make an mcu SELF PROGRAMMABLE!!!!That means this bootloader can get data from some source in some way and put the data into the empty space of mcu's flash inshort...its capable of putting a SECOND PROGRAM into mcu program memory and THAT SECOND program is the program that you want to put into the mcu(sounds cool!!!) if we provide the mcu some way to communicate with a PC or programming source,it can program itself!!!And AVRs in arduino boards come with this bootloader thingy loaded,and the bootloader allows the micro to get program data from its UART(I guess u know what that is)!!!! so we dont need another programmer,just an usb to serial converter or a serial port on pc and any program we use to put our program into the mcu will actually communicate with the mcu via serial port!!! Thats the case of the mystical bootloader!!!


Hmm...Now I should tell you the truth....the Arduino guys were trying to create a whole new platform for rapid prototyping.They wanted to create a simple looking interface with vast amount of libraries so that it might become easy for us to do our mcu works fast.So basically what they did is,they used the same good old avr-gcc and avrlibc(WinAVR for windows people) and put some libraries over it and then they designed a simple looking IDE interface(or the Arduino Interface) and integrated everything into one folder called the arduino folder.If you browse through different folders of arduino,u will know that.

So basically general arduino boards come with an USB 2 Serial converter and the target AVR microcontroller with bootloader into it and the IDE simply communicates with the target micro via the usb2 serial converter.


If you have ever used any C/C++ compiler,then you should be aware of #define.This preprocessor command can make things easy for us in many ways....alright,before I answer to your questions,lets have a look at Arduino UNO pinmapping image:

Okay...this picture also verifies that Arduino is merely AVR...this pinmapping is for Atmega168,almost the same pinout or this pinout is applicable for Atmega328 as well....
Now...look at it...the have created a new set of pinouts by providing a few definitions over the standard AVR pinout...thats all....and those pinMode and digitalWrite functions are either functions or definitions

NOW...a question...can we use the original AVR IO PORT definitons in Arduino compiler????OF COURSE AND YES!!!!!WE CAN!!!We can use almost everything unless its not being used by some arduino library such as timer 0 and etc.


YES,YES AND YES,you can.You can use any avr compiler with arduino...All you need to know is the actual pin numbers since on ardunio board its not written.You can use the picture attached above for atmega168 and for other,simply google the name of your arduino board with the word "pinmapping" at hte end, such as "Arduino Mega 2560 pinmapping" annd you will have the pin map.

Now another can you upload the code????Well...very simple!!!Like other compiler and IDEs,Arduino software generates its hex files as well but for some weird reason,it puts that file in the temporary you dont see it.But if you have a hex file of your is how to do it

1.Download XLoader or AVRpal.NET
   XLoader link(
2.Connect you Arduino board to PC.
3.If you have downloaded XLoader,then open should look like this
The interface is your arduino board,select the COM port its connected to and then select the hex file you want to upload and then simply click "Upload"
If you have downloaded AVRpal.NET then when you open it,it should look like this

Alright...this software isnt just for arduino...its for AVR programmer USBasp as click on ArduHexLoader button...a window like this should appear

This is same as your board,the COM port and then the file and hit upload!!! you see...ARDUNIO ISNT SOMETHING COMPLETELY NEW!!!!IT'S A CONCEPT BASD ON AVR....IF YOU HAVE ANY QUESTION,FEEL FREE to LEAVE IT IN THE COMMENTS.

Saturday, March 31, 2012

Simple Fun Morse Code decoder with AVR microcontroller

Hi people...let's have some fun with AVR micros.This is my first post on any hardware project based on microcontroller except programmer or programming hardware.It's just a fun project but can also be useful to those who practice morse code...Well by this time u know what that thing's a simple morse code decoder with one button,ATmega16(not overkill,kind of superkill for anything like this,but at that time,that was easy to work with for me as I had a development board for 40pin avrs),LCD for showing output.

Unfortunately,that circuit is a history now so I cant post any image of it(Sorry folks).But I will post the schematic and a video I uploaded then to youtube(Though the video quality is...better see for yourselves).
Okay let's come to the point.Many of you know what morse code's an old system of electrical communication where messages are sent as a combination of Dash(long duration beeps or current flow) and dots(shot beeps or current flow).This was used in morse telegraph communications systems.The morse code chart is given below for interested people from wikipedia:

Though I didnt follow the timing issues then,only used the codes.

Now,why this old stuff using new things right???Well,answer is simple...mainly for fun and some skill testing also :) .
Here goes my schematic:

Circuit is pretty simple...just one button for taking input.

I had to add some extra things for displaying to LCD and clearing the LCD etc. such as a 7sec delay after entering the code to show the result on LCD.

The source code was written in Bascom AVR.Its a pretty cool compiler and easy to work with and awesome for string handling and code optimization.The source code is not BIG so It is posted here.


'8th pin of PORTA used for input

$regfile = "m16def.dat"

$crystal = 8000000

$lib "lcd4busy.lib"
'defining LCD pins
Const _lcdport = Portb
Const _lcdddr = Ddrb
Const _lcdin = Pinb
Const _lcd_e = 2
Const _lcd_rw = 1
Const _lcd_rs = 0
Dim A As Integer 'the delay counter
Dim Bttn_pressed As Integer 'variable to check if the button has been pressed before when released
Dim Mrsc As String * 32 'string for holding the morse code input
Dim Strf As String * 32 'string for holding the processed output
Dim X As Integer 'LCD upper line character position

Mrsc = ""
Strf = ""
Ddra = 0
Cursor Off
X = 1
If Pina.7 = 1 Then
A = A + 1
Bttn_pressed = 1
Waitms 500
Elseif Pina.7 = 0 Then
If Bttn_pressed = 1 Then
If A = 1 Then
A = 0
Bttn_pressed = 0
End If
If A > 1 And A < 3 Then
Locate 1 , X
Lcd "."
Mrsc = Mrsc + "."
A = 0
'Waitms 10
Bttn_pressed = 0
X = X + 1
Elseif A >= 3 And A < 6 Then
Locate 1 , X
Lcd "_"
Mrsc = Mrsc + "_"
A = 0
Bttn_pressed = 0
X = X + 1
'Waitms 10

Elseif A >= 6 And A < 12 Then
Select Case Mrsc
Case "._"
Strf = Strf + "A"
Case "_..."
Strf = Strf + "B"
Case "_._."
Strf = Strf + "C"
Case "_.."
Strf = Strf + "D"
Case "."
Strf = Strf + "E"
Case ".._."
Strf = Strf + "F"
Case "__."
Strf = Strf + "G"
Case "...."
Strf = Strf + "H"
Case ".."
Strf = Strf + "I"
Case ".___"
Strf = Strf + "J"
Case "_._"
Strf = Strf + "K"
Case "._.."
Strf = Strf + "L"
Case "__"
Strf = Strf + "M"
Case "_."
Strf = Strf + "N"
Case "___"
Strf = Strf + "O"
Case ".__."
Strf = Strf + "P"
Case "__._"
Strf = Strf + "Q"
Case "._."
Strf = Strf + "R"
Case "..."
Strf = Strf + "S"
Case "_"
Strf = Strf + "T"
Case ".._"
Strf = Strf + "U"
Case "..._"
Strf = Strf + "V"
Case ".__"
Strf = Strf + "W"
Case "_.._"
Strf = Strf + "X"
Case "_.__"
Strf = Strf + "Y"
Case "__.."
Strf = Strf + "Z"
Case "____"
Strf = Strf + " "
End Select
Lcd Strf
Mrsc = ""
A = 0
X = 1
Bttn_pressed = 0

Elseif A >= 15 Then
Bttn_pressed = 0
Mrsc = ""
Strf = ""
A = 0
X = 1
End If
End If
End If

Code has been commented so It should be easy to understand...

Here is the (Sorry again for quality)

If you need some information...tell me.Have fun!!!

Monday, January 30, 2012


An easy to use avrdude GUI for Windows platform

CEMSTech AVRpal.NET is a very easy to use avrdude GUI.NOw,avrdude is a very popular programmer application for AVR microcontroller mainly because its cross platform and its small in size but it has one major drawback...ITS COMM
AND LINE!!!!(well...I hate typing commands).So I decided to go for making an avrdude GUI.Now,avrdude is the "dude" of AVRs so I named my app. "AVRpal"(:D :D)...Now many of you will try to shoot me as I havent added any support for parallel,serial programmers and NOT even for USBtinyISP...IT only supports USBasp...its because
I had only USBasp and this works great,may be popular than USBtinyISP(Dont blame me if I am wrong guys).So,as I built this app. for me at first,I couldn't so didn't add any support for other programming hardwares but avrdude supports a lot.Now I did one thing for you,I made it OPEN SOURCE!!!If you can code in VB.NET,just download the code from here and enjoy!!!
Now...a screenshot of this app:

Now you can see that the interface looks funny...well it was made so intentionally(I didn't provide support for many programmers,so at least I hope this is gonna save me from getting beaten up by embedded people(well...I hope so)).So guys,go to and download the binary from here.

Now this application requires a modified firmware for USBasp to enable the slow sck control feature from the application window.I will upload the modified firmware soon.


Sunday, April 18, 2010

Softwares needed

Hmm...this is the part where we will know which softwares are to be used for uC coding,simulation and programming.Well...the architecture of uC and your PC is different and so you can't use your computer compiler softwares to program your uC.Well...there are several compilers for programming avr like avr-gcc,bascom avr etc.they support the coding architecture of PC(For instance,avr-gcc is a c code compiler for avr uCs) but compiled output is different.But you can configure your programming editor(Hope you know the editor you use to write the code and the compiler you use to compile your code is different) with this uC compilers.Well,uCs can also be programmed with assembly language(a low level language) in which you can directly access memory addresses etc. but it's not as user friendly as a mid level language like c or high level language like basic(bascom avr).In this tutorial we will use avr-gcc as our compiler(for assembly,there is a good tutorial here).
Here is the list of softwares.First I am giving you the list for Windows OS,then Linux(Ubuntu,other distributions should also be compatible).

Softwares for windows:

1.AVR Studio:
This is a very good software and a complete IDE for avr uCs by Atmel with built in assembler(assembly compiler).You can also use it to compile C(if you have WinAVR installed) codes.It has a simulator in which you can run your codes to see if they are bug free.You can even program your uC right through this IDE if you have a AVR Studio compatible programmer(List of programmers can be found in it's menu) .This great software is absolutely free and requires only a free registration.The link is here.
Visit the link and download "AVR Studio 4.18"(requires a free registration) then download the service pack(SP2 or SP3).Install AVR Studio 4.18 first then the service pack(because service pack is not the complete software,just an update).Check "install USB driver"(When shown).

2.WinAVR: A collection of compiler and all the files you need(some you don't).A software for programming uC(avrdude) is integrated with it(This is highly necessary if you are using USBasp as programmer).Can be downloaded from here.(That's a open source one,so you can modify it if you want).An integrated editor(Programmer's Notepad) can be used as a code editor for avr-gcc.
N.B. :- It may show some errors if you are using windows vista or 7 (64 bit version). To fix it,you need to patch winavr.The patch can be found here.Download it and follow the instructions(May be you need to replace a file given there as patch).Recent releases of WinAVR should be free from this problems.If not...then write to me.

Proteus VSM:A simply awesome software for simulating circuit you want to make(means you can just draw the circuit in it's workspace and run the circuit in you PC virtually).This software supports a lot of avr uCs and you can just add the compiled file there.You can even design PCBs for your circuits here.Unfortunately...this is not a free software and too much costly(>$2000 or $3000).There are many cracked versions available online.Search them(I can't give it's link here...the admin guys may shut my blog up!).

Well...there are other IDE's available...such as Eclipse.To know how to use it with winavr,click here.

Ponyprog:You can use this one if you are planning to build a parallel/serial programmer stated in the previous chapter.This is a very handy tool and can be downloaded from here.

AVR-Burn-O-Mat:AVRdude is a command line software(aahh...I hate command typing).This is a GUI(Graphical User Interface) for avrdude(means you give command to avrdude via this software by simply clicking things,REMEMBER,this is not an alternative to avrdude,just a GUI for it).Link is here.

Well...I am writing a GUI for avrdude.You will get it soon!It's is not as versatile as Burn-O-Mat but a simple one to use.

Softwares for Linux:

Hmm...the OS with ever growing popularity.Here is the list of softwares for it.

avr-libc,avrdude,uisp : there is no collection like WinAVR available for Linux.In ubuntu,you will get them in your Synaptic Package Manager(Preference menu).Download them and this manager software will automatically mark necessary extra apps needed before download.After downloading,they will be installed automatically.

Kontrollerlab:A very good IDE for Linux.You can even add any avrdude compatible programmer in it.That means it can even be used to program your uC.Link is here.
Download the compatible package from the link.This is the one I am using in my Ubuntu OS.

Eclipse can be used as a IDE for Linux too.

Installing Driver for programmer(Only if you are using USBasp):Hmm...something else I still need to to install the driver for the latest zip archive from then extract it.When you insert the USB cable of your USBasp hardware,a "Found New Hardware Box appears"(If you have already written the firmware into Atmega8 of USBasp and your connections are alright).There you show the "bin/win-driver" folder of your extracted USBasp folder.Then the setup will automatically locate driver for USBasp.
Now,time to test the hardware.Go to command prompt and type "avrdude -c usbasp -p m16" or replace the "m16" with "m8" or "m32" if you are using them as target uC.(No need to worry,I'll explain that!).Most probably,you will see "avrdude: error: could not find USB device "USBasp" with vid=0x16c0 pid=0x5dc".Well, this is because of the version difference between the driver given with avrdude and the one you installed.If you're lucky and you have set everything up,you should see an ok message.Otherwise,if you haven't connected the target uC or if there is any connection error in the connection between the uC and USBasp (Or in the power connection of target uC) and the driver version is perfect then you should see "target doesn't answer" message.If you haven't connected the target uC,then you can jump saying "yeppi,my USB device works!" or if you have,then you can say to yourself,"No problem...just to fix the target uC USBasp is alright!".
Now,if you have got an error message like "could not find USBasp",then unplug the hardware and reconnect it.If this does't work,copy the libusb0.dll & libusb.sys file to "WinAVR/bin" directory.A message will appear saying that these files already exist...but just press yes.Now test it,you should see a positive result.If not,then check your USBasp for connection errors.

Saturday, April 17, 2010

Hardwares needed we are preparing for our voyage to uC world!This tutorial is about the hardwares or precisely programming hardware you need to insert the program into your avr chip.Well... what about other parts you need to make project circuits or your own circuits,right? will get their values in schematics of projects and when you are making a project of your own...that's up to you!
First we need to build a power supply for our uC.uCs are mostly operated with +5V.This should be regulated(specially when you are using timing or communication features or ADC etc. because voltage ripples can cause incorrect data outputs).
This is the Schematic of the power supply for uC.This is actually not a full power supply.It's just the voltage regulator part.Build it according to schematic and don't forget to use a heatsink with 7805 IC(It may get terribly hot when used for a long time)
N.B. :- There are two ground pins in your uC,connect both of them to your circuit ground.
Parts list(picture is fair as schematics , not for seeing parts list):
  1. IC-7805(see Datasheet for pin config)
  2. Capacitor-220uF,16V(others voltage ratings will work)
  3. Resistor-1k
  4. LED
  5. Power connector
  6. Switch
Now let's come to program the uC.avr uCs can be programmed in two ways:
  1. Parallel programming(don't mistake,it doesn't mean programming with parallel port of pc)
  2. Programming through SPI bus(this is what we will discuss,because this the way of in system programming.For informations on parallel programming,see datasheet)
In system programming hardware:Well...there are several programming hardwares for that.We will give schematics of the most popular hardwares.Some of them are commercially available(STK500,AVRISP mk II etc.).If you can afford them...then buy one(But we advise you to have the experience of building one of these hardwares)Here are the schematics:
1.Parallel port programmer:If you have an old PC(Old is gold!),then this one can be the starting programmer for you.There are several parallel port programmers.This one was tested by us.Schematic:
N.B. : SCK,MOSI,MISO are the pins of SPI bus of your uC.Find their pin number from Datasheet(same applicable for RESET)In this circuit, a buffer IC has been used(74HC125).You may be thinking about the strange connection pattern of this circuit(You should be,if not experienced).Don't worry, that circuit is easy.But you need parallel port diagram to make this.Ok,here is it:This is the female side of the DB25 Connector Cable used here.You can directly connect the circuit without using the cable but I recommend you shouldn't(You may get some shocks due to earthing).
The Whole circuit can be built on a breadboard(including the power supply).
After building it,we shall use a program Ponyprog to send the program from PC.(will be discussed in the next chapter)
2.Serial port programmerI haven't seriously tested this one but many use it(may be!).It's a bit complex than the first one.
N.B. : This one is not supported by USB 2 Serial Converters
Here is the Schematic:Here,Serial port config is already given.So I haven't shown it.
N.B. : I don't guarantee if it works but since I know,this is a popular one.
USB programmer: we are getting modern.Well...the programmers stated above are backdated as serial and parallel ports are not available in today's PCs or Laptops(However,if you have an old one,you can still build them...after a will know why I said "Old is gold")To do something with USB port,Hardware driver is needed and to let the PC know what kind of hardware is connected to USB,some id codes and high/low operations are needed.That's why,in almost every USB device,there is a microcontroller or dedicated USB controller chip. Now you may have felt why I said "Old is Gold",because to make a USB programmer,you need a USB controller Chip or uC as driver in which you need to write the hardware program(firmware).Here is a diagram on how USB programmers work.
To know why we need to do that for USB,search google with the following keyword "USB in a nutshell".This is a very good book on USB.
Luckily , if you have an old PC/Laptop,you can make any of the first two programmers(they don't require a uC or controller chip to program your uC) and to be modern,you may use them temporarily to write the driver program(also called firmware) to your USB programmer's driver uC and forget them.Here is the Schematic of one of the most popular(may be the most) USB programmer(that I use at present),USBasp by Thomas Fischl( looks horrible may be but quite easy to make.Here,as driver uC an Atmega48 has been used.But you can also use Atmega8(Even others if you understand the firmware code).This programmer requires a driver.It's available at the website stated above the schematic.
To build this, you need to know the usb pin know this,visit this site.
N.B. :- Some connections are not very necessary in this circuit.For example...the connection between pin 1 and pin 16(self programing) is for firmware upgrading and not important so it can be deducted from the circuit(But NOT THE ONE FROM PIN 16 TO x2).Connections from pin 2 and 3 to X2 are also not important(keep them if you want).X2 is a connector.You can simply use serial rail to make this one(this would be better if you want to keep your uC circuit on breadboard).This circuit can be built on breadboard but I recommend you build it on a veroboard or PCB.PCB Layouts are available at the site stated above schematic.
Some useful pics: My USBasp board The ISP connector of the board(just serial rail....X2 in the schematic)
These pins are connected to Atmega8's MOSI,MISO,SCK,pin 16 and ground....
Others are unnecessary

One thing to tell you about this circuit is that if you are planning to build a PCB in which you will put your target uC to program,then keep the VCCINT(the target uC will be powered by USB).Otherwise,for ISP operation,deduct it.

Getting Started with avr microcontroller

Well...time to stop this history lecture and come to the point.We are using atmel avr microcontroller.Many of you may ask why we are using this one.Well...actually I have already answered it but missed one point.Atmel guys write their datasheets very well and they are easy to understand(Datasheet is the documentation of the device you are using...means pin configs,register descriptions etc.).
Atmega16 is an 8bit avr microcontroller with 16k in system programmable flash.Well...after all these almost non-technical stuffs,the aforesaid one is like instantly changing speed from as slow as a cycle to as fast as a bullet train!!!Well, avr is a computer architecture developed by Atmel.It's a modified harvard architecture system.8bit means the register size(a temporary memory where data can be stored,exchanged etc.) is limited to 8bits and more precisely...the arithmetic logic unit(CPU) can process 8bit data at a time(maximum).Register is like a set of memory blocks.Each of them can store one bit(0 or 1).So each register of avr should have 8blocks for 8bits.There are some 10bit,16bit registers too,but they are actually collections of several 8bit registers(We shall see them in datasheet).
Now...what is that "in system programmable flash" thing?Well...flash is a non-volatile memory and in avr microcontroller(and in many others),this is the memory where the program you have written is kept."In system" means you can program the microcontroller even after installing it in your circuit.That's a great thing because you don't need to remove uC from circuit to program it.You just power your circuit and connect your programming hardware to it and just send the program from your PC or Laptop!
Now...I have stated something new here what I haven't stated before:"Programming Hardware".Well...Since the beginning of this tutorial I have been saying that uC can be "programmed".But how?You can't just load the program into a pendrive and then insert it into uC!You need a circuit that will work as an interfacing medium between the uC and your PC.This is the programming hardware.There are many kinds of programming hardwares available for avr(We will discuss it soon).
Besides, you also need a software that will use the hardware to send the program to uC.Well...we will discuss it too!
Now...let's come to datasheet.I said you need it to know about the uC you are using.Seeing it you can know the features of your uC,pin config, internal devices and how to access them through your code etc.A very good video on accessing the datasheet is about to be published(It's on atmega8 but you can easily get the main theme).Well...let's move to our next chapter.

Friday, April 16, 2010

How to select a perfect microcontroller for your work

Well...after having a basic knowledge of uCs (microcontroller) , we move to an essential part...there are many uC models and manufacturers....which uC should we select for our work,right?'s a bit like choosing other electronic components.For example, for timing pulse operation,we select NE555 IC , not CD4017.Like this, we will select our uC according to what we want to do with it....means what integrated facilities it must have to meet our demands.Cost is also a big factor if you want to go commercial.If your desired work can be done with a $1 uC,then it is impractical to choose a $5 uC for that.Size can also be a big factor.two uCs can be of same price but different size and sometimes you may have to choose the smaller one to make your circuit compact.
Well...internal facilities or hardwares play the main role so this factor has the first priority in case of choosing a suitable uC.Like,for your work , you need an analog to digital converter or a higher clock rate or built in USB hardware(this stuffs will be discussed don't get scared seeing them) etc. etc. etc. There are some uCs that may meet all your demands...means you may use one like them in every application but they may be costly so you have to choose cheaper , specially dedicated uCs("dedicated" doesnt mean these uCs can only do a single job,they can do other jobs but are "specialized" for doing that single job).
A good example is this we are explaining every basic thing of we have to choose a uC in which every general hardware is present(means the common hardwares found in most of the uCs).So we are using Atmega16.There is another reason behind choosing this one.This is a general purpose uC and...almost all the tools you need(software,circuit schematics) to work is free(except hardware) and AVR microcontrollers are good to be used in novice level.

What is microcontroller and why it is used

We live in electronics age.Electronic stuffs are all around us and doing a lot of works for us every day...every moment.Many of them are quite smart and complex too.For example,let's take a look at a very familiar phone!They are like small computers and have so many functionalities. Of course these matter how complex... are built with many know what logic is...simply visit this link. make this logic gates "electronically",there are many logic gate IC's available or you may make them using simple equipments like relays,transistors etc.You can do this when you are building a very simple circuit. But...what about complex ones...huh?Like your mobile phone?there you need to control the LCD,display various informations on it...that requires very complex logic operation,let alone controlling other thing such as network communication,phone book,internet ,application...bla bla bla.Well,if u want to make a phone without microcontroller, then the size would be as big as a truck(!!!!!!!!!!!!!) and to add a new function,you will have to change the entire circuit.Well...there is one thing that will stand with you to face such challenges...microcontroller. Image : Atmega16 Microcontroller (We will use it)
Microcontroller is a small computer in a single chip.I mean,it has almost everything a computer consists of...CPU,RAM,Non- Volatile memory like Hard disk(not actually like that,in a solid state form without any rotating parts).Like a computer you can program it and through it's I/O pins,you can send command or take datas for processing.And logics can be programmed,so you don't need a truck size board now(Yeppi!) .So, your circuits can now be extremely small...highly customizable...and very easy...and secure.Now where is this security stuff coming from...right? want to sell a complex (with many logics) circuit you have built with great labour.You sell it...and someone buys it and copies it and...sells it at a lower price..because he has just copied he can cut the extra cost you added for research(ohhhh)...but if that was a microcontroller based could just "lock" the microcontroller code and sell it and...that copier guy cannot make your circuit because he doesn't have your code to run the circuit(Now do that...copier).So it makes your work easy and safe too.
Now...where can we find microcontrollers?Well...they are everywhere,mobile phone,washing machine,microwave oven,television,printer,photocopier,modem,toys(aaahhh)...and many other.
So,we can say that...they have become a part of our life

Sunday, March 14, 2010

Atmel microcontroller tutorial - Index

hi guys.I am Shovon(M.E. BUET).I am an electronics and robotics enthusiast.I have been working with uCs for a long time and I have collected valuable infos and willing to share 'em. I am writing a tutorial on uC(Microcontroller).The uC I'm gonna use is Atmel Atmega16(8,32 will be ok).Well,let's keep this mumbo jumbos short...and move to the tutorial
N.B. :-For descriptions...see other blog posts
Here is the complete index:
Atmel uC tutorial
  1. 8 bit timer
  2. 16 bit timer
  3. Project - a clock
  4. Special application - the PWM
  • Analog to digital converter - the magical connector between analog and digital world!!
  1. ADC description
  2. Some Coding
  3. Project - voltimeter
  • LCD Display...your monitor for uC Computer!!
  1. Overview
  2. LCD pin configuration
  3. Now... some coding
  4. Project...LCD Clock!!
  • Make your uC remember things even when it's turned off - the EEPROM
  1. Overview
  2. Registers
  3. Some Coding
  4. Project...Alarm Clock
  • Tick...Tick...Tick...tititi...Time to communicate with your pc...the USART
  1. Overview
  2. Serial Communication Basic
  3. Register
  4. controlled stepper motor
  • Some other uC stuffs
  1. Serial Peripheral Interface - SPI
  2. I2C/TWI
  3. Some good tutorials on uCs