fbpixel
The different communication protocols

The different communication protocols

Whatever your electronics, programming or home automation project, you will certainly be using a communication protocol. Whether to program the microcontroller or to communicate with a sensor. This article presents various communication protocols commonly used on Arduino, Raspberry Pi and ESP8266/ESP32.

Serial communication bus

Serial port

USB

USB (Universal Serial Bus) is a communication bus standard used to exchange data between computer peripherals. The special feature of this standard is that it allows devices to be connected while they are in operation and enables automatic recognition of the peripheral).

UART

UART (Universal Asynchronous Receiver Transmitter) is the standard that specifies how data is sent over the serial port.

RS-232

The RS-232 protocol is a communications protocol that defines connectivity and enables asynchronous, duplex communication between two devices. The special feature of this protocol is that it uses voltages from 3 to 25 V to transmit data, making it a bus less sensitive to interference and noise.

(RS232/RS422/RS485)

I2C

The I2C communication bus is a protocol for connecting several “Master” devices to several “Slave” devices, enabling up to 128 devices to communicate. It enables asynchronous connections between several components to share information via a “common bus”. This protocol is generally used for board-to-board exchanges, but can also be used over longer distances.

SPI

SPI (Serial Peripheral Interface) is a serial data bus that operates in full-duplex mode, i.e. it can transmit and receive data at the same time. It uses a Master-Slave architecture, with slave selection via a dedicated line.

CAN

The CAN (Controller Area Network) bus is a serial communication bus widely used in the automotive industry. It allows multiplexing of different devices, enabling them to communicate via the same bus. This reduces the amount and complexity of wiring.

Ethernet

Ethernet is a wired communication protocol that exchanges data in high-speed packets.

(I2S)

MIDI

MIDI (Musical Instrument Digital Interface) is a communication protocol between electronic instruments, controllers and music software. It involves sending a series of bytes to specify the type of message and associated information (note, note length, instrument, etc.).

Wireless communication protocols

Bluetooth

BLE

The BLE (Bluetooth Low Energy) network is a Bluetooth network with low energy consumption.

Wifi

ESP-NOW

A low-power communication protocol developed by Espressif using 2.4GHz waves.

RF 433MHz

RF 2.4GHz

(Zigbee)

LoRaWAN

The Lora network (Long Range Wide-area network) is a radio network that enables low-power devices to communicate at low speeds. This makes it possible to have connected objects with significant autonomy.

You now have a complete overview of the wired and wireless communication protocols most commonly used in electronics and computing.

Arduino MEGA microcontroller overview

Arduino MEGA microcontroller overview

The Arduino Mega 2560 board is an enhanced version of the Arduino UNO. It has a large memory capacity and a large number of inputs.

Microcontroller features

The Arduino MEGA microcontroller uses the ATmega2560 microprocessor, which operates at a clock frequency of 16 MHz and has 8 kB RAM, 4 kB EEPROM and 256 kB Flash memory (for programming and data storage).

  • CPU ATmega2560
  • Voltage : 5V
  • Flash : 256 kB
  • RAM : 8 kB
  • EEPROM : 4 kB
  • Clock speed : 16MHz
  • WiFi : No
  • Bluetooth : No
  • SD : No

Power supply

The Arduino MEGA microcontroller operates over a voltage range of 7-12V, thanks to its on-board voltage regulator, while the microprocessor operates at 5V. In normal operation, the microcontroller consumes up to 45mA (if no power is supplied) and can accept a maximum current of 40mA on each of its IO pins.

Pinout

  • Analog I/O : 16 (A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15)
  • Digital I/O : 38 (14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 46, 47, 48, 49, 50, 51, 52, 53)
  • Broches PWM : 17 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 44, 45, 46)
  • Communication Serial: 10 (10, 11, 12, 13, 14, 15, 50, 51, 52, 53)
  • I2C communication: 1 ((20, 21))
  • SPI communication: 1 ((53, 52, 50, 51))
  • Interrupt : 1 (2)

Summary of features

Microcontrôleur
Nom: ArduinoMEGA
Marque: Arduino
Caractéristiques
CPU: ATmega2560
Tension d’alimentation : 7-12V
Tension logic: 5V
E/S digitales: 54
Entrées analogiques: 16
Flash: 256kB
SRAM: 8kB
EEPROM: 4kB
Fréquence d’horloge: 16 MHz
Wifi: No
Bluetooth: No
SD card: No
Touch: No
UART/SPI/I2C/I2S: Yes/Yes/Yes/No

How to get started

Arduino MINI microcontroller overview

Arduino MINI microcontroller overview

The Arduino MINI board has been designed for projects where space is critical and the configuration is fixed.

Microcontroller features

