7. Embedded programming¶
This week’s tasks
Read the datasheet for the microcontroller board you are programming Program the board you have made to do something
================================================================================================================================================
ARDUINO NANO¶
Arduino Nano is a small, complete, flexible and breadboard-friendly Microcontroller board, based on ATmega328p, developed by Arduino.cc in Italy in 2008 and contains 30 male I/O headers, configured in a DIP30 style.
Arduino Nano Pinout contains 14 digital pins, 8 analog Pins, 2 Reset Pins & 6 Power Pins.
It is programmed using Arduino IDE, which can be downloaded from Arduino Official site.
Arduino Nano is simply a smaller version of Arduino UNO, thus both have almost the same functionalities.
It comes with an operating voltage of 5V, however, the input voltage can vary from 7 to 12V.
Arduino Nano’s maximum current rating is 40mA, so the load attached to its pins shouldn’t draw current more than that. Each of these Digital & Analog Pins is assigned with multiple functions but their main function is to be configured as Input/Output.
Arduino Pins are acted as Input Pins when they are interfaced with sensors, but if you are driving some load then we need to use them as an Output Pin.
Functions like pinMode() and digitalWrite() are used to control the operations of digital pins while analogRead() is used to control analog pins.
The analog pins come with a total resolution of 10-bits which measures the value from 0 to 5V.
Arduino Nano comes with a crystal oscillator of frequency 16 MHz. It is used to produce a clock of precise frequency using constant voltage.
There is one limitation of using Arduino Nano i.e. it doesn’t come with a DC power jack, which means you can not supply an external power source through a battery.
This board doesn’t use standard USB for connection with a computer, instead, it comes with Type-B Micro USB.
The tiny size and breadboard-friendly nature make this device an ideal choice for most applications where the size of the electronic components is of great concern.
Flash memory is 16KB or 32KB that all depends on the Atmega board i.e Atmega168 comes with 16KB of flash memory while Atmega328 comes with a flash memory of 32KB. Flash memory is used for storing code. The 2KB of memory out of total flash memory is used for a bootloader.
The SRAM memory of 2KB is present in Arduino Nano. Arduino Nano has an EEPROM memory of 1KB.
ARDUINO NANO DATASHEET
ARDUINO IDE¶
The Arduino Integrated Development Environment - or Arduino Software (IDE) - contains a text editor for writing code, a message area, a text console, a toolbar with buttons for common functions and a series of menus. It connects to the Arduino hardware to upload programs and communicate with them.
TinkerCad¶
Tinkercad Circuits which is more aimed towards electronic circuits and Arduino coding rather than mechanical design, while still keeping the “for-beginners” profile , using interactive circuit editor, students can explore, connect, and code virtual projects with a bottomless toolbox of simulated components.
=====================================================================================================================================================
Setting up the board¶
We started by downloading the ARDUINO IDE and the DRIVER supporting it.
To download ARDUINO IDE
To download THE DRIVER
To set up the board , I went to the tools option and selected the following
Board: Arduino Nano
Processor: ATmega328P
Port - COM5
As we can see , I did not select a port at first so it didnt upload !
==================================================================================
BLINK¶
Now we started experimenting with the software.... The first task was to use a built in example called blink
And then upload it to the Arduino by clicking on the upload option on the bar.
And here is the result
So as we can see , the given code programmed the microcontroller board to blink the led on light for 1 complete second and off for one complete second. This was a really good way to get started on how to use the board and understand how coding works......
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
====================================================================================
MORSE CODE USING ARDUINO IDE¶
So we were given a task to pre code our microcontroller to send a Morse code 1 word message . dot = 0.5 second light on. dash=1 second light on. gap between dots and dashes=0.5 second light off. gap between letters=2 second light off
I tried it out using Tinkercad circuts
I decided to go with a simple word ‘HEY’
Morse code
Here is the result
Then, I transferred the code into Arudino IDE to see how it would work on the Arduino nano
Here’s the result
void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
// H
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
// E
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
//Y
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(500);
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(500);
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(500);
}
===============================================================================
SERIAL MONITOR¶
What is the serial monitor? The serial monitor’s job is to allow you to both send messages from your computer to an Arduino board and also to receive messages from the Arduino. It can be used as a debugging tool, testing out concepts or to communicate directly with the Arduino board and that you can have multiple tabs open, each with its own Serial Monitor.
int led = 13;
int entry = 0;
void setup() {
pinMode(led, OUTPUT);
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
entry = Serial.read();
if (entry == '1') {
digitalWrite(led, HIGH);
}
else if (entry == '0') {
digitalWrite(led, LOW);
}
else {
Serial.println("done");
}
}
}
I tried it out in TinkerCad first and here’s how it went
Viola!! it worked… Now time to try it pur on the board.
I uploaded the code to the arduino using the Arduino IDE software
And as we can see, the serial monitor was able to read the data given to the board directly ♡ .