Difference between revisions of "Arduino/C3/AVR-GCC-programming-through-Arduino/English"
(Created page with " {| style="border-spacing:0;" | style="background-color:#c0c0c0;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| '''Vi...") |
Nancyvarkey (Talk | contribs) |
||
Line 15: | Line 15: | ||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| In this tutorial, we will learn to: | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| In this tutorial, we will learn to: | ||
− | * Interface a''' seven segment display''' to''' Arduino''' | + | * Interface a''' seven segment display''' to''' Arduino board'''. |
* Write an''' AVR-GCC''' program to display a digit on '''seven segment display '''and | * Write an''' AVR-GCC''' program to display a digit on '''seven segment display '''and | ||
* Display digits 0 to 9 on the '''seven segment display.''' | * Display digits 0 to 9 on the '''seven segment display.''' | ||
Line 43: | Line 43: | ||
AVR -GCC | AVR -GCC | ||
− | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| * '''GCC '''stands for''' GNU Compiler Collection.''' | + | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| |
+ | * '''GCC '''stands for''' GNU Compiler Collection.''' | ||
* It is a '''compiler''' which supports various programming languages. | * It is a '''compiler''' which supports various programming languages. | ||
* '''AVR-GCC '''is a part of '''GCC''' and supports compiling '''C programs''' for '''AVR microcontrollers.''' | * '''AVR-GCC '''is a part of '''GCC''' and supports compiling '''C programs''' for '''AVR microcontrollers.''' | ||
Line 73: | Line 74: | ||
|- | |- | ||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| | ||
− | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Refer the pin mapping for '''Arduino''' and '''microcontroller'''. | + | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Refer the '''pin mapping''' for '''Arduino''' and '''microcontroller'''. |
|- | |- | ||
Line 94: | Line 95: | ||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Slide: '''Software Setup''' | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Slide: '''Software Setup''' | ||
− | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| * We need to install '''AVR-GCC assembler''' and a '''AVR-LIBC library'''. | + | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| |
+ | * We need to install '''AVR-GCC assembler''' and a '''AVR-LIBC library'''. | ||
* '''AVR-GCC''' will generate a '''hex''' file and upload it to '''Arduino board'''. | * '''AVR-GCC''' will generate a '''hex''' file and upload it to '''Arduino board'''. | ||
Line 110: | Line 112: | ||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Type, | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Type, | ||
− | '''sudo space apt hyphen get space install space avr | + | '''sudo space apt hyphen get space install space avr hyphen libc space gcc hyphen avr ''' |
And press '''Enter'''. | And press '''Enter'''. | ||
Line 130: | Line 132: | ||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| We can see that the installation has been completed successfully. | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| We can see that the installation has been completed successfully. | ||
− | Let me clear the terminal. | + | Let me clear the '''terminal'''. |
|- | |- | ||
Line 142: | Line 144: | ||
'''ls space forwardslash dev forwardslash ttyACM asterisk''' | '''ls space forwardslash dev forwardslash ttyACM asterisk''' | ||
− | and press | + | and press '''Enter'''. |
|- | |- | ||
Line 159: | Line 161: | ||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Download the file '''Makefile '''from the '''Code files''' link of this tutorial. | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Download the file '''Makefile '''from the '''Code files''' link of this tutorial. | ||
− | '''Makefile''' enables us to create a ''' | + | '''Makefile''' enables us to create a ''' dot hex''' file and upload it to '''Arduino'''. |
Save the '''Makefile''' in the folder where you will be saving the '''C''' program. | Save the '''Makefile''' in the folder where you will be saving the '''C''' program. | ||
Line 178: | Line 180: | ||
<nowiki>#include <util/delay.h> </nowiki> | <nowiki>#include <util/delay.h> </nowiki> | ||
− | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| | + | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| We have to include the '''libraries''' required for our program. |
− | '''avr | + | '''avr slash io dot h''' contains all the basic '''libraries''' required to perform the input and output operations. |
− | '''util | + | '''util slash delay dot h''' contains the '''libraries''' for the '''delay function.''' |
|- | |- | ||
Line 218: | Line 220: | ||
Sending 1 to '''PB5''' turns '''off''' the '''LED'''. | Sending 1 to '''PB5''' turns '''off''' the '''LED'''. | ||
− | These two steps | + | These two steps will run in an infinite '''while loop''' making the '''LED''' blink. |
|- | |- | ||
Line 228: | Line 230: | ||
|- | |- | ||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Save the file | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Save the file | ||
− | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| I’ll save the code as '''dot hyphen blink | + | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| I’ll save the code as '''dot hyphen blink dot c''' in the '''Downloads''' folder. |
|- | |- | ||
Line 237: | Line 239: | ||
> cd /home/spoken/Downloads | > cd /home/spoken/Downloads | ||
− | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Go to the '''Downloads''' folder where '''dot hyphen blink | + | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Go to the '''Downloads''' folder where '''dot hyphen blink dot c '''file is saved. |
|- | |- | ||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| > make FNAME = onoff | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| > make FNAME = onoff | ||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Type, '''make space FNAMEin capital <nowiki>=dot </nowiki>hyphen blink '''and press '''Enter'''. | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Type, '''make space FNAMEin capital <nowiki>=dot </nowiki>hyphen blink '''and press '''Enter'''. | ||
− | This '''command''' creates a ''' | + | This '''command''' creates a ''' dot hex''' file and uploads it to the '''Arduino'''. |
|- | |- | ||
Line 316: | Line 318: | ||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| | ||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Switch back to the '''terminal'''. | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Switch back to the '''terminal'''. | ||
+ | |||
+ | Clear the '''terminal''' now. | ||
|- | |- | ||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| | ||
− | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Type | + | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Type '''make space FNAME''' in capital '''equals two''' and press '''Enter'''. |
|- | |- | ||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Point to the output | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Point to the output | ||
− | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Now you can see that | + | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Now you can see that the digit two in the '''seven segment''' is glowing. |
|- | |- | ||
Line 514: | Line 518: | ||
|- | |- | ||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| | ||
− | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Switch back to the '''terminal'''. | + | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Switch back to the '''terminal''' and clear it. |
|- | |- | ||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| | ||
− | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Type | + | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| Type '''make space FNAME''' in capital '''equals counter''' and press '''Enter'''. |
|- | |- | ||
Line 556: | Line 560: | ||
Spoken Tutorial workshops | Spoken Tutorial workshops | ||
− | | style="background-color:#ffffff;border-top:1pt solid #000001;border-bottom:0.75pt solid #000001;border-left:1pt solid #000001;border-right:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| The''' Spoken Tutorial Project''' Team | + | | style="background-color:#ffffff;border-top:1pt solid #000001;border-bottom:0.75pt solid #000001;border-left:1pt solid #000001;border-right:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| The''' Spoken Tutorial Project''' Team conducts workshops and gives certificates. |
− | + | ||
− | + | ||
For more details, please write to us. | For more details, please write to us. | ||
Line 582: | Line 584: | ||
| style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| This tutorial has been contributed by FOSSEE and Spoken Tutorial Project, '''IIT Bombay'''. | | style="background-color:#ffffff;border:1pt solid #000001;padding-top:0cm;padding-bottom:0cm;padding-left:0.071cm;padding-right:0.191cm;"| This tutorial has been contributed by FOSSEE and Spoken Tutorial Project, '''IIT Bombay'''. | ||
− | This is | + | This is Priya from IIT Bombay. |
− | Thanks for | + | Thanks for joining. |
|} | |} |
Revision as of 09:27, 9 April 2018
Visual Cue | Narration |
Slide 1: | Welcome to the Spoken Tutorial on AVR-GCC programming through Arduino. |
Slide 2:
Learning objectives |
In this tutorial, we will learn to:
|
Slide 3:
Pre-requisites |
To follow this tutorial, you should have basic knowledge of :
|
Slide 4:
System Requirement |
To record this tutorial, I am using:
|
Slide:5
AVR -GCC |
|
Slide 5:
External Devices |
We also require some external devices such as:
|
Show the image: ssd.png
Seven-segment display |
|
Show the image: | In this experiment we will be using the common anode seven-segment display.
Please refer to the basic level tutorials of this series to know more about Seven segment display. |
Refer the pin mapping for Arduino and microcontroller. | |
Show the circuit connection(image) | Do the circuit connection as shown here.
The Dot pin of the Seven Segment Display is connected to the pin 13 of the Arduino. Any one of the common pins is connected to the +5V through a resistor. |
Show the real connection | This is the live setup of the connection. |
Point to the Dot in the diagram | Now we will write an AVR-GCC program to blink the Dot LED on the seven segment display. |
Slide: Software Setup |
|
Press Ctrl + Alt + T keys | Open the terminal by pressing Ctrl + Alt + T keys together. |
Type
> sudo apt-get install avr-libc gcc-avr |
Type,
sudo space apt hyphen get space install space avr hyphen libc space gcc hyphen avr And press Enter. |
Enter the administrative password if prompted and press Enter. | |
Press ‘Y’ | We can see the installation process has begun.
Press 'Y' wherever there is a prompt during installation to confirm the configuration. Installation will take some time to complete depending upon the internet speed. |
Point to the prompt | We can see that the installation has been completed successfully.
Let me clear the terminal. |
Now let us connect the Arduino board to the computer. | |
Installing AVRA | To check the port number of Arduino, I'll type
ls space forwardslash dev forwardslash ttyACM asterisk and press Enter. |
Highlight ttyACM0 | We can see the output as shown.
Here ttyACM0 represents the port number of Arduino. You may get a different port number. Make a note of your port number. |
Slide 6:
Make file for ATmega328P |
Download the file Makefile from the Code files link of this tutorial.
Makefile enables us to create a dot hex file and upload it to Arduino. Save the Makefile in the folder where you will be saving the C program. |
Let us write the avr-gcc program to blink the Dot LED and upload it to the microcontroller. | |
Open text editor | Open any text editor and type the following. |
Highlight according to narration:
// include library files #include <avr/io.h> #include <util/delay.h> |
We have to include the libraries required for our program.
avr slash io dot h contains all the basic libraries required to perform the input and output operations. util slash delay dot h contains the libraries for the delay function. |
// Turns LED on and off
int main (void) { DDRB |= ((1 << DDB5)); while(1) { PORTB = ((0 << PB5)); _delay_ms (1000L); PORTB = ((1 << PB5)); _delay_ms (1000L); } return 0; } |
Arduino board has an LED at PB5.
Set PB5, that is pin 13 of Arduino as output. Sending 0 to PB5 turns on the LED. Sending 1 to PB5 turns off the LED. These two steps will run in an infinite while loop making the LED blink. |
Textbox for the narration | Source code that are used in this tutorial are available in the Code Files link of this tutorial.
You can download and use it. |
Save the file | I’ll save the code as dot hyphen blink dot c in the Downloads folder. |
Switch to the terminal. | Switch to the terminal. |
Type,
> cd /home/spoken/Downloads |
Go to the Downloads folder where dot hyphen blink dot c file is saved. |
> make FNAME = onoff | Type, make space FNAMEin capital =dot hyphen blink and press Enter.
This command creates a dot hex file and uploads it to the Arduino. |
Point to the output | Now, you can see that the dot LED in the seven segment is blinking. |
Next, we will display digit 2 on the seven segment display. | |
Point to the diagram | To display '2', a,b,d,e,g segments should be high and the other LEDS should be low. |
show the connection (Two.jpg) | Pins a, b, c, d, e, f and g of the seven segment display are connected to pins 2, 3, 4, 5, 6, 7 and 8 of the Arduino respectively.
The common pin is connected to +5Volts through resistor. |
Let us see the live connection setup. | |
Let us see the source code for this program. | |
Open any text editor and type the following code. | |
Highlight according to narration:
// Prints decimal number 2 #include <avr/io.h> #include <util/delay.h> int main (void) { DDRD |= 0xFC; DDRB |= ((1 << DDB0)); |
The first two lines of the code in the main function set pins 2 to 8 as output pins. |
while(1)
{ PORTB = ((0 << PB0)); PORTD = 0b10010000; } return 0; } |
The codes inside the while loop are used to control the state of the respective LEDs.
Sending 0 will cause the LED to glow and sending 1 will turn it off. |
Save the file | Save it as two.c file. |
Switch back to the terminal.
Clear the terminal now. | |
Type make space FNAME in capital equals two and press Enter. | |
Point to the output | Now you can see that the digit two in the seven segment is glowing. |
Slide 7:
Assignment 1 |
Pause the tutorial and do the below assignment.
|
Next, we will display the numbers 0 to 9 on the Seven Segment Display. | |
Show the setup | Setup remains the same. |
Let us see the source code for this program.
Open any text editor and type the following code. | |
Highlight according to narration:
// Prints decimal numbers from 0 to 9 #include <avr/io.h> #include <util/delay.h>
int main (void) { DDRD |= 0xFC; DDRB |= ((1 << DDB0)); while(1) |
|
{
for(int i = 0; i < 10; i++) { sevenseg(i); _delay_ms (1000L); } } return 0; } |
The for loop is used to count from 0 to 9.
|
void sevenseg(int dec)
{ switch(dec) { case 0: PORTB = ((1 << 0)); PORTD = 0b00000000; break; case 1: PORTB = ((1 << 0)); PORTD = 0b11100100; break; case 2: PORTB = ((0 << 0)); PORTD = 0b10010000; break;
PORTB = ((0 << 0)); PORTD = 0b11000000; break;
PORTB = ((0 << 0)); PORTD = 0b01100100; break;
PORTB = ((0 << 0)); PORTD = 0b01001000; break;
PORTB = ((0 << 0)); PORTD = 0b00001000; break;
PORTB = ((1 << 0)); PORTD = 0b11100000; break;
PORTB = ((0 << 0)); PORTD = 0b00000000; break;
PORTB = ((0 << 0)); PORTD = 0b01000000; break; default: PORTB = ((1 << 0)); PORTD = 0b00000000; break;
} |
The sevenseg function receives an integer ranging from 0 to 9.
Based on the input, the case structure is executed. Thus displaying the digits from 0 to 9. |
Save the file | Save it as counter.c file. |
Switch back to the terminal and clear it. | |
Type make space FNAME in capital equals counter and press Enter. | |
Point to the output
|
Now we can see the digits 0 to 9 is displayed in the seven segment display. |
This brings us to the end of this tutorial. Let us summarize. | |
Slide 8:
Summary |
In this tutorial, we learnt to
|
Slide 9:
About Spoken Tutorial project |
The video at the following link summarizes the Spoken Tutorial project.
Please download and watch it. |
Slide 10:
Spoken Tutorial workshops |
The Spoken Tutorial Project Team conducts workshops and gives certificates.
For more details, please write to us. |
Slide 11:
Forum for specific questions |
Please post your timed queries in this forum. |
Slide 12:
Acknowledgement |
Spoken Tutorial project is funded by NMEICT, MHRD, Government of India.
More information on this mission is available at this link. |
This tutorial has been contributed by FOSSEE and Spoken Tutorial Project, IIT Bombay.
This is Priya from IIT Bombay. Thanks for joining. |