Skip to content

Week 11, Networking

Assignments

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

See group work page for details

Individual assignment

  • Design, build and connect wired or wireless node(s) with network or bus addresses and a local input and/or output devices

Individual work

For my individual project, I will need to have an interface where the number of cards and players can be selected. I2C communication seems to be a good option given flexibility for both input and output.

For this week, I am making a control board with an LED and also nodes with a button plus LED. My control board will use an ESP32, while the nodes will have ATTiny412s. My designs are based on work from my instructor for networking week.

My intention in using the ESP32 is to have potential for a WiFi interface, allowing for another layer of networking.

For the control board, I made a board with a socket for the ESP32, 4 pins for the VCC, GND, SCL, SDA lines for I2C communication. I also added a button and LED (with 1k resistor) connected to the ESP32. The design was made in KiCad, and all the connections made. It was tested with the electrical rules checker. I only moved to PCB design after the schematic checks passed.

Schematic for the control board

With the schematic, I imported all components into the PCB editor for KiCad. These were wired, and tested with the design rule checker. Using the bezier curve tool, I deviated from a rectangular board.

PCB control board

The files for the Main Control Kicad are available.

Similarly, I needed to make boards for the ATTiny412, led, and button. Importantly, these have 4 pins for the VCC, GND, SCL, SDA lines for I2C communication. Additionally, there are 3 pins for programming the node via VCC, GND, and UPDI. This is based on the design used by my instructor. Again, the schematic design was checked with the electrical rules checker.

Node schematic

In the PCB editor, the traces were made. For these, I made circular boards to keep it interesting.

Node PCB

The files for the Node Kicad are available.

Using the Roland MX-20, I fabricated the boards.

Fabricated boards

Subsequently, all the components were soldered onto the board.

Soldering node

Then it was time to program the nodes. For this I used the Arduino IDE. This needs to have support for the ATTiny412 added. This can be found by adding the source of https://drazzy.com/package_drazzy.com_index.json to the IDE. This is added by putting this URL in the settings.

Adding support for tinyAVR devices to ArduinoIDE

The ATTiny412 needs to be connected to the computer and the board needs to be specified in the IDE. After adding support, the specific board for programming can be chosen.

Selecting board and port

With my instructors help, we programmed the nodes with the basic code.

Programming node

//original code by Luis Diaz
//Fab Academy 2022
//Fab Lab León
//ATtiny412 node 1 I2C

#include <Wire.h>
int d1 = 0;
#define led 4

void setup() {
  pinMode(led, OUTPUT);
  Serial.begin(115200);
  Wire.begin(8);     //change address for the nodes in my case I use 1 and 2.
  Wire.onReceive(recieveEvent);
}

void loop() {
  if (d1 == 1)
  {
    digitalWrite(led, HIGH);
  }
  else
  {
    digitalWrite(led, LOW);
  }

  delay(500);
}

void recieveEvent(int howMany)
{
  while (Wire.available())
  {
    d1 = Wire.read();
  }
}

To enable communication, I made a wire with 4 pin connectors. All my four pins for communication are in the same orientation, which is important for the proper control.

Making wire connectors

Then, I connected the control board ESP32 to my computer with USB, and the nodes were connected to the control board. I first tried to detect the nodes with the following program. Unfortunately, I was not getting success in detecting the nodes.

I only started because I had other code that should have blinked the LEDs on the nodes, but that was not working.

from machine import Pin, I2C
import time

i2c = I2C(0, scl=Pin(6), sda=Pin(5), freq=115200)



while True:
    print("start scan ...")
    devices = i2c.scan()

    if devices:
        for address in devices:
            print("   found", address, "(0x{:02X})".format(address))
    else:
        print("   no devices found")

    time.sleep(1)

Therefore, I then tried to program the ESP32 with Arduino code, as the microprocessor also supports that.

Using the following code

#include <Wire.h>
#include <twi.h>
#include <twi_pins.h>

//original code by Luis Diaz
//Fab Academy 2022
//Fab Lab León
//ATtiny412 node 1 I2C

#include <Wire.h>
int d1 = 0;
#define led 4

void setup() {
  pinMode(led, OUTPUT);
  Serial.begin(115200);
  Wire.begin(1);     
  Wire.onReceive(recieveEvent);
}

void loop() {
  if (d1 == 1)
  {
    digitalWrite(led, HIGH);
  }
  else
  {
    digitalWrite(led, LOW);
  }

  delay(500);
}

void recieveEvent(int howMany)
{
  while (Wire.available())
  {
    d1 = Wire.read();
  }
}

I was able to program the control node. When connected to USB (for power), a node connected to the control node blinked as expected.

I2C blinking node

While I then had successful I2C communication, I ran out of time during the week to program the buttons. That would have been my 2nd spiral, where button pushes would change the blinking behavior.