Tuesday, February 17, 2015

BASIC INPUT OUTPUT IN ARDUINO

This tutorial will focus on how to use basic arduino IDE for input & output & reading writing basic I/O  data to any pin or from any pin.

command line for an arduino program uses

void setup() function to make permanent initializations of pins.

void loop() function includes those statements that keep repeating throughout the program execution.

FOLLOWING are some basic i/o functions:
int sensor_x= A1;   
#define sensory A2;

pinMode(1, INPUT);
pinMode(3,OUTPUT);
pinMode(A0, INPUT);
pinMode(sensor_x, INPUT);
pinMode(sensory, INPUT);

All the above functions are different ways to select a single pin as input or output/ analog or digital. & are necessarily a part of Void Setup() function.
The pinMode command here is similar to
DDRX command in AVR or Port initialization command in 8051.

digitalWrite(3,HIGH);
int data_on_pin_1= digitalRead(1);
int data_Analog0=analogRead(A0);
int data_Analog1=analogRead(sensor_x);
int data_Analog2=analogRead(sensory);
analogWrite(3, 150);

Semicolons are a must. Also Its a case sensitive language so watch the keywords properly.These can be either a part of Void setup() or void loop() function depending on the nature of your application.

DigitalWrite has 2 arguments ( pin number, value)
For digitalWrite the values can be HIGH (means logic 1 ) or LOW (means logic 0).

For digitalRead values read will only be either 1 or 0.

For analogWrite, since we hv an 8bit DAC, the values can be  between 0-255.
thus the resolution becomes (5/256)
So analog voltage output at the PWM pin when you give analogWrite value 100 will be
100 * (5/256)= 1.95 volts.
value 0 will act as LOW.
& Value 255 will act as HIGH.

For analogRead, we have an inbuilt 10 bit ADC & so the values can be between 0-1023.Thus the resolution becomes(5/1024).
So analog Voltage input will be written to the integer data_analog1. if you have your sensor connected to pin 0.

See them as digitalWrite & analogWrite equivalent to PortX command in AVR.
& analogRead & digitalRead equivalent to PinX command in AVR.

we'll use these commands for manipulation in coming tutorials.

& also learn about serial communication with other Pc & making yout microcontrollers speak to each other.

If you have any questions or doubts, feel free to ask them in comments below.

-Abhirup

Sunday, February 8, 2015

Your First Java Program: Hello World




In this section, our plan is to lead you into the world of Java programming by taking you through the three basic steps required to get a simple program running. The Java system is a collection of applications not unlike any of the other applications that you are accustomed to using  browsers etc. As with any application, you need to be sure that Java is properly installed on your computer. You also need an editor (notepad , wordpad etc) and a terminal application(command prompt etc). 

Programming in Java. We break the process of programming in Java into three steps:

1. Create the program by typing it into a text editor and saving it to a file named,  say, helloworld.java.
2. Compile it by typing "javac helloworld.java" in the command prompt window.
3. Run (or execute) it by typing "java helloworld " in the command prompt window.

The first step creates the program; the second translates it into a language more suitable for machine execution (and puts the result in a file named helloworld.class);the third actually runs the program.
1.      Creating a Java program. A program is nothing more than a sequence of characters, like a sentence, a paragraph, or a poem. To create one, we need only define that sequence characters using a text editor in the same way as we do for e-mail. helloworld.java is an example program. Type these character into your text editor and save it into a file named helloworld.java.




Remember that the file name should be same as the program class name.


2.      Compiling a Java program. At first, it might seem to you as though the Java programming language is designed to be best understood by the computer. Actually, to the contrary, the language is designed to be best understood by the programmer (that's you). A compiler is an application that translates programs from the Java language to a language more suitable for executing on the computer. It takes a text file with the .java extension as input (your program) and produces a file with a .class extension (the computer-language version).


Open cmd.exe window.







Give a path to that drive where you have stored your helloprogram.java file (mine is M drive) 






Create a folder java in your drive and move the .java file in that folder and open the folder in cmd window (cd command is used to open a folder).



Now open the program file by writing “javac helloworld.java” , this will create a class file




 











3.      Executing a Java program. Once you compile your program, you can run it. This is the exciting part, where the computer follows your instructions. To run the helloworld program, type the following at the cmd window:
               “     java helloworld      ”



OUTPUT






Also feel free to ask any doubts regarding the projects.







-Manish :)

