Search This Blog

Powered By Blogger

Wednesday, June 19, 2013

Arduino...What are you???

Well...here 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.
SO...NUMBER 1 ... WHAT IS ARDUINO????

Answer:
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.

NOW...NUMBER 2...WHY DO WE CALL IT ARDUINO THEN?????

Answer:
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...

NOW...NUMBER 3...YOU KNOW MAN,I KNOW ITS AVR...BUT I HEARD THEY HAVE PUT SOME ALIEN STUFF LIKE BOOTLOADER  INSIDE THE CHIP...IS IT STILL LIKE NORMAL AVRs OR HAS IT BEEN TRANSFORMED BY THE MYSTICAL BOOTLOADER????

Answer:
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.
Alright....so 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 memory...so 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!!!)...so 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!!!

ALRIGHT...NUMBER 3...OK I GET IT...THEN WHY DID THEY MAKE THE WHOLE NEW COMPILER/IDE FOR ARDUINO????WHY ALL THESE TROUBLES?THEY COULD HAVE CREATED JUST A LOADER PROGRAM RIGHT?????

Answer:
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.

OKAY...OKAY....NUMBER 4...YOU SAID THAT WE BASICALLY USE WINAVR....AM I RIGHT????WELL...I DONT RECALL WRITING ANY pinMode() FUNCTION OR digitalWrite() FUNCTION IN WINAVR COMPILER AND MOREOVER,THE PIN NUMBERS ARE COMPLETELY DIFFERENT?HOW DO YOU EXPLAIN THAT....MHMMM???

Answer:
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.


NOW.....the BIG BURNING QUESTION.....CAN I USE ANY COMPILER WITH ARDUINO BOARD????

Answer:
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 thing...how 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 folder.so you dont see it.But if you have a hex file of your program....here is how to do it


1.Download XLoader or AVRpal.NET
   XLoader link(http://russemotto.com/xloader/)
2.Connect you Arduino board to PC.
3.If you have downloaded XLoader,then open it...it should look like this
The interface is straightforward...select 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 well...so click on ArduHexLoader button...a window like this should appear


This is same as XLoader...select your board,the COM port and then the file and hit upload!!!

So...now 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.