The Arduino MINI microcontroller uses the ATmega328P microprocessor. This processor operates at a clock frequency of 8(3.3V ver) 16(5V ver) MHz, with 2 kB RAM, 1 kB EEPROM and 32 kB Flash memory (for programming and data storage).

  • CPU ATmega328P
  • Voltage : 5V
  • Flash : 32 kB
  • RAM : 2 kB
  • EEPROM : 1 kB
  • Clock speed : 8(3.3V ver) 16(5V ver)MHz
  • WiFi : No
  • Bluetooth : No
  • SD : No

Power supply

The Arduino MINI microcontroller operates over a voltage range of 3.35-12V (3.3V ver) or 5-12V(5V ver), thanks to its on-board voltage regulator. The microprocessor operates at 3.3 or 5V. In normal operation, the microcontroller consumes up to 45mA (if no power is supplied) and can accept a maximum current of 40mA on each of its IO pins.

Pinout

  • Analog I/O : 6 (A0, A1, A2, A3, A4, A5)
  • Digital I/O : 8 (0, 1, 2, 4, 7, 8, 12, 13)
  • PWM pins: 6 (3, 5, 6, 9, 10, 11)
  • Communication Serial: 14 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)
  • I2C communication : 1 ((‘A4’, ‘A5’))
  • SPI communication: 1 ((10, 13, 12, 11))
  • Interrupt : 1 (2)

Basic code and pin identification

To use the input/output pins in the code, simply use the labels present on the board, i.e. A0-A5 and 0-13. Pins A0, A1, A2, A3, A4 and A5 can also be replaced by 14, 15, 16, 17, 18 and 19 respectively. For your information, analog pins can also be used as digital I/Os.

const int analogPin=A0; // broches A0-A5 ou 14-19
const int digitalInPin=2; // broches 0-13 et 14-19
const int digitalOutPin=4; // broches 0-13 et 14-19
const int pwmPin=3; // broches 3 5 6 9 10 11

int analogVal=0;
int digitalState=LOW; //LOW or false or 0
int pwmVal=250;

void setup() {
  Serial.begin(9600); //broches 0(Rx) et 1(Tx)
  
  pinMode(analogPin,INPUT_PULLUP); // broches 0-13 et 14-19, Argument OUTPUT, INPUT, INPUT_PULLUP
  pinMode(digitalInPin,INPUT);
  pinMode(digitalOutPin,OUTPUT);
  pinMode(pwmPin,OUTPUT);
}

void loop() {
 analogVal=analogRead(analogPin); // broches A0-A5 ou 14-19, return int
 digitalState=digitalRead(digitalInPin); // broches 0-13 et 14-19, return boolean
 digitalWrite(digitalOutPin,HIGH); //broches 0-13 et 14-19, valeur LOW(0) ou HIGH(1)
 analogWrite(pwmPin,pwmVal);// broches 3 5 6 9 10 11, valeur 0-255
}

Summary of features

Microcontrôleur
Nom: ArduinoMINI
Marque: Arduino
Caractéristiques
CPU: ATmega328P
Tension d’alimentation : 3.35-12V (3.3V ver) or 5-12V(5V ver)
Tension logic: 3.3V ou 5V
E/S digitales: 14
Entrées analogiques: 6
Flash: 32kB
SRAM: 2kB
EEPROM: 1kB
Fréquence d’horloge: 8(3.3V ver) 16(5V ver) MHz
Wifi: No
Bluetooth: No
SD card: No
Touch: No
UART/SPI/I2C/I2S: Yes/Yes/Yes/No

How to get started

Arduino NANO microcontroller overview

Arduino NANO microcontroller overview

The Arduino NANO board is a smaller version of the Arduino UNO with similar functionality. Ideal for rapid prototyping and building embedded projects.

Microcontroller features

The Arduino NANO microcontroller uses the ATmega328 microprocessor. This processor operates at a clock frequency of 16 MHz, and has 2 kB RAM, 1 kB EEPROM and 32 kB Flash memory (for programming and data storage).

  • CPU ATmega328
  • Voltage : 5V
  • Flash : 32 kB
  • RAM : 2 kB
  • EEPROM : 1 kB
  • Clock speed : 16MHz
  • WiFi : No
  • Bluetooth : No
  • SD : No

Power supply

The Arduino NANO microcontroller operates over a voltage range of 7-12V, thanks to its on-board voltage regulator. The microprocessor operates at 5V. In normal operation, the microcontroller consumes up to 19mA (if no power is supplied) and can accept a maximum current of 40mA on each of its IO pins.

Pinout

  • Analog I/O : 8 (A0, A1, A2, A3, A4, A5, A6, A7)
  • Digital I/O : 8 (0, 1, 2, 4, 7, 8, 12, 13)
  • PWM pins: 6 (3, 5, 6, 9, 10, 11)
  • Communication Serial: 14 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)
  • I2C communication : 1 ((‘A4’, ‘A5’))
  • SPI communication: 1 ((10, 13, 12, 11))
  • Interrupt : 1 (2)

