It's the Simple Things

Arduino is an opensource electronic platform providing convenient access to a chip/microcontroller (MCU).It also comes with an IDE and a language to program the chip and gets access to its input ouput.

What is a microcontroleur ?

It's a small and low cost computer on a chip that execute one task at the time.

What is a GPIO ?

GPIO = general purpose input ouput pin.In Input mode you can read 1 or 0 from the pin.In Output mode you an write 1 or 0 from the pin.

Gpio are grouped on PORT.

To go deeper:

Usually there GPIO port are associated with 3 registers in the the MCU:

For example I could have PORTB that controls 8 GPIOs.The first 4 in Input Mode, the last 4 in Output mode.I read 0 fo the first to pin, 1 for pins 2 and 4 , and write 1 for pin 5 and 7 and 0 for pins 6 and 8.I would have my Port like:

DPR: 00001111IVR: 00000011OVR:01010000

Often address of registers are given for MCU.

My first simple and easy Arduino program:

We are going to switch on a led by pressing a button.

I need:

An Arduino

Wires

a Led

A button

a resistor

Install Arduino IDE from their website.Plug your Arduino on your computer, drivers should installs by themselves (on windows).Open the IDE and set the COM port .

Schema :

​

​

Code:

Arduino language in based on C and provide convenient method to interact with your MCU.It supports a lot of them !

The program is divided in 2 parts:void setup(), to init your pins, variables.Void loop(), to code the behavior.

You can set an Pin in Input ou Output mode with the pinMode(pinNumber) function.We are using pin 13 in Output mode ( switch on/off the light) anf pin 4 in Input mode (read the value of the button).

So lets set this two behavior:

pinMode(13, OUTPUT);pinMode(4,INPUT);

Then in the loop we are constantly reading the value of the pin 4 and depending on the return switch on or of the led.To read a input you have the method digitalRead(pinNumber). And to write a value you have the method digitalWrite(pinNumber).

You can upload the code in the board by pressing the downloading Arrow.

To go further:

We could have played directly with registers to execute this programm.Depending on the board, find the 3 port registers address of pin 13 and the one of pin 4. let's call this portA for pin 4 (port A contains pin 0 to 7) and B for pin 13 ( portB contains pin 8 to 15).