Arduino/C3/AVR-GCC-programming-through-Arduino/English
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. |