"HELLO WORLD" IN ARDUINO - LED BLINKING & WRITING / RUNNING YOUR FIRST PROGRAM

Hello & welcome to the first tutorial on ARDUINO.

This tutorial is focused on imparting basic ARDUINO knowledge to folks interested in beginning in embedded systems & robotics with the ARDUINO open-source hardware platform.

An open- source hardware platform such as arduino  is a great piece of technology to work with.
Its modules/ hardware plans/schematics as well as sample software projects are created under Creative Common License & thus it is accessible by everybody freely for their use.

Thus there has been seen a massive tsunami of Arduino boards/ shield/ many open source sensor & actuator units as well as Software projects compatible with arduino over the past few years.

Its easy to access also because its cross platform. I.e, same arduino can be programmed & used invariably on both mac OS/ linux / & Windows.



The very first post is on the "HELLO WORLD" in Arduino. The first arduino board we gonna talk about is deumilanove.

From www.arduino.cc, you can download the latest version of Arduino software deployment package. Install & open the Arduino IDE (which is a java based Integrated development environment.)

1) Basic View of the Arduino IDE.





































2) Before beginning programming with Arduino, Connect the Arduino board to your desktop & find the newly added device in the Device Manager.
Come back to Arduino & set the Board from the drop down menu, Select the Serial Port(COM Port) to which your Arduino is connected ,(find it from you MY COMPUTER->PROPERTIES->DEVICE MANAGER->COM PORT)



Select the Programmer as AVRISP mkII for onboard Programmer IC available

































Also we will cover Arduino as ISP in upcoming tutorials. It is the method used for programming an AVR on breadboard using Arduino as a burner. It can also be used for burning programs onto an Arduino AVR prototyping shield.

3)Write the following Basic Code in the Notepad & Save it in a new folder
Arduino Projects->Hello World->
void setup() {.....  } includes all the functions & initialization that remain Static During the
whole program Runtime. Eg. you only need to make a pin as input or output Once For a code.

void loop() {....... } includes all the functions & commands the keep running in Loop.
Eg. You can set the output pins "High"(logic 1) or "Low"(logic 0) anytime during the running of code. 











































Arduino is an advancement over the conventional Hierarchy of Microcontroller programming:

Hierarchy of micro-controller Programming For Freshers to Robotics & embedded:
bottom to top
Zeroth level : MACHINE LANGUAGE : As all codes are fundamentally to be converted to this level.
1)A higher level of abstraction was Intel 80xx uc programming using ASM codes
2) A higher level of abstraction was Intel 80xx uc programming using C & structured language codes.
3) A higher level of abstraction was AVR uc programming using C & ASM mixed language codes.
4) A higher level of abstraction was PIC uc programming using Mikro-C language of PIC.
5) A higher level of abstraction is ARM programming using Embedded c.
6) Arduino programming & so onn..

i.e as we go upwards from Zeroth to 6th level, the complexity in technology involved increases. & so does the no. of instructions & routines. As the no. of functions & capability increases, more time is spent of interfacing & faster computation & multitasking capacity of controllers. For which more & more inbuilt functions & command are provided to developers to ease the task of programming.

Thus as we climb higher up the hierarchy, the programming becomes easier & more stress is laid on the effective & efficient use of the inbuilt commands.

4) After successfully compiling the code, connect the board using the USB cable provided with
the board & Click the upload button to burn the sketch onto your Arduino.







































5) Here is how Duemilanove looks like. It has an Atmega 328 (with 10 bit adc input & 6 x (8bit PWM )channels) at heart with 16Mhz XTERN. clock, a reset switch, ISP programming socket. a 12 volt DC input jack. Ethernet port next to FT232 inbuilt for programming the arduino. The & 4 SMD LED's for POWER IN, HARDWARE SERIAL(RX, TX), LED (PIN 13). So all in all i'd say its a compact, development board, with inbuilt burner hardware, & voltage regulator & pin outs.

a preview of arduino deumilanove.

You could also burn a code into an avr using Arduino & later use it on breadboard for your projects.
Below shown is the basic circuit of arduino for every breadboard project


Add caption
Or you could implement it on breadboard in such a way.















Arduino is perfect for hobbyists. It also provides the ease of use as you do not require indepth knowledge of AVR FUSES & SFR's (SPECIAL FUNCTION REGISTERS). There are plenty of interesting projects provided in online arduino forums & www.arduino.cc , youtube , as well as in your arduino software package.
For inbuilt example goto File->Examples & you'll find cool ready to use examples.
Be sure to understand them & their compatibility with your arduino before burning the sketch.

