Home


Fab academy

Week 14: Embedded Networking and Comunications



Week 14: Embedded Networking and Comunications

This week's assignment focuses on designing, building, and connecting wired nodes with network or bus addresses and a local interface. To achieve this, I designed the Coquiduino Serial Board, the setup features one TTL cable and two custom PCBs, each equipped with an ATtiny44 microcontroller operating as slaves in parallel. The project faced interference issues, necessitating a unique solution where the transmitter pin for each slave is set as an input by default and only set to output when returning confirmation of readings. This setup allows all slave boards to follow commands from the master computer using the Arduino IDE.


PCB Design:

Schematic:

Schematic


PCB:

PCBDesign


PCB Fabrication:

PCB Milling:

PCBMILL


PCB Engraving:

I was excited to try engraving the ceramic PCB with the CNC laser. The results were very good.

AdobeIllustrator
AdobeIllustrator


PCB Soldering:

Soldering
Soldering

Final Result:

FinalResult
FinalResult


Connections:

FinalResult


Loading Code:

FinalResult


In this setup, we have two ATtiny44 microcontrollers acting as slave nodes. Each node performs specific actions based on commands received from the master PC via serial communication.

FinalResult


Arduino IDE: Code

Node A:

Functionality:

Node A controls three LEDs and a temperature sensor (LM35). When it receives the command 'a' from the master, it sequentially powers on the three LEDs. When it receives the command 'T', it reads the current temperature from the LM35 sensor and sends this reading back to the master.

Code Explanation:

We use the SoftwareSerial library to handle serial communication since the ATtiny44 has limited hardware serial support. In the setup() function, we initialize serial communication and set the LED pins as outputs. In the loop() function, we check if there is any data available from the serial input. If the command 'a' is received, the LEDs are powered on sequentially with a delay between each. If the command 'T' is received, the code reads the analog value from the temperature sensor (LM35), converts it to a temperature reading, and sends this value back to the master via serial communication.


    #include <SoftwareSerial.h>
   // *** Define the RX and TX pins
               
   #define TX   9  //
   #define RX   10  // 
   #define LED1 1
   #define LED2 2
   #define LED3 3  
   #define LM35 0      
  
  SoftwareSerial mySerial(RX, TX);
                
   char chr;
                 
  void setup() {
  // initialize serial communications at 9600 bps:
                  
  mySerial.begin(9600);
  pinMode(TX,INPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(LM35, INPUT);
  }
                  
   void loop() {
   char chr = mySerial.read();
  
                  
   if (chr == 'a') {   
   digitalWrite(LED1, HIGH);
   delay(500);
   digitalWrite(LED1, LOW);
   delay(500);
   digitalWrite(LED2, HIGH);
   delay(500);
   digitalWrite(LED2, LOW);
    delay(500);
   digitalWrite(LED3, HIGH);
   delay(500);
   digitalWrite(LED3, LOW);

    pinMode(TX,OUTPUT);
    mySerial.println(chr);
    delay(1000);
   pinMode(TX,INPUT);
  }
  
  else if (chr == 'T') {
  lm35();
  }
  }

  void lm35(){
     // Read temperature from LM35
  int tempReading = analogRead(LM35);
  float voltage = tempReading * (5.0 / 1023.0);  // Convert analog reading to voltage
  float temperature = voltage * 100;  // Convert voltage to temperature (10mV per degree Celsius)

  pinMode(TX,OUTPUT);
  mySerial.print("Temperature: ");
  mySerial.print(temperature);
  mySerial.println(" C");
  delay(1000);
  pinMode(TX,INPUT);
  
  }
                  

    

Node B:

Functionality:

Node B controls three LEDs and a button. When it receives the command 'b' from the master, it sequentially powers on the three LEDs. When it receives the command 'm', it reads the state of the button (pressed or not) and sends this state back to the master.

Code Explanation:

Similar to Node A, we use the SoftwareSerial library for serial communication. In the setup() function, we initialize serial communication, set the LED pins as outputs, and set the button pin as input. In the loop() function, we check for incoming data from the serial input. If the command 'b' is received, the LEDs are powered on sequentially with a delay between each. If the command 'm' is received, the code reads the state of the button and sends this state back to the master via serial communication.


        #include <SoftwareSerial.h>
   // *** Define the RX and TX pins
               
   #define TX   9  //
   #define RX   10  // 
   #define LED1 1
   #define LED2 2
   #define LED3 3  
   #define Button 0      
  
  SoftwareSerial mySerial(RX, TX);
                
   char chr;
                 
  void setup() {
  // initialize serial communications at 9600 bps:
                  
  mySerial.begin(9600);
  pinMode(TX,INPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(Button, INPUT);
  }
                  
 void loop() {
   char chr = mySerial.read();
  
                  
   if (chr == 'b') {   
   digitalWrite(LED1, HIGH);
   delay(500);
   digitalWrite(LED1, LOW);
   delay(500);
   digitalWrite(LED2, HIGH);
   delay(500);
   digitalWrite(LED2, LOW);
    delay(500);
   digitalWrite(LED3, HIGH);
   delay(500);
   digitalWrite(LED3, LOW);

    pinMode(TX,OUTPUT);
    mySerial.println(chr);
    delay(1000);
   pinMode(TX,INPUT);
  }
  
  else if (chr == 'm') {
  button(chr);
  }
  }
  
  void button (char chr){
  if ((chr == 'm')) {
     int state = digitalRead(Button);
    pinMode(TX,OUTPUT);
    mySerial.print("Button State: ");
    mySerial.println(state);
    delay(1000);
    pinMode(TX,INPUT);
  }
}
        
        


Final Result:


Group Assigment Page!!


Group Assigment Personal Aport:

This week's assignment involved establishing communication between two Seeeduino Xiao ESP32 boards using Wi-Fi and the MQTT protocol to send messages.

To begin, our primary objective was to set up Wi-Fi communication between the two ESP32 boards and use the MQTT protocol to send and receive messages. For hardware, we used two Seeeduino Xiao ESP32C3 boards. In terms of software, we relied on the Arduino IDE, installing two libraries: WiFi.h for handling Wi-Fi connections and PubSubClient.h for managing MQTT communication.

For the MQTT broker, we used the server broker.hivemq.com and connected to a Mobile-Hotspot Wi-Fi network, using SSID and password to ensure a secure connection.

We successfully sent the word "avanzando" from one board to the other. One board acted as the publisher, sending the message to the MQTT topic, while the other board acted as the subscriber, receiving the message. This exercise helped us understand the flow of data in an MQTT system and the significance of topics in organizing message communication.

GroupalAssigment

Successfully sending the message "avanzando" demonstrated our understanding of Wi-Fi and MQTT protocols, reinforcing the importance of reliable network connections and proper configuration in IoT projects. This assignment provided valuable experience for future wireless communication endeavors.

You can download the files HERE!