Week 11: Networking and Communications
This week, we explored networking and communications, focusing on the various protocols microcontrollers use to exchange data, whether sending commands or sharing process information. As part of the assignment, we tested and compared different communication protocols, evaluating their effectiveness for wired and wireless applications. Click here to check on this week's group assignment page.
Work log
Completed tasks
- Demonstrated workflows used in network design.
- Implemented a communication protocol.
1.What is a communications protocol?
A communication protocol is a set of rules or an agreed-upon "language" that microcontrollers use to exchange data with each other reliably. It ensures that the data is sent, received, and understood correctly between devices.
Why are communication protocols necessary? Microcontrollers are capable but limited devices; they have finite processing power, memory, GPIO pins, and peripherals. When a system grows in complexity, a single microcontroller often can't handle everything efficiently. This is where inter-MCU communication becomes essential.
Main reasons for offloading tasks to secondary microcontroller:
- Processing limits: When a primary MCU is tasked with motor control, sensor fusion, and display management simultaneously, it may struggle to meet real-time deadlines. Offloading time-critical tasks, such as motor PID loops, to a secondary microcontroller enables the main MCU to focus on higher-level logic and system coordination.
- Peripheral specialization: Different microcontrollers are optimized for specific functions. For example, an ESP32 excels at WiFi and BLE communication, an ATtiny is ideal for low-power I/O operations, and an STM32 is well-suited for precise timing tasks. Rather than using a single, potentially expensive MCU for all roles, deploying specialized microcontrollers can be more cost-effective and efficient.
- Real-time requirements: Tasks demanding strict timing—like PWM generation, encoder reading, or stepper motor control—benefit from being handled by a dedicated MCU. This approach prevents critical operations from being delayed by other processes running on the main controller.
- Physical separation: In distributed systems or robots, sensors and actuators may be physically distant from the main controller. Assigning local microcontrollers to handle processing at each node reduces wiring complexity, lowers latency, and increases system reliability.
- Power domains: A low-power microcontroller can remain active to monitor sensors or handle simple tasks while the main MCU enters a low-power sleep mode, thereby improving overall energy efficiency.
Common communications protocols include:
| Protocol | Wires | Topology | Speed | Typical Use |
|---|---|---|---|---|
| I2C | SDA, SCL | Multi-master / slave bus | 100 k – 3.4 M bps | Sensors, EEPROMs, MCU-to-MCU |
| SPI | MOSI, MISO, SCK, CS | Master / slave | 10s of Mbps | Displays, flash, fast sensors |
| UART | TX, RX | Point-to-point | Configurable | Debugging, GPS, MCU-to-MCU |
| CAN | CANH, CANL (differential) | Multi-node bus | Up to 1 Mbps | Automotive, robotics |
2. Which communication protocol did I choose to focus on for this assignment?
As I mentioned in my Week 9 assignment, I anticipated that I might revisit I2C at some point, and that time has come. For this assignment, I have decided to use I2C as the communication protocol. I have used I2C in the past; in my original robot, it served as the foundation for communication between my microcontrollers. For this new iteration of my robot, I require a similar type of connection, so I2C is once again the logical choice. Before I explain what I accomplished for this assignment, I’d like to provide a brief overview of the I2C communication protocol.
I2C (Inter-Integrated Circuit) is a synchronous serial communication protocol developed by Philips in the 1980s, designed for short-distance communication between integrated circuits (ICs) on the same board. It is widely used in embedded systems for connecting microcontrollers, sensors, and other peripherals. Before diving into technical details, it's important to understand that "short distance" in I2C typically means any length from a few centimeters up to about 1 meter. This limitation exists because I2C lines have inherent capacitance, and the I2C specification defines a maximum bus capacitance of 400 pF. As the wire length increases, so does the capacitance, which slows down the signal edges and can lead to communication errors.
Please note that I2C terminology has recently changed; the following table outlines both the previous and current terms.
| Old term | New term | Role |
|---|---|---|
| Master | Controller | Initiates communication and generates the clock |
| Slave | Target / Peripheral | Responds to requests from the controller |
| Multi-master | Multi-controller | Multiple devices can initiate communication |
| Master-Slave | Controller-Target | Full description of the bus relationship |
Key characteristics of I2C include:
Two-wire interface:
- SDA(Serial Data Line): Carries the data being transmitted between devices.
- SCL(Serial Clock Line): Provides the timing signal for data transmission.
Both lines are open-drain and require pull-up resistors (typically 4.7 kiloohms for standard mode).
Multi-device support : One or more controllers can control the clock and initiate transfers; each target on the bus has a unique 7-bit or 10-bit address. Up to 127 devices can share the same bus.
How does I2C handle communication between multiple devices?
- Controller initiates communication and generates the clock signal (SDA falls while SDA is high).
- Controller sends the target address + R/W bit.
- Target responds with an ACK or NACK signal.
- Data bytes are transferred, each followed by an ACK or NACK.
- Controller terminates communication by sending a STOP condition (SDA rises while SCL is high).
The following table shows the bus states:
| Bus state | SDA | SCL | Who controls it |
|---|---|---|---|
| Idle | HIGH (via pull-up) | HIGH (via pull-up) | Pull-up resistor |
| Transmitting 0 | LOW | Toggling | Device pulls line to GND |
| Transmitting 1 | HIGH (released) | Toggling | Pull-up resistor (device releases line) |
| ACK | LOW | HIGH pulse | Target pulls SDA low to acknowledge |
| NACK | HIGH | HIGH pulse | Target releases SDA (no acknowledgement) |
I2C addresses are how the controller identifies which device it wants to talk to on the shared bus.
Address size:
- 7-bit addresses: The standard, giving 128 possible addresses (0x00-0x7F)
- 10-bit addresses: An extended format, giving 1024 possible addresses (0x000-0x3FF)
Addressing scheme:
| Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| Field | A6 | A5 | A4 | A3 | A2 | A1 | A0 | R/W |
In a 7-bit address, the first 7 bits (A6-A0) represent the device's unique address on the bus, while the least significant bit (R/W) indicates whether the controller intends to read from (1) or write to (0) the target device.
In a 10-bit address, the first two bits are fixed as '11110', followed by 8 bits for the address (A9-A2), and the R/W bit is still used to indicate read/write operations.
Some addresses are reserved for special purposes, such as general call (0x00), which allows a controller to address all devices simultaneously.
Most ICs have a partially fixed address set by the manufacturer, with 1-3 bits you can configure via hardware pins (ADDR pins tied to GND or VCC):
- The MPU-6050 IMU has address 0x68 or 0x69 depending on the configuration of the AD0 pin.
- The PCF8574 I/O expander lets you set 3-bits, giving 8 possible addresses (0x20-0x27).
This configurable addresses allow for multiple identical devices on the same bus, up to however many bits are available for configuration.
If two devices share the same address and there's no way to configure one, there is a problem. Solutions include:
- I2C multiplexers like the TCA9548A let you switch between multiple sub-buses, isolating conflicting devices.
- Using another device with a different default address.
When wiring up a new device with an unknown address, you can run an I2C scanner, a short sketch that tries very address from 0x01 to 0x7F and reports which ones ACK.
3.How did I experiment with I2C for this assignment?
At that point in the Fab Academy, I assumed that the electronics for my robot would be a XIAO ESP32-C6 controlling four different Attiny 1616 microcontrollers. So I first attempted to use my XIAO ESP32-C6 for this assignment. However, I discovered that I had connected the I2C resistors between the corresponding GPIOs on the XIAO and the pin headers without using the pull-up configuration. Fortunately, my instructor told me to stick with the Raspberry Pi Pico 2 I had previously used. So I decided to redesign my system as a Raspberry Pi Pico 2 running two Attiny 1616 boards.
For starters, KiCad is an open-source software suite designed for creating electronic circuit schematics and printed circuit boards (PCBs). It features an integrated workflow that enables users to design a schematic in conjunction with its corresponding PCB. Additionally, KiCad offers various utilities to assist with circuit and PCB design. These include a PCB calculator for determining trace width, resistance, and current capacitance; a Gerber viewer for inspecting manufacturing files; and an integrated SPICE simulator to validate circuit behavior. KiCad is compatible with Windows, macOS, Linux, and Docker, and it supports PCBs with up to 32 copper layers, making it suitable for designs of varying complexities.
4. My PCB design
This week, I designed the PCB that I will use in my upcoming electronics assignments and to get acquainted with a microcontroller that I will use for my final project. The PCB I designed is based on the Xiao ESP32C6 board, as I aim to utilize its connectivity options and processing power to assist with debugging during indoor testing and to serve as the brain of my robot. Furthermore, the Xiao ESP32C6 can host RTK rover firmware and instructions for relaying commands to other microcontrollers. This capacity will be useful since an RTK module like the UM982 can interface with the Xiao ESP32C6, perform positioning operations, and relay that information to the Xiao without overloading it. Another design consideration I took into account when designing this board was the tools available for fabrication. FabLab Puebla is currently equipped with CNC3018 and monoFab SRM-20 milling machines, which are ideal for manufacturing one-layer PCBs. However, manufacturing double-sided PCBs with these machines can be a daunting challenge; as such, I decided to make my design a one-layer PCB. Another design consideration was the surface-mount package size; our local instructor advised us to use 1206 SMT components. That number is based on the component's dimensions in inches: 12 = 0.12 inches long and 06 = 0.06 inches wide, which is approximately 3.2 mm x 1.6 mm; those dimensions are still comfortable for manual soldering.
4.1. Getting started with KiCad
Before I began designing my PCB, I first installed the component library provided by the Fab Academy team to ensure compliance with the necessary component packages and sizes. There are two methods to install a library. The first method involves clicking on the icon for the "Plugin and Content Management" menu, which opens the plugin and content management interface. This interface features a search bar for locating specific add-ons organized into four categories: Plugins, Fabrication Plugins, Libraries, and Color Themes. To find the Fab Academy Library, I entered "KiCad FabLib" into the search bar. I chose to download the top option on the list because its description included links to the repository maintained and updated by its users. After clicking "Install" and then "Apply pending changes," a window titled "Applying Package Changes" will pop up, showing two progress bars along with details such as the download URL and operation status. Once the progress bars are complete, we can click "Close."
Once the folders containing each type of file are decompressed, if the download proceeds without any problems, our folders should include one file with the .kicad_sym extension. This file contains all the symbols from the boards currently offered by Seeed Studio. A second folder should contain several files with the .kicad_mod extension, which correspond to the footprint files for each board currently available from Seeed Studio. A third folder should contain the .step file, which represents the 3D model.
File with the .kicad_sym extension:
Files with the .kicad_mod extension:
Adding an electronic component's footprint is almost the same as adding a symbol. The major difference is that the process starts by selecting the "Manage Footprint Libraries" option under the Preferences menu. Additionally, the .kicad_mod file may not be visible when trying to add its path while viewing it through our file browser opened from KiCad. In this case, the program will focus on localizing the folder containing the file rather than the file itself.
Offset number was changed from 4 to 1
Clicking the footprint cell will open the Footprint Chooser. Footprints are also sorted by libraries and can be filtered using the search bar on top.
After placing the Xiao ESP32C6 board, I began designing the power supply section of the breakout board. I started by adding a couple of SMD horizontal pin header connectors to accommodate the voltage and ground terminals of a power supply. I also included a voltage regulator to adjust the input voltage to a level that would safely power the Xiao board, along with a couple of capacitors. My intention was to power the Xiao with a 5-volt signal. I selected a regulator from the fab library and included the capacitors according to the recommendations outlined in the regulator's library. It is advised to place a 0.47 µF capacitor between the unregulated voltage and the regulator's input pin, as well as a second capacitor at the output of the regulator, with a minimum value of 22 µF to maintain stability. The suggested values indicate that the input capacitor should be ceramic (without polarity), while the output capacitor should be electrolytic (polarized). A small input capacitor is usually placed to handle fast, high-frequency noise and spikes coming from the supply line, acting like a nearby fast reservoir. A larger capacitor is usually placed at the output of a regulator to handle larger changes in load current while keeping the regulator's output stable.
One method for connecting components in KiCad involves clicking on a terminal of one component and dragging the cursor until it reaches the terminal of another component. Once you have identified the terminal you wish to connect, simply click on the other terminal to finalize the connection.
Symbols that represent a power output and ground terminal can be added by accessing the Choose Power symbol menu, which can be opened by clicking on the fourth icon of the bar on the right side of the interface.
Another way to connect components in KiCad is by using global labels. These labels can be created and accessed by clicking on the thirteenth icon in the bar on the right side of the interface. To ensure they function correctly, one component should have a label designated as an input, while the other component should use the same label as an output.
The circuit design features an LED connected in parallel to the Xiao board, functioning as an indicator. When the board is powered on, the LED illuminates, indicating that the board is energized. To prevent excessive current draw, I placed a 1000-ohm resistor in series with the LED. This resistor takes in the extra voltage and keeps the current at a safer level. Since my regulator provides 5V and a typical red LED requires 2V, the voltage across the resistor is calculated as 5V - 2V = 3V. Using Ohm's law, I can determine the current: I = V/R; thus, I = 3V/1000 ohms = 0.003 A, which is equivalent to 3 mA. The resulting current value still results in an LED with notable brightness.
I also included an additional LED connected to a pin from the Xiao board and a pull-down button. I included these elements to help me figure out if the board gets damaged. In case I suspect the board is no longer working properly, I could program the LED to start blinking following some pattern; if the LED does not respond, that means the board may be damaged or needs a hard reset. A similar logic applies to the button; when pressed, it will send a high logic value to its corresponding pin. If the Xiao can get that read, it means the board is still functioning.
The schematic is complete. The pins on the Xiao board that can be soldered with through-hole pins have been connected to an SMT pin header, except for the two used for the LED indicator and the push button.
Before proceeding with the PCB design, I ran the Electronic Rule Checker (ERC) from the Inspection menu. This tool detects potential mistakes that could lead to circuit failure. However, it is important to understand what the ERC considers a mistake. For instance, in my circuit, I did not connect anything to the pins on the back of the Xiao board because I do not need them for the deliverables I am preparing for the upcoming assignments. Nevertheless, the ERC flagged these unconnected pins as potential issues.
I would like to evaluate KiCad's simulation capabilities prior to reviewing my PCB design. KiCad can simulate electronic components if their SPICE models, which are standardized descriptions of electronic circuits, are available. While KiCad may not be the first choice for simulation among some users, it is essential to acknowledge this functionality offered by the EDA software.
Simulations in KiCad are performed using the schematic editor. To start, you need to place SPICE-compatible components and set their values by double-clicking on each symbol to edit their properties. In this simulation, I connected a resistor in series with a capacitor, along with a DC power supply.
To initiate the simulator, click on the fifth icon from the right in the top bar. This will open the simulation tab, where you can select the type of analysis you wish to conduct. In this section, you will also need to specify the source, starting value, final value, and increment step. After completing these fields and clicking "OK," the simulator will present a screen that allows you to visualize various graphs related to the simulation. To view specific data, the final step is to place a probe on the circuit at the point where you want to measure a value. Once the probe is placed, the window will display a graph representing the requested data. In this instance, I requested information on the voltage stored by the capacitor and its relationship with the current.
4.3 PCB Design
To translate our schematic to a PCB, we can open the PCB editor either from the schematic editor or from KiCad's main interface. Before proceeding with my design, I opened the Board Setup menu by clicking the icon resembling a PCB with a gear. I only changed the values for minimum clearance between traces and the minimum track width. I chose a minimum track of 0.8 mm, as that is the diameter of the V-tools used for engraving PCBs at FabLab Ibero Puebla, and as such, the minimum clearance is equal to the tool's radius, 0.4 mm.
5. Files
Here are the downloadable files for this week:
KiCad schematic and PCB layoutReflection
While some ideas must initially be drafted by hand, such as circuit designs, it is advantageous to live in the era of EDA (Electronic Design Automation) software. I was previously unaware of the compatibility between EDA software and 3D CAD files; this capability can assist designers in more effectively sizing the spaces for housing electronics within a product.