Assignment

Send a message between two projects


Projects

For this weekly group assignment we decided to test a communication between two our projects, in particular we tried to connect Dario's master board with Antonio's slave one, using an I2C Communication.
The Inter-integrated Circuit (I2C) Protocol is a protocol intended to allow multiple “slave” digital integrated circuits (“chips”) to communicate with one or more “master” chips. Like the Serial Peripheral Interface (SPI), it is only intended for short distance communications within a single device. Like Asynchronous Serial Interfaces (such as RS-232 or UARTs), it only requires two signal wires to exchange information. Via

Code

We programmed our board with those codes.

Master Code
See Dario documentation for more info about it.
            
#include <SoftwareSerial.h>
#include <TinyWireM.h>
#include <USI_TWI_Master.h>

SoftwareSerial darioSerial(0,1);

void setup(){
  darioSerial.begin(9600);
  TinyWireM.begin();
  delay (300);
}

void loop(){
  darioSerial.println("Hey I want to communicate");
  TinyWireM.requestFrom(8,1); 
  while (TinyWireM.available()) {
    int m = TinyWireM.receive(); //m is for "message"
    darioSerial.println(m);
}
  delay (600);   
  }                   
         
         


Slave Code
In this case, Antonio wrote a new code to interface his slave board to Dario's one. He used the TinyWireS library made by nadavmatalon (GitHub).
         
#include <TinyWireS.h>

int LEDPin = 4;

void setup() { 
  pinMode(LEDPin, OUTPUT);
  digitalWrite(LEDPin, HIGH);
  TinyWireS.begin(8);
  TinyWireS.onRequest(RapidBlink);
}

void loop(){
  TinyWireS_stop_check();
}

void RapidBlink() {
  TinyWireS.write(0);
  for (short i = 0; i < 5; i++) {
    digitalWrite(LEDPin, HIGH);
    delay(50);
    digitalWrite(LEDPin, LOW);
    delay(50);
}
}
         
       


Test

According to these codes, the expected behaviour is to have master to send a text message and the slave to answer it with blink led and a byte with 0 value.
The wiring we used is:
  • SCK ISP (T44) to SCK Pin (T45)
  • MOSI ISP (T44) to MOSI (SDA) Pin (T45)
  • GND ISP (T44) to GND Pin (T45)
  • VCC ISP (T44) to VCC Pin (T45)


  • And in the end a video to show our result: