Networking and Communications

The requirements for this week is send a message between two projects and document your work on the group work page and reflect on your individual page what you have learned, and the the individual assignment must comply with the following design point, build and connect wired or wireless node(s) with network or bus addresses and a local interface.

GROUP ASSIGMENT

Networking and Communications

Communications can be classified into different types based on topology, transmission medium, and the protocols used.

Communication Protocols

SPI (Serial Peripheral Interface)

SPI is a synchronous communication protocol primarily used for high-speed communication between a microcontroller and peripherals such as sensors, memory, and other devices. SPI uses four lines for communication:

  • MISO (Master In Slave Out): Line for sending data from the slave to the master.
  • MOSI (Master Out Slave In): Line for sending data from the master to the slave.
  • SCK (Serial Clock): Clock line generated by the master.
  • SS (Slave Select): Line for selecting the slave device to communicate with.

SPI is fast and efficient but requires more connection pins, which can be a limitation in some projects.

UART (Universal Asynchronous Receiver-Transmitter)

UART is an asynchronous communication protocol, meaning it does not require a shared clock line. Data is sent in the form of individual bits in a specific sequence, usually with a start bit, 5-9 data bits, an optional parity bit, and one or more stop bits. The main pins used are:

  • TX (Transmit): Line for sending data.
  • RX (Receive): Line for receiving data.

UART is simple and widely used, especially for long-distance serial communication or between computers and devices.

I2C (Inter-Integrated Circuit)

I2C is a synchronous, multi-master/multi-slave communication protocol, meaning that multiple devices can operate as masters and slaves. It is used for communication between microcontrollers and low-speed, short-distance peripherals. I2C utilizes only two lines for communication:

  • SDA (Serial Data Line): A bidirectional data line.
  • SCL (Serial Clock Line): A clock line generated by the master.

I2C Protocol Features

  • Addressing: Each I2C device has a unique address, allowing multiple devices to connect on the same bus without conflict.
  • Pin Efficiency: Only two pins are required for communication, conserving microcontroller space.
  • Simplicity: Configuration and implementation are straightforward.
  • Flexibility: Supports multiple devices on the same bus and multi-master communication.
  • Compatibility: Compatible with a wide range of peripheral devices, including sensors, memory, and more.

Implementation of I2C between Arduino UNO, Xiao RP2040, and Xiao ESP32

Arduino UNO

The Arduino UNO has dedicated pins for I2C: A4 (SDA) and A5 (SCL). The Wire.h library makes I2C implementation easy on the Arduino.

Xiao RP2040

The Xiao RP2040 also supports I2C and has configurable pins for SDA and SCL, which can be defined in the code as per the project's needs.

Xiao ESP32

The Xiao ESP32 is compatible with I2C and, like the RP2040, allows configuration of the SDA and SCL pins through software. The Wire.h library is compatible and simplifies the implementation.

The design of this board is the one from my Electronic Design Week

I2C Configuration between Devices

Connections

  • SDA: Connect the SDA pin of each device together.
  • SCL: Connect the SCL pin of each device together.
  • VCC: Connect all VCC pins together.
  • GND: Connect all GND pins together.

Code

I2C Addresses

Assign a unique I2C address to each slave device.

  • Arduino UNO: 0x08
  • Xiao RP2040: 0x09
  • Xiao ESP32: 0x0A

Arduino Code (Master)

This code will send a command to each slave device every 3 seconds and also turn on the integrated LED on pin 13 of the Arduino UNO.

Xiao RP2040 (Slave) Code

This code waits for a command from the master and turns on the LED on pin D1, keeping it on.

Xiao ESP32 (Slave) Code

This code waits for a command from the master and turns on a strip of 8 Neopixels on pin 5, keeping them on.

The moment of trurh

I successfully implemented an I2C communication system between an Arduino UNO, a Xiao RP2040, and a Xiao ESP32. The Arduino UNO acted as the master, sending commands every three seconds to each slave device to turn on their respective LEDs and a strip of Neopixels. This setup demonstrated the simplicity and efficiency of using the I2C protocol for inter-device communication in a multi-microcontroller system.

Problems?

Surprisingly, there were no problems of any kind for this practice, neither with electronics nor with programming.