Table of Contents

Objectives Timeline Group Assignment Individual Assignment
  • Conclusion
  • References
  • Design Files
  • Week 11: Networking & Communications

    Objectives

    These are the tasks for this week:

    Timeline

    Wednesday

    Thursday

    Friday

    Saturday

    Sunday

    Monday

    Tuesday

    Wednesday

    Group Assignment

    Individual Assignment

    Using the Attiny 412

    For this week, I will be referencing Midhun's (FA2023) and Adrian Torress' documentation, but I will be modifying it for the Attiny 1614 chip for the nodes and a development board I made during Electronics Poduction Week as my master board. I wanted to use I2C and UART communication protocol

    These is the pinmapping of Attiny1614

    The datasheet for the Attiny can be seen here

    Communication Protocols

    Using I2C

    I2C
    Source: How To Mechatronics

    Using UART

    UART
    Source: Electronics Stack Exchange

    Designing the Servo Driver Nodes

    This week I wanted to design modular servo driver boards that can each use 4 servos.

    PCBDesign Schematic

    Schematic

    For this week I wanted to design boards that can accept both I2C and UART communication protocols

    A tip by You can simply use Ctrl+C > Ctrl+V to copy and paste pictures into KiCAD

    For I2C communication I will be using Midhun's (FA2023) documentation, but adapting for Attiny 1614 (he used ATtiny 412) I tried improving on the original design by adding UART connections following the convention followed by FTDI to be able to debug the code if required.

    Schematic

    I wanted to make connections for both I2C and UART to in my boards. Since we have 02x03 IDC connectors, based on instructor input, I tried designing a hybrid connector for both I2C and UART connections

    This is how the completed schematic for my servo driver board looks like

    PCB Designing

    Since I want to make multiple copies, ideally the node PCB should be small. So, once I was able to get the connections right, I took a screenshot of the mock PCB for reference and proceeded to remove the trace,compress the space in between and add the traces again to make the PCB smaller

    Since my board had to be designed in such a way that it is easily milled in a repeatable manner, I wanted to avoid using wired vias for connections that I used previously. This increased design time by a lot, and in the end I had to add a 0 ohm resistor to make one connection to GND. This is how my node PCB looks like once done.

    PCBDesign

    Making the PCB

    Assembled Board

    Milling

    Just like previous weeks, I milled the boards. This included two nodes and one FTDI programer board to be able to program and debig the Attiny 1614.

    But later I realized that the programmer board I had milled was wrong, and I had to discard it because of lack of time

    Bill of Materials

    Just like before, I used the interactive BOM plugin to create a rough draft of required components, which was then used to create the final BOM sheet

    These are the BOM sheets for the two nodes (Node 1 has additional 4.99 K resistors for SDA and SCL pins of I2C connection, since I do not have them pulled up in the master board) and the new programmer desiigned by out instructor Saheen.

    Soldering

    These are how my node boards look like after soldering:

    Verification

    Using the Benchtop Power Supply

    Safety
    Testing for short circuiting for Node 1
    Testing for short circuiting for Node 1

    Now to make the connectors for wired connections. My instructor helped make a connector using 2 02x03 IDC connectors for each node and a 02x02 IDC connector (for I2C) and a 1x02 connector (for RX, TX) at the master board.

    The picture shown below shows a diagram of how the connector was designed:

    Programming

    Program 1: Testing I2C Connection

    I will be using this Xiao ESP32 C6 Development Board I made in Electronics Production Week

    Master Board

    Code for master board

    To make it for my Xiao, I had replaced Wire.write("x is "); in the original code with Wire.write((const uint8_t*)"x is ", 5); to avoid this error:

    Compilation error: invalid conversion from 'const char*' to 'uint8_t' {aka 'unsigned char'} [-fpermissive]

    For more explanation, click here.

    First we plug the master board and prepare the IDE and upload the following code

    
        // Wire Master Writer
        // by Nicholas Zambetti  < http://www.zambetti.com> and modified by Noel Joseph Saji 09/04/2022
        
        // Demonstrates use of the Wire library
        // Writes data to an I2C/TWI slave device
        // Refer to the "Wire Slave Receiver" example for use with this
        
        // Created 29 March 2006
        
        // This example code is in the public domain.
        
        
        #include <Wire.h>
        
        void setup() {
            Wire.begin();  // join i2c bus (address optional for master)
        }
        
        byte x = 0;
        
        void loop() {
            Wire.beginTransmission(8);  // transmit to device #8
            Wire.write((const uint8_t*)"x is ", 5);      // sends five bytes
            Wire.write(x);              // sends one byte
            Wire.endTransmission();     // stop transmitting
        
            x++;
            delay(500);
        }
                    
                            

    Code for Nodes

    Then we plug in one of the nodes plugged with the programmer are the IDE. Then we set the following in tools in the Arduino IDE

    Additionally we set the supply side voltage to 3.3 V if it does not work at 5V using the toggle switch in the programmer. Then we add the following code:

    
        // Slave-reader
        //
        // Wire Slave Receiver
        //
        // by Nicholas Zambetti < http://www.zambetti.com> and modified by Saheen Palayi 06/06/2022
        //
        // This work may be reproduced, modified, distributed,
        // performed, and displayed for any purpose, but must
        // acknowledge this project. Copyright is retained and
        // must be preserved. The work is provided as is; no
        // warranty is provided, and users accept all liability.
        //
        
        
        // Demonstrates use of the Wire library
        // Receives data as an I2C/TWI slave device
        // Refer to the "Wire Master Writer" example for use with this
        
        // Created 29 March 2006 by Nicholas Zambetti
        
        // This example code is in the public domain.
        
        
        //Added software serial for Attiny84
        // #include <SoftwareSerial.h>
        #include <Wire.h>
        
        
        // Software serial rx,tx pins of Attiny84
        const byte rxPin = 0;
        const byte txPin = 1;
        
        
        //declaring mySerial as SoftwareSerial
        // SoftwareSerial mySerial(rxPin, txPin);
        
        
        void setup() {
        
            Wire.begin(8);                 // join i2c bus with address #8
            Wire.onReceive(receiveEvent);  // register event
            Serial.begin(9600);          // start serial for output
        }
        
        void loop() {
            // Serial.println("hello");
            delay(100);
        }
        
        // function that executes whenever data is received from master
        // this function is registered as an event, see setup()
        void receiveEvent(int howMany) {
            while (1 < Wire.available()) {  // loop through all but the last
            char c = Wire.read();         // receive byte as a character
            Serial.print(c);            // print the character
            }
            int x = Wire.read();  // receive byte as an integer
            Serial.println(x);  // print the integer
        }        
                            

    Connecting Different Boards

    I connected the boards as shown below using the connector I made previously

    Program 2: Controlling LEDs using a Switch through I2C

    Code for Master Board

    
        #include <Wire.h>
    
        #define LED D3
        #define Switch D2
        int Sval;
        int counter = 0;
        
        void setup() {
        pinMode(Switch, INPUT);
        pinMode(LED, OUTPUT);
        Serial.begin(9600); 
        Wire.begin(); 
        }
        
        void loop() {
            Sval=digitalRead(Switch);
        
            if (Sval==1){
            digitalWrite(LED, LOW);
            }
        
        
            else if (Sval == 0) {
            digitalWrite(LED, HIGH);  //Debugging LED on Master board lights up to confirm that switch has been pressed.
            counter++;
            Serial.print("counter: ");
            Serial.println(counter);
            
            int slaveAddress = (counter % 2 == 0) ? 8 : 9;
            int ledState = (counter % 2 == 0) ? 0 : 1;
            
            // Send command to toggle LED on the selected slave device
            Wire.beginTransmission(slaveAddress);
            Wire.write(ledState);
            Wire.endTransmission();  
            
            delay(500);
            }
        
            else if (Sval==0){
            
            }
        
            delay(100);
            Serial.println(Sval);
        }
                                            
                            

    Conclusion

    Mistakes & Solutions

    1. ProshPlay 3D model missing: If 3D models are not being updated even after attaching the correct link in 3D preview, try updating the footprint library and repeat the relinking process once again
    2. Not able to burn bootloader/upload program using SerialUPDI and Attiny1614: While trying to burn the bootloader, I got an error saying Failed to burn bootloader

      After consulting ChatGPT, I tried measuring voltage drop at the chip whch was measured at only 3V, even though at the supply side there was 5V drop. I tested the continuity at the GND line and found that I used a 1k resistor instead of a 0 ohm resistor, which I then replaced, but it still did not solve the problem bad solder joint in the 0 Ohm resistor which prevented current from flowing through it.

      The next morning, Akash (FA2025) helped solve the problem by changing the supply voltage to 3.3 V (from 5V) using the toggle switch on the programmer, and setting the clock speed to 16 MHz (instead of default 20MHz). The problem with the voltage supply is caused by problems with the old programmer board (which will be replaced by the new one I will use today), but I am unaware of what it has to do with clock speed, but based on ChatGPT prompts, higher clock speeds require more precise timing and tighter voltage requirements, and due to errors that crept in while designing the boards (or the programmer), the chip is not stable enough to be communicated to at this clock speed fo 20MHz, so you need to slow it down.

      The ChatGPT prompts I used have been listed below:

    3. Compilation error while using Wire.write() for I2C connection:Acccording to ChatGPT you cannot directly use strings in Wire.write() for I2C connection

    References

    References to help reader understand in detail

    1. Attiny 1614 datasheet

    Design Files

    Click here to access the design files