Skip to content

14. Networking and communications

second try with two Attiny 1614-SSFR boards

process to make a board => see week 5






loading the code


To upload the code I pay attention to this settings.



board setting


Since the ftdi interface is occupied, and thus also rx and tx, I lay down on the Arduino pin 0 and pin 1 via software serial to further “rx and tx” interfaces.
This procedure allows me to send the data to the serial monitor via ftdi.

In addition, the ldr on board 1 measures the light intensity and transmits the data to board 2, which switches on an led after a certain level of darkness.


sender code

//sender board
#include <SoftwareSerial.h>

#define ARDUINO_ID 1
#define MESSAGE "Hello I am Arduino "

boolean messageReceived;

SoftwareSerial softwareSerial(0, 1); // RX, TX

const int sendPin = 10;

const int ldrPin = 9;

void setup() {

Serial.begin(4800);
  softwareSerial.begin(4800);
  messageReceived = false;

pinMode(sendPin, OUTPUT);

pinMode(ldrPin, INPUT);

}

void loop() {
softwareSerial.print(MESSAGE);
  softwareSerial.println(ARDUINO_ID);

  Serial.print("Sent message: ");
  Serial.print(MESSAGE);
  Serial.println(ARDUINO_ID);

  if(softwareSerial.available()){

    messageReceived = true;

    while( softwareSerial.available()){

      if(messageReceived){

        Serial.print("Received message: ");
        messageReceived = false;

      }

      Serial.write(softwareSerial.read());

    }

  }

  delay(2000);

int ldrStatus = analogRead(ldrPin);

if (ldrStatus <= 500) {

digitalWrite(sendPin, HIGH);

Serial.print("SEND => Its DARK => Turn on the LED : ");

Serial.println(ldrStatus);

} else {

digitalWrite(sendPin, LOW);

Serial.print("SEND => Its BRIGHT => Turn off the LED : ");

Serial.println(ldrStatus);

}

}

receiver code

//receiver board
#include <SoftwareSerial.h>

#define ARDUINO_ID 2
#define MESSAGE "Hello I am Arduino "

boolean messageReceived;

SoftwareSerial softwareSerial(0, 1); // RX, TX
const int ledPin = 10;

const int receivePin = 9;

void setup() {
Serial.begin(4800);
  softwareSerial.begin(4800);
  messageReceived = false;


pinMode(ledPin, OUTPUT);

pinMode(receivePin, INPUT);

}

void loop() {
softwareSerial.print(MESSAGE);
  softwareSerial.println(ARDUINO_ID);

  Serial.print("Sent message: ");
  Serial.print(MESSAGE);
  Serial.println(ARDUINO_ID);

  if(softwareSerial.available()){

    messageReceived = true;


    while( softwareSerial.available()){

      if(messageReceived){

        Serial.print("Received message: ");
        messageReceived = false;

      }

      Serial.write(softwareSerial.read());

    }

  }

  delay(2000);
int receiveStatus = analogRead(receivePin);

if (receiveStatus >= 500) {

digitalWrite(ledPin, HIGH);

Serial.print("RECEIVER => Its DARK => Turn on the LED : ");

Serial.println(receiveStatus);

} else {

digitalWrite(ledPin, LOW);

Serial.print("RECEIVER => Its BRIGHT => Turn off the LED : ");

Serial.println(receiveStatus);

}

}

For this assignment I have changed and mixed some codes, which I have taken from Daniele Ingrassia’s part of the local lecture and from the website create.arduino.cc.


27.6.2021 Upon further inspection I realized, that I am sending the address but the receiver is not really verifying if the message is for him.
Upon reception the receiver should check if(ARDUINO_ID == 2) {do something}
else {do nothing}
Unfortunately my programmer and one of my boards stopped working . I know that my code is not perfect, but it would be a big effort to fix it right now.

28.6.2021 I made another two sketches for correcting the “ID-Issue”.

