WEEK 15
NETWORKING AND COMMUNICATIONS
For this assignment I prepared a simple practice to establish communication between my Hello world board using an ATtiny 84 and an Arduino Mega 2560. Each board has a led and a push button to work with. What this practice is about turning on the led of one board using button of the other one.
I had to use 2 programs to make this work, one program for the Hellow world board and other for the arduino Mega.
For the ATtiny 84 it was necessary to include the SoftwareSeria.h library to declare the RX and TX ports.
I had some connectivity problems at the beginning but I realized that they were due to wire that wasn't properly connected.
ATtiny 84 code:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(0, 1); // RX, TX
//Variables
int LED=8;
int BOTON=7;
int DATO=HIGH;
void setup() {
pinMode(LED, OUTPUT);
pinMode(BOTON,INPUT);
mySerial.begin(9600);
}
void loop() {
mySerial.write(digitalRead(BOTON));
delay(100);
if(mySerial.available()){
DATO=mySerial.read();
}
if(DATO==HIGH)
digitalWrite(LED,HIGH);
else
digitalWrite(LED,LOW);
}
Arduino Mega 2560
//Variables
int LED=13;
int BOTON=7;
int DATO=HIGH;
void setup() {
pinMode(LED, OUTPUT);
pinMode(BOTON,INPUT);
Serial3.begin(9600);
}
void loop() {
Serial3.write(digitalRead(BOTON));
delay(110);
if(Serial3.available()){
DATO=Serial3.read();
}
if(DATO==HIGH)
digitalWrite(LED,HIGH);
else
digitalWrite(LED,LOW);
}
Everything worked properly, however I noticed that the communication from the Hello world board to the Arduino Mega was slower than the communication on the other way around, After looking for some answers I found that it was because I'm using the internal clock of my ATtiny 84 at 1Ghz.