Networking and communications

For this week the assigment was design and build a wired and/or wireless network connecting at least two processors

Big fail

In the begining of this assigment I have considered to make bridges and nodes for I2C communications. I have downloaded the files from fabacademy, but when I try to program the circuits, all of them have issues to upload .hex. So I reconsidered change the circuits by fabduinos. However, we kept I2C communication.


New I2C communication

The main idea is abstracted in the right image. The slave will send a numbers between 0 and 127 when the master request communication, it will get the value to transform in angle of servomotor. The slave address is 8 and send one byte. This idea become real when I connect two fabduinos through SDA/SCL pins. In master board connects a servomotor. The next images show this hardware implementation. Additionally, we connect fabduino with FTDI wire and AVRISP. The power supply is the same for boths kits. You can donwload the source files here



Master code

#include <Wire.h>
#include <Servo.h>

Servo myservo;  // create servo object to control a servo


void setup() {
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output

  myservo.attach(7);
}

void loop() {
  Wire.requestFrom(8, 1);    // request a byte from slave device #8

  while (Wire.available()) { // slave may send less than requested
    char c = Wire.read(); // receive a byte as character
    Serial.print(int(c));         // print the character
    myservo.write(c);

  }
  Serial.println("");
  delay(1500);
}

Slave code

#include <Wire.h>

void setup() {
  Wire.begin(8);                // join i2c bus with address #8
  Wire.onRequest(requestEvent); // register event
}

void loop() {
  delay(1500);
}

// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {
  char c = random(0,127);
  Wire.write(c); // respond with message of one byte
  // as expected by master
}

Finally!