primary code__

#include <SoftwareSerial.h>

#define ARDUINO_ID 1
SoftwareSerial softwareSerial(6, 7); // RX, TX

void setup() {
  Serial.begin(4800);
  softwareSerial.begin(4800);
}
void loop() {

  softwareSerial.println(2); // sending message to Arduino 2
  Serial.print("Sent message to Arduino 2");
  delay(3000);
}

secondary code__

#include <SoftwareSerial.h>
#define ARDUINO_ID 2
int receivedId;
SoftwareSerial softwareSerial(6, 7); // RX, TX

void setup() {
  Serial.begin(4800);
  softwareSerial.begin(4800);
}

void loop() {
  softwareSerial.println(ARDUINO_ID);
  if(softwareSerial.available()){
    receivedId = softwareSerial.parseInt();
    if(receivedId == ARDUINO_ID)
      Serial.println("I received a message from Arduino 1!");
       else
       Serial.println("Message discarded!");
  }
  delay(3000);
}

So now, if Arduino1 sends a message to Arduino2, it responds “I received a message from Arduino 1!”.
If the ID is changed to anything else e.g. 3, it responds “Message discarded!”.

Here is the block diagram for the secondary code:


code2flow.com/.


first try with a ATtiny44-SSU and a ATMEGA88thin

For this assignment I use the boards that I have already presented in input and output devices.

load the files and connect the boards


First I upoad the sketches on the boards.



Then I connect the boards so that they can communicate with each other. Since I want to read the data on the serial monitor to see whether the communication is working, I route the rx and tx to pin 6 and pin 7 on the receiver board.
Now I can read out the serial monitor directly from the rx and tx on the receiver board.




On this pins I connected the boards for the communication.



Here you can see that the receiver board receives signals from the sender board and forwards them to the receiver board, which it then displays in the serial monitor.


Codes

Ultrasonic board / sender board

#include <SoftwareSerial.h>
SoftwareSerial mySerial(4, 5); // RX, TX



int ledPinrot=0;
int ledPingruen=1;
int trigger=7;                               
int echo=8;                                  
long dauer=0;                                                                        
long entfernung=0;                         

void setup()
{

    mySerial.begin(9600);
    mySerial.println("Board 1");
    pinMode(trigger, OUTPUT);               
    pinMode(echo, INPUT);

}

void loop()
{

    digitalWrite(trigger, LOW);              

    delay(5);                             
    digitalWrite(trigger, HIGH);             

    delay(10);                               
    digitalWrite(trigger, LOW);              

    dauer = pulseIn(echo, HIGH);             

    entfernung = (dauer/2) / 29.1;           


if (entfernung >= 500 || entfernung <= 0)
{
    mySerial.println("canĀ“t read");
    digitalWrite(ledPinrot, HIGH);   
 delay(1000);
}
else
{
    mySerial.print(entfernung);
    mySerial.println(" cm  Board 1");
    digitalWrite(ledPinrot, LOW);
    digitalWrite(ledPingruen, HIGH);



}
delay(1000);
}

receiver board

#include <SoftwareSerial.h>



SoftwareSerial mySerial(7,6); // RX, TX neu
long entfernung=0;  
long dauer=0;

void setup()
{
    Serial.begin(9600);
    mySerial.begin(9600);
    Serial.println("Board 2 - I am receiving data from board 1");
}

void loop()
{

if(mySerial.available())
Serial.write(mySerial.read());

delay(100);
}

group assignment

Networking Group Assignment

files

Board_with_a_ATtiny1614.kicad_pcb

Board_with_a_ATiny1614.kicad_sch

sonarboard_with_a_ATtiny44-SSU_eagle.brd

sonarboard_with_a_ATtiny44-SSU_eagle.sch

Board_with_a_ATMEGA88.BRD/Eagle

Board_with_a_ATMEGA88.sch/Eagle


Last update: June 29, 2021