Arduino 101
A sprint presentation on MCUs and I/O devices
DEEC-IST | HackerSchool | NEEC | IEEE-SB
Why are we where?
2/36
How do computers communicate?
3/36
How do computers communicate?
bit: The most basic unit of computing information
Either 0
Or 1
byte: Normally the smallest addressable unit of memory in
most computing systems
It consists of 8 bits
4/36
Ohm’s Law
We are Electrical and Computer Engineers, not Computer
Scientists! We have to understand the underlying hardware too,
lets start with the basics!
5/36
Simple electronic components
6/36
Simple electronic components
7/36
But how can I make the connections?
I need to have a conductive material between my components
so they are electrically connected. . . But how?
Short Answer: ECAD and Soldering, in many shapes and
forms.
But is soldering viable for prototyping? 8/36
Breadboard?
Use a breadboard they say. . . .
9/36
Breadboard.
He now have a conductive array where we can connect cables to
prototype our circuit!
10/36
What is a Microcontroller?
Small embedded computer
Generically includes:
processor (CPU)
memory (RAM/Flash)
and I/O pins
Normally the code runs on the baremetal
Alternatively it can run a simple, deterministic OS
FreeRTOS
11/36
What are Sensors and Actuators?
Sensors: collect data from the environment
Actuators: perform actions over the environment
12/36
What are Sensors and Actuators?
These devices can communicate with the MCU through various
protocols:
General Purpose I/O (GPIO) and ADC I/O
Inter-Integrated Circuit (I²C)
Serial Peripheral Interface (SPI)
Universal Asynchronous Receiver-Transmitter (UART)
etc. . .
13/36
Some of the sensors you have. . . .
14/36
Arduino UNO
ATmega328P
Single-core 8-bit AVR microprocessor
20 MHz max frequency
2 kB of on-chip SRAM for data and instructions
23 GPIO pins
6 channel 10-bit Analog-to-Digital converter
Arduino UNO
Board that integrates a ATmega328P chip
Adds peripherals such as
Quartz Oscillator for clock signal
USB Controller
Interfaces for Power signals
15/36
Arduino UNO Pinout
16/36
Setup and Microcontroller programming
For ease of use we will be using Arduino IDE
17/36
Digital I/O - How does it work?
The information can only be in two states:
HIGH (between 5V and 3.0V)
LOW (between 1.5V and 0V)
Our information is a single binary digit - a bit!
18/36
Analog I/O - How does it work?
Question: If my ADCs have a 10-bit (binary digit) resolution,
how many states can I have?
19/36
Analog I/O - How does it work?
A bit represents one of two possible states
HIGH (0)
LOW (1)
Therefore with 10-bits:
20/36
Analog I/O - How does it work?
So our ADC acquired a continous signal and converted it into a
discrete one! This is called quantization!
21/36
Let’s build something! - Concept
Let’s build a very simple luminosity detection system
22/36
Let’s build something! - Schematic
23/36
Let’s build something! - Code
24/36
One more challenge
25/36
. . . And one more for good luck
26/36
Thank you for coming
And always remember:
27/36
Eletronic Fundamentals (Revisions)
Ohm’s Law
Kirchoff’s Voltage Law (KVL)
Kirchoff’s Current Law (KCL)
28/36
Kirchoff’s Current Law
“In loop there can be no residual Voltage”
29/36
Kirchoff’s Voltage Law
“In a node there can be no residual Current”
30/36
Common C datatypes
bool
/* A binary value -> stored in a byte*/
int
/* A signed integer value -> stored in 4 bytes*/
unsigned int
/* A signed integer value -> stored in 4 bytes*/
long int
/*A signed integer value -> stored in 8 bytes*/
float
/* A decimal value -> stored in 4 bytes*/
double
/*A decimal values -> stored in 8 bytes*/
and many, many more. . . .
31/36
Functions
int add (int arg0, int arg1){
int temp = 0;
temp = arg0 + arg1;
return temp
}
32/36
Applying C to arduino
void setup(){
/*code here runs once, at the start of our routine*/
}
void loop(){
/*code here will run until the board is reset!*/
}
33/36
Digital I/O - Code example
Digital GPIO
digitalRead(PIN);
digitalWrite(PIN, value);
34/36
Analog I/O - Code example
Analog GPIO
analogRead(PIN);
analogWrite(PIN, value);
35/36
More I/O
I²C
#include <Wire.h>
[Link](SDA_PIN, SCL_PIN);
[Link](data);
UART
HardwareSerial mySerial(2); // Use UART2
[Link](BAUD_RATE, SERIAL_8N1, RXD_PIN, TXD_PIN);
36/36