Networking and communication

Goal of this week

design, build, and connect wired or wireless node(s) with network or bus addresses

Assignement Work

For this week I've decided to created the I2c connection between two board I've done in the previous week: input and output:

with this connection I need to have at least a master and a slave boards:

I2C connection

The I2C manual is visibile in the schedule of the course: in it there are everything about this kind of connection in details. I also found this scheme useful for the building of my connection:

The main concept of the i2c networking is the link between the master's SDA and SCL pins and the slave's ones.

So I find the two pin position in the attiny44 and 45 in order to connect the two board(one has the attiny44 and the other has the 45 one).

attiny45:

attiny44:

The next step in this work is the programming the master and slave : the master will ask something to the slave and the slave answer with something:the main aim of the networking is that of exchange information between two or more board:

To compile this two program I have included the libraries TinyWireM and TinyWireS because the stantard library Wire doesn't work with the bootloader of attiny microcontrollers.

with this master and slave I've communication but I have problem of conversion with my number int :

IMG_6205 from Marco Cialone on Vimeo.

to solve this problem I have done a small modification of my master and slave and it works:

this is the master code:

//Master
#include <SoftwareSerial.h>
#include <TinyWireM.h>
#include <USI_TWI_Master.h>
SoftwareSerial ATSerial(1,2); // RX, TX 
 void setup() {
 TinyWireM.begin();
 ATSerial.begin(9600);
 }


void loop() {
 // put your main code here, to run repeatedly:
 TinyWireM.requestFrom(3,1);
 ATSerial.print("The other has written:");
 while(TinyWireM.available()){
 int a= TinyWireM.receive();
 ATSerial.print(a);
 }
 ATSerial.println();
 delay(1000);
 }

this is the slave code:

 #include <TinyWireS.h>
 //#include <usiTwiSlave.h>
 String variabi = "2342";
 int variabi_int = variabi.toInt();     
 void setup() {
 // put your setup code here, to run once:
 TinyWireS.begin(3);
 TinyWireS.onRequest(invia);
 }
 void loop() {
 // put your main code here, to run repeatedly:
 delay(1000); 
 }
 void invia(){
 TinyWireS.send(variabi_int);
 }

The final result is this :

IMG_6206 from Marco Cialone on Vimeo.

Group assignement

For the group assignement I've done a connection SPI with Giada:

the master's code is this :

#include <SoftwareSerial.h>       
#define rxPin 1
#define txPin 0

SoftwareSerial serial(rxPin,txPin);

void setup() {
pinMode (rxPin,INPUT);
pinMode (txPin,OUTPUT);
serial.begin(9600);
}

void loop() {

serial.print(1);
delay(2000);
serial.print(2);
delay(2000);
}

the slave's code:

#include <SoftwareSerial.h>
#define rxPin 0
#define txPin 1
#define ledPin 5
int rxbuffer
SoftwareSerial serial(rxPin,txPin);
void setup(){
pinMode(rxPin,INPUT);
pinMode(txPin,OUTPUT);
pinMode(ledPin,HIGH);
digitalWrite(ledPin,HIGH);
serial.begin(9600);
}

void loop(){
rxbuffer=serial.read();
if(rxbuffer=='1'){
digitalWrite(ledPin,LOW);
delay(200);
digitalWrite(ledPin,HIGH);
delay(200);
digitalWrite(ledPin,LOW);
delay(200);
digitalWrite(ledPin,HIGH);
delay(200);
digitalWrite(ledPin,LOW);
delay(200);

else if(rxbuffer=='2'){
  digitalWrite(ledPin,HIGH);

  }
delay(1000)
}
}

IMG_6197 from Marco Cialone on Vimeo.

second group assignement

We have also done the I2C connection together with our hello board as a slaves and an other hello board as a master:

my slave's code:

    #include <TinyWire.h>
    #include <twi.h>


    #define led_pin 8

    void setup() {
      // config led_pin as Output for driving an LED
      pinMode(led_pin, OUTPUT);

      // config TinyWire library for I2C slave functionality
      TinyWire.begin(12);
      // sets callback for the event of a slave receive
      TinyWire.onReceive( onI2CReceive );
    }

    void loop() {

    }

    /*
    I2C Slave Receive Callback:
    Note that this function is called from an interrupt routine and shouldn't take long to execute
    */
    void onI2CReceive(int howMany){
      // loops, until all received bytes are read
      while(TinyWire.available()>0){
        if(TinyWire.read()=='1') {
          digitalWrite(led_pin, HIGH);
        } else {
          digitalWrite(led_pin, LOW);
        }
      }
    }

the another slave as the same code with the led_pin 7 and the master code is this:

 #include <Wire.h>

 void setup() {
 Wire.begin(); // join i2c bus (address optional for master)
 delay(20);
 } 
void loop() {
Wire.beginTransmission(8); // transmit to device #8
Wire.write(1);
Wire.endTransmission();    // stop transmitting
delay(2000);
Wire.beginTransmission(12);
Wire.write(1);
Wire.endTransmission();
delay(2000);
Wire.beginTransmission(8); // transmit to device #8
Wire.write(0);
Wire.endTransmission();    // stop transmitting
delay(2000);
Wire.beginTransmission(12);
Wire.write(0);
Wire.endTransmission();
delay(2000);
}

the final result is this:

HDBE5001 from Marco Cialone on Vimeo.