The next step of this could be

  •  interfacing multiple analog/digital sensors to Arduino 
  • Programming avr using Bootloader & Arduino as ISP.
  • Programming Arduino wirelessly using Xbee.


All these will be covered in the coming tutorials.





Also feel free to ask any doubts regarding the projects.







-Abhirup :)

Saturday, February 7, 2015

"HELLO WORLD" IN AVR - LED BLINKING & WRITING / SIMULATING YOUR FIRST PROGRAM

Hello & welcome to the first tutorial on AVR

This tutorial is focused on imparting basic AVR knowledge to folks interested in beginning in embedded systems & robotics.

The very first post is on the "HELLO WORLD" in robotics (specifically AVR).
I'd suggest you kindly clear your basics of digital electronics before starting this tutorial.
Also learn to read data sheets of basic IC's such as the following:


  1. 555 timer.
  2. max232
  3. opamp 741
  4. lm35
  5. adc0804
  6. ATtiny
& our first microcontroller  ATMEGA 16.
FOR beginning the set of tutorials, we'll download "WINAVR setup" & install it onto the desktop. & open the PROGRAMMER's NOTEPAD.



1) select file->new->c/c++ file to compose your first AVR program
2) write the given program & save it at a desired location in a separate folder

3) Now find the makefile & edit it.


4) to Edit makefile, select the desired F_CPU speed (Preferably 8000000 or 16000000) & also change the TARGET FILE NAME to the name of your own progam saved with programmer's notepad. & then save the makefile using File->save as on top left of makefile. SAVE THE MAKEFILE IN THE SAME FOLDER AS YOUR PROGRAM.C . 
5) After storing your own program file & makefile in the same folder. Click on Make Clean & Make All.
check for ZERO ERRORS in the dialog box below. & proceed.
Congrats, You have compiled your first AVR PROGRAM USING PROGRAMMER'S NOTEPAD.

6) Your project Folder will appear similar to this after step 5. It will have the "program.c" file as well as makefile & the "program.hex" file. & a bunch of other files whose use we'll discuss in the coming tutorials.

& Now , moving on to our next software Proteus. Its an animated software simulation method of your circuits.
Google this Software. You'll find plenty of good download links with FULL SETUP (SOFTWARE + CRACK+ LICENSE KEY). So Download & install the setup using the "HOW TO TEXT FILE".
7)Using the part list library within Proteus. Make the connections & Construct this basic circuit. 
8) Save the design file for your ease in the same folder as your AVR project folder. I advise you make a folder for each project in the coming tutorials & save it with the title name of your project.
eg. :  LED_BLINKER_TEST folder
              > LED_BLINKER.c
              >LED_BLINKER.hex
              >LED_BLINKER.dsn
              >makefile



9)Now lets add the hex program to the Proteus circuit for software simulation. for that click
SOURCE->Add/remove source file-> & select the target processor as the microcontroller in the design. for our design we chose atmega16. & click new to select the source file . CLICK & SELECT THE .HEX FILE from the project folder & proceed.

10) Now after adding the Hex file to design. click Execute & the click on the green Play button on the bottom left to Simulate. & use pause/play/stop button as & when you require.
After following all steps properly, You'll see the Animated led glowing after a specific delay.



Next, we'll Focus On BURNING the program to a real hardware using AVRDUDE .
Open AVRDUDE GUI & make the following settings:
i.e set your controller(we are using atmega16), programmer/burner (i am using usbasb), com port(check for ComPort by looking into the device manager for New hardware. This will pop up everytime you connect a new controller/device to your pc ), high fuse & low fuse.
Select the hex file & execute.

As my device is not connected to the machine. you see the message below.

 




when you connect your device , you'll see it in the device manager.
while programming, select the same COM PORT (COM3 in this case ) while programming.





You may use a common AVR burner hardware & connect the controller on a development board or breadboard & program the controller to see the led connected to C- bit 1, blinking.








































For all of you who are yet confused about the fuses , i'll do a separate comprehensive tutorial on 
  • AVR FUSES of some common AVR controllers.
  • TIMERS /DELAYS & INTERRUPTS
  • SERIAL & PARALLEL COMMUNICATION

Also feel free to ask any doubts regarding the projects.







-Abhirup :)