Networking

and Communications

  • individual assignment: design, build, and connect wired or wireless node(s) with network or bus addresses
  • group assignment: send a message between two projects

    #ArduinoUno#Atmega328P

Group Assignment


I was in the group with Zhengya Gong, Yazan Barhoush, Noora Nyberg and Xinhui Hu. We were sending messages between 3 ATtiny412 boards connected with Rx/Tx Hub. The assignment is published on Xinhui's page Networking and Communications.

Serial communication


Unfortunatly I don't have the boards yet for my final project, so this week I'm working on general concept and understanding of networking and communications with an Arduino UNO. Quarantine is making my page more and more looking as an Arduino tutorial, but restrictions in Finland started to lifting down, so soon we are back to intensive PRACTICAL work.

Serial communication is a communication protocol for data exchange between the curciuts by streaming the data by 1 bit at a time. The important requirement is that both devices on a serial bus are configured to use the exact same protocols. Here is the great tutorial on Serial communication.

Serial protocol rules:

  • Data bits
  • Synchronization bits: mark the beginning and end of a packet, start bit and the stop bit(s)
  • Parity bits: used as the simplest form of error detecting code
  • Baud rate: how fast data is sent over a serial line (usually 9600 bps)

A serial bus consists of just two wires - one for sending data and another for receiving. As such, serial devices should have two serial pins: the receiver, RX, and the transmitter, TX. Important to note the complementary connection RX-to-TX, TX-to-RX.

The idea is that the master can send commands to slave devices and through these commands control the output device (i.e. on-board LED), in this type of the serial connection the devices sharing the Tx and Rx input. Master/slave architecture implies that only node of the network that can issue commands is the master (PC). The network interactions at the master’s side is controlled and viewed in serial monitor. I have a board with ATTiny412 microcontroller, the LED is connected to pin 1, and can be used as an output for this board that will be controlled by the master. Unfortunately, I burned my board by connecting it in a wrong way.

Each node is going to have an ID hardcoded (it’s network address). The node waits to get a character and if maches its address, the listening mode pin is set as an output to put out a message and flash the LED and then put back to listening the pin.

Main code settings:

  • const char node = 'node ID'; // each board has it's own ID stored in node (1,2,3 etc..)
  • if (incomingByte == node); // in the listening mode node waits for the character, if it reads the character mathing it's ID from the serial it is implementing the command
  • pinMode(Rx, INPUT); // Rx is an input by default for all the nodes
  • pinMode(Rx, OUTPUT);
    mySerial.print("node");
    mySerial.println(node);
    pinMode(Rx, INPUT);
    // when writing the response, make Rx as an output for a while.

Since I understood the idea, I will continue with this assignment later.

So far, I implemented the simplest task: serial communication to control the LED (previously instead of serial monitor I was using bluetooth with MIT App inventor application.) during WEEK 12.

Node 1 - Arduino UNO


A universal asynchronous receiver/transmitter (UART) is a block of circuitry responsible for implementing serial communication. Arduino UNO has 1 UART.

  • pin 0 - RX
  • pin 1 - TX
  • ...

    Fig 1. Arduino UNO Rx, Tx pins.

    Upload the sketch on Arguino UNO, Tools:
  • Board: "Arduino Uno"
  • Choose the port
  • Programmer: "AVRISP mkll"
  • ...

    Fig 2. Arduino IDE code for NODE 1.

    Typing the node adress in the serial monitor, the node name will be dispalyed and the LED will blink.

    Node 2 - Atmega328P board


    The 2 node is my main board with ATmega328P microcontroller. The pins used in the programm:

  • pin 0 - RX
  • pin 1 - TX
  • pin 9 (LED) - 5
  • ...

    Fig 3. The board on Atmega328P and Arduino IDE code for NODE 2.

    Upload the sketch on Atmega328P, Tools:
  • Install the Device Manager in Arduino IDE: Preferences -> Additional Boards Manager URLs -> insert link ->

    https://raw.githubusercontent.com/carlosefr/atmega/master/package_carlosefr_atmega_index.json

  • Add the board: Tools -> Boards Manager -> Install "Atmega boards"
  • Board: "Atmega328P"
  • Choose the port
  • Programmer: "USBtinyISP"
  • Checking the programm on the Node 2 performance.

    Network


    Now, when the both nodes were succesfully programmed, I connected them as follows, and connect the Arduino Uno board to the computer with USB cable:

  • RX Arduino Uno (pin 0) - RX Atmega 328P (pin 0)
  • TX Arduino Uno (pin 1) - TX Atmega 328P (pin 1)
  • GND Arduino Uno - GND Atmega 328P
  • VCC(5V) Arduino Uno - VCC(5V) Atmega 328P
  • ...

    Fig 4. Connection of the nodes.

    Finally, I opened the Serial monitor in Arduino IDE: when the node number is sent, the LED on the corresponding board is blinking and the node address appears on the display:

    Files:

    Reflection

    I wanted to use the Arduino MEGA board instead of Uno, but or some reason, after uploading the sketch, nothing appeared on the serial monitor, when I typed the node number. I also got unlucky as my Attiny412 board was burned, and the Attiny44 was giving really strange outcomes till it stopped responding to my manipulations at all.