Basic code and pin identification

To use the input/output pins in the code, simply use the labels present on the board, i.e. A0-A7 and 0-13. Pins A0, A1, A2, A3, A4 and A5 can also be replaced by 14, 15, 16, 17, 18 and 19 respectively. For your information, analog pins can also be used as digital I/Os.

const int analogPin=A0; // broches A0-A7
const int digitalInPin=2; // broches 0-13 et 14-19
const int digitalOutPin=4; // broches 0-13 et 14-19
const int pwmPin=3; // broches 3 5 6 9 10 11

int analogVal=0;
int digitalState=LOW;
int pwmVal=250;

void setup() {
  Serial.begin(9600); //broches 0(Rx) et 1(Tx)
  
  pinMode(analogPin,INPUT_PULLUP); // broches 0-13 et A0-A7, Argument OUTPUT, INPUT, INPUT_PULLUP
  pinMode(digitalInPin,INPUT);
  pinMode(digitalOutPin,OUTPUT);
  pinMode(pwmPin,OUTPUT);
}

void loop() {
 analogVal=analogRead(analogPin); // broches A0-A7, return int
 digitalState=digitalRead(digitalInPin); // broches 0-13 et 14-19, return boolean
 digitalWrite(digitalOutPin,HIGH); //broches 0-13 et 14-19, valeur LOW(0) ou HIGH(1)
 analogWrite(pwmPin,pwmVal);// broches 3 5 6 9 10 11, valeur 0-255
}

Summary of features

Microcontrôleur 
Nom:Arduino NANO
Marque:Arduino
Caractéristiques 
CPU:ATmega328
Tension d’alimentation :7-12V
Tension logic:5V
E/S digitales:14
Entrées analogiques:8
Flash:32kB
SRAM:2kB
EEPROM:1kB
Fréquence d’horloge:16 MHz
Wifi:No
Bluetooth:No
SD card:No
Touch:No
UART/SPI/I2C/I2S:Yes/Yes/Yes/No

How to get started

Multitasking with Arduino

Multitasking with Arduino

Multitasking is the ability of a microcontroller to execute several tasks or processes over the same time horizon. In practice, an Arduino cannot execute tasks in parallel, but it can arrange and execute a number of tasks one after the other in a very short space of time. This gives the illusion of multitasking. In this article, we’ll look at a few examples of multitasking.

If your project requires you to run tasks in parallel (multithreading), you’ll need to consider other microcontrollers or microcomputers.

Using interrupts

Description

Interrupts enable the microcontroller to execute a function when an event occurs on one of the interrupt pins. Rather than constantly reading the value of a sensor, the program will only trigger when the sensor value changes. This solves many task layout problems.

Code

const byte interruptPin = 2;

void setup() {
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), onEvent, CHANGE);
}

void loop() {
}

void onEvent() {
  Serial.println(F("Action"));
}

Using the millis() function

Description

The millis() function returns an unsigned long variable representing the number of milliseconds elapsed since the microcontroller was powered up. In particular, it allows you to perform an action when a time interval has elapsed without blocking the rest of the program.

Code

unsigned long currentTime=0;
unsigned long previousTime=0;
bool ledState=LOW;

void setup() {
  Serial.begin(9600);
}

void loop() {
  currentTime=millis();
  if((currentTime-previousTime)>200){
    previousTime=currentTime;
    Serial.println(F("Action "));
  }
}

Using the microprocessor’s built-in timers

Timers are microcontroller registers that increment when a clock pulse is received.

Using Timer libraries

Arduino time management libraries are numerous. As a general rule, they interface with the Arduino’s timer registers. To name the best-known: TimerOne.h MsTimer2.h, TimerThree.h

Using task management libraries

These libraries allow tasks to be executed in an orderly fashion, giving the impression of multithreading.

Examples include TaskManager, ProcessScheduler, ArduinoThread or FreeRTOS. Find these libraries in the Arduino reference list.

Multitasking with the Arduino Due board

For boards based on SAM architecture, such as the Arduino DUE, there’s a library that lets you manage multiple tasks in different loop() functions. This also works for Zero, MKRZero and MKR1000 boards.

Multi-core microcontroller: ESP32

The NodeMCU ESP32 microcontroller is equipped with a dual-core microprocessor and uses the FreeRTOS OS, enabling it to run tasks in parallel.

Multithreading with Raspberry Pi

The Raspberry Pi is a microcomputer, which means it can perform several tasks at the same time. What’s more, its microprocessor is equipped with four cores, enabling it to perform true multitasking. You can, for example, run several Python scripts or C++ programs (or others) at the same time. It’s also possible to use multithreading libraries within a Python script.