Assignments

This week we learned about networking and communications, something that has intrigued me since I was a child. How

Table of Contents

  • Group Assignment
    • Send a message between two projects.
    • Document your work to the group work page and reflect on your individual page what you learned
  • Individual Assignment
    • design, build and connect wired or wireless node(s) with network or bus addresses and a local input and/or output devices

    Roadmap

    Communication Protocol.

    Communication protocol is basically a set of rules and conventions that determine how data is transmitted, received, and interpreted between devices. Its purpose is to ensure smooth and reliable communication by defining aspects like data formats, error handling, and transmission speeds.

    UART (Universal Asynchronous Receiver-Transmitter), SPI (Serial Peripheral Interface), and I²C (Inter-Integrated Circuit) are communication protocols commonly used in embedded systems for connecting microcontrollers, sensors, and other peripherals. Here's a detailed comparison:

    Feature UART SPI I²C
    Communication Type Asynchronous Synchronous Synchronous
    Number of Wires 2 (TX, RX) 4+ (SCLK, MOSI, MISO, SS/CS) 2 (SCL, SDA)
    Speed Low Very High Moderate
    Device Support Point-to-Point Master & Slaves Multiple Devices
    Complexity Simple Moderate Low

    Wired and Wireless Network.

    For every communication system medium is very important. Where the two communicating devices makes used of the medium to sent or receive datas. In the wired communication, two device communicate using the wired medium. Based on the distance, certain equipments such as switches, amplifier or repeaters are used to enhance the flow of the communication. The wired communication is much more realiable since there is minimum disturbance from the enviroment.

    In wireless communication, usually the communication medium is the air. The performance of these protocol is determined by the type of communication protocol used. Since the type of protocol used directly affects the range of communication. Wifi and bluetooth are of short range protocol. Lora, GSM, FM and AM are of long range communication.

    Thank you Rico san for these videos!

    Synchronous Communication

    Synchronous data transmission is a data transfer method in which a continuous stream of data signals is accompanied by timing signals. This type of communication can be virtual as well, either scheduled or a little more impromptu.
    Synchronous communication occurs when tasks are performed one after another, in a sequential order. One task must complete before the next begins. For example, when waiting in line, each person is served one by one.

    • Characteristics: Sequential and predictable.
    • Example:A face-to-face conversation: You listen while the other person speaks, and only after they finish, you respond.
    • In Computing: Code execution halts until a task is completed.

    Asynchronous Communication

    Asynchronous transmission is also know as start or stop transmission. It sends data from the sender to the reciever usuing the flow control method. This type of communication isn’t generally conducted in person, nor is it planned for or scheduled. Asynchronous communication allows tasks to operate independently of one another. Tasks can overlap or run concurrently. For instance, sending an email while continuing other activities.

    • Characteristics: Independent and non-blocking.
    • Example: Sending a text message: You send it and go about your day, and the recipient replies when they are available.
    • In Computing: Code execution continues without waiting for a task to complete.
    • Synchronous = Immediate response(like a phone call).
    • Asynchronous = Delayed response (like an email).

    Individual Assignment

    First of all, i decided to try connecting my board with Wi-fi so I followed this official page for my microcontroller. I started off by connecting my Bluetooth/WiFi antenna with the board and copy pasting this code and scanned the nearby Wi-fi networks

                                    
    #include "WiFi.h"
    
    void setup()
    {
        Serial.begin(115200);
    
        // Set WiFi to station mode and disconnect from an AP if it was previously connected
        WiFi.mode(WIFI_STA);
        WiFi.disconnect();
        delay(100);
    
        Serial.println("Setup done");
    }
    
    void loop()
    {
        Serial.println("scan start");
    
        // WiFi.scanNetworks will return the number of networks found
        int n = WiFi.scanNetworks();
        Serial.println("scan done");
        if (n == 0) {
            Serial.println("no networks found");
        } else {
            Serial.print(n);
            Serial.println(" networks found");
            for (int i = 0; i < n; ++i) {
                // Print SSID and RSSI for each network found
                Serial.print(i + 1);
                Serial.print(": ");
                Serial.print(WiFi.SSID(i));
                Serial.print(" (");
                Serial.print(WiFi.RSSI(i));
                Serial.print(")");
                Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*");
                delay(10);
            }
        }
        Serial.println("");
    
        // Wait a bit before scanning again
        delay(5000);
    }
                                    
    
                                    

    Then in the serial monitor, you will to see the nearby networks.

    I2C
    #include 
    
    const char* ssid     = "your-ssid";
    const char* password = "your-password";   
    
    void setup()
    {
        Serial.begin(115200);
        delay(10);
    
        // We start by connecting to a WiFi network
    
        Serial.println();
        Serial.println();
        Serial.print("Connecting to ");
        Serial.println(ssid);
    
        WiFi.begin(ssid, password);
    
        while (WiFi.status() != WL_CONNECTED) {
            delay(500);
            Serial.print(".");
        }
    
        Serial.println("");
        Serial.println("WiFi connected");
        Serial.println("IP address: ");
        Serial.println(WiFi.localIP());
    }  
    void loop()
    {
      }
    
    

    Then in the serial monitor, you should see this.

    I2C

    For this week, I planned on controlling my board with a web server and for that I referred to Thinley Wozer's documentation. It actually helped me a lot. Instead of using his code, I modified it by deleting the 2nd LED code that he put and then I changed my GPIO to 20 too. Then I asked AI(chatgpt for explanation and this is what it gave me).

    #include 
    #include 
    
    const char* ssid = "SSID";
    const char* password = "Password";
    
    WebServer server(80);
    
    const int ledPin1 = 20; // GPIO pin for LED 1
    
    void setup() {
      pinMode(ledPin1, OUTPUT);
    
      Serial.begin(115200);
      Serial.println();
      Serial.println("Connecting to Wi-Fi");
    
      WiFi.begin(ssid, password);
      while (WiFi.status() != WL_CONNECTED) {
        delay(1000);
        Serial.print(".");
      }
    
      Serial.println("");
      Serial.println("WiFi connected");
      Serial.println("IP address: ");
      Serial.println(WiFi.localIP());
    
      // HTML for the web page (only one LED)
      String html = "";
      html += "

    ESP32 Web Server

    "; html += "

    HELLO LED-I am going to control you little thing! MWAHAHAH!

    "; html += ""; html += ""; html += ""; server.on("/", HTTP_GET, [html]() { server.send(200, "text/html", html); }); server.on("/on1", HTTP_GET, []() { digitalWrite(ledPin1, HIGH); server.send(200, "text/plain", "LED 1 turned on"); }); server.on("/off1", HTTP_GET, []() { digitalWrite(ledPin1, LOW); server.send(200, "text/plain", "LED 1 turned off"); }); server.begin(); Serial.println("HTTP server started"); } void loop() { server.handleClient(); }
    #define LED_PIN 3  // Change this to your desired output pin
    
    void setup() {
      Serial.begin(9600);  // Start serial communication at 9600 baud rate
      pinMode(LED_PIN, OUTPUT);  // Set LED pin as output
    }
    
    void loop() {
      if (Serial.available() > 0) {
        char receivedChar = Serial.read();  // Read the incoming byte
    
        // Check the received character and control the LED accordingly
        if (receivedChar == '1') {
          digitalWrite(LED_PIN, HIGH);  // Turn the LED on
          Serial.println("LED ON");
        }
        else if (receivedChar == '0') {
          digitalWrite(LED_PIN, LOW);   // Turn the LED off
          Serial.println("LED OFF");
        }
      }
    }
    
                                    

    Final Project Development

    I sent a diagram for my electrical connections for the week and then Sir Rico gave me useful suggestions and advices. He told me that I had connected the relay in the wrong way.

    These were his explanations : "The wires from the MCU will be VCC, GND and Signal...to the Relay. From the Relay...there will be a wire in from a power source (+) and a wire out to the device (Motor, Pump, LED) that is also the + wire. The GND wire goes from power source directly to the device."
    "basically...the + wire from the power source is 'interrupted' by the relay (switch). the microcontroller sends an ON or OFF signal via the signal wire to allow the 'interruption' to connect or disconnect. The VCC and GND wire to the Relay is to power the Relay module"
    He sent me these 2 pictures so I could vidualize and understand better too

    Then he sent me a refined diagram for my electrical components which has helped me understand about the connections better. Thank you Rico san!!!

    Then I redrew my electronics diagram which then helped me get a better visualization of how my final PCB would look like.