Edward Octavio Muñoz Sandoval                                                                                                                   Contact: edw_ard0@hotmail.com

Week 15 Assignment: Networking and Communications

        1.-Design and build a wired &/or wireless network connecting

          at least two processors

Connection

For this assignment I used my attiny developed in week 6 and an Arduino one.

 

I used the serial communication to send a byte from the Arduino one to my attiny, the connection diagram is shown in the picture below:

 

Code Arduino one

The code in the Arduino one is very simple, just send a "HIGH" or a "LOW" signal to the Attiny through the serial communication with 5 seconds of delay between each signal.

 

 

 

 

#include <SoftwareSerial.h>

 

//Variables

  int BUTTON=7;

 

void setup()

{

  pinMode(BUTTON,INPUT);

  Serial.begin(9600);

}

 

void loop()

{

 Serial.write(HIGH);

 delay(5000);

 Serial.write(LOW);

 delay(5000);

}

 

Code Attiny

The code in the Attiny is similar to the code developed in week 11 assignment, which switch on and off a led with a delay like a blink code. The delay depends on the value read from the potentiometer, this process is done by taking the value of the analog input from the potenciometer and inserting it as a delay for the led.

 

To this point I have not explained where the serial communication works in the attiny.

 

In the code there is an "IF" statement that ask "IF the "DATO" read from the Arduino one is HIGH, then blink the led (like explained above), but if "DATO" is not HIGH then turn of the led"

 

 

 

#include <SoftwareSerial.h>

SoftwareSerial mySerial(5, 8); // RX, TX

 

  int DATO=HIGH;

  int sensorPin = A0;    // select the input pin for the potentiometer

  int ledPin = 6;      // select the pin for the LED

  int sensorValue = 0;  // variable to store the value coming from the sensor

 

void setup() {

   pinMode(ledPin, OUTPUT);

  mySerial.begin(9600);

}

 

void loop() {

  // read the value from the sensor:

  sensorValue = analogRead(sensorPin);

  // turn the ledPin on

  if (DATO==HIGH) //ask if the arduino one button is on

{

  digitalWrite(ledPin, HIGH);

  // stop the program for <sensorValue> milliseconds:

  delay(sensorValue);

}

  // turn the ledPin off:

  digitalWrite(ledPin, LOW);

  // stop the program for for <sensorValue> milliseconds:

  delay(sensorValue);

 if(mySerial.available())

 { DATO=mySerial.read();}

}

Results

The way to probe my communication was working, was to disconnect RX and TX when the variable "DATO" was in HIGH so the led never stops blinky.

Second network practice

I design and produce another board for this assignment, I used the Atmega328 with the ISP pins integrated in the board, 2 buttons (one for reset and one for input), 16 Mhz crystal and one led int he pin 13.

Following the same process of electronic design, I mil the board in the Modela machine.

Cut

Engrave

Pads

Then I weld the components in the board

Attiny Code

I programmed the attiny with a new code that turn on the led when in the serial communication read a "high" and send to the atmega a high or low depending of the state of the button.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(5, 8); // RX, TX

 

  int DATO=HIGH;

  int buttonPin = 10;    // select the input pin for the button

  int ledPin = 6;      // select the pin for the LED

  bool buttonState = LOW;

 

 

void setup() {

   pinMode(ledPin, OUTPUT);

  mySerial.begin(9600);

}

 

void loop() {

  // read the value from the button:

 

  buttonState=digitalRead(buttonPin);

 

  if (buttonState==HIGH)

  {

  mySerial.write(HIGH);

  }

  else if (buttonState==LOW)

  {

  mySerial.write(byte(0));

  }

  if (DATO==HIGH) //ask if the arduino one button is on

{

  digitalWrite(ledPin, LOW);

  // trun the ledPin on

}

else

{digitalWrite(ledPin, HIGH);

  // trun the ledPin off

  }

 if(mySerial.available())

 { DATO=mySerial.read();}

 delay(100);

}

Atmega Code

The atmega code is the same as the attiny, the microcontroller read a high or low and turn the led on or off and send the statte of the button to the attiny.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(5, 8); // RX, TX

 

  int DATO=HIGH;

  int buttonPin = 10;    // select the input pin for the button

  int ledPin = 6;      // select the pin for the LED

  bool buttonState = LOW;

 

 

void setup() {

   pinMode(ledPin, OUTPUT);

  mySerial.begin(9600);

}

 

void loop() {

  // read the value from the button:

 

  buttonState=digitalRead(buttonPin);

 

  if (buttonState==HIGH)

  {

  mySerial.write(HIGH);

  }

  else if (buttonState==LOW)

  {

  mySerial.write(byte(0));

  }

  if (DATO==HIGH) //ask if the arduino one button is on

{

  digitalWrite(ledPin, LOW);

  // trun the ledPin on

}

else

{digitalWrite(ledPin, HIGH);

  // trun the ledPin off

  }

 if(mySerial.available())

 { DATO=mySerial.read();}

 delay(100);

}

Results

After several tries finally I could communicate the attiny and the attmega, the probe is shown in the next video: