WEEK 13

13. Networking and Communications

  • Design and build a wired &/or wireless network connecting at least two processors


  • This week I finally managed to make my fabduinos using Daniele Ingrassia's Satshakit. It took me a lot of tries and errors to get one that worked properly. At the end the issue happened to be a batch of bricked crystals. In the same time I kept exercising with Arduino Ide and studied the I2C wire network. It is very interesting, and simple enough for me to understand and use.

    Connection scheme

    The setup

    Sketch and video

    Both sketches are based over the Wire library. You can see in the video the serial monitor reads a number starting from zero and adding 1 at every loop, when you reset the master, it start again from 0 and the slave send the new values to the serial monitor.


    Master writer

    		
    		#include < Wire.h >
    
    void setup()
    {
      Wire.begin(); // join i2c bus (address optional for master)
    }
    
    byte x = 0;
    
    void loop()
    {
      Wire.beginTransmission(4); // transmit to device #4
      Wire.write("x is ");        // sends five bytes
      Wire.write(x);              // sends one byte
      Wire.endTransmission();    // stop transmitting
    
      x++;
      delay(500);
    }
    		


    Slave reciever

    		
    #include < Wire.h >
    
    void setup()
    {
      Wire.begin(4);                // join i2c bus with address #4
      Wire.onReceive(receiveEvent); // register event
      Serial.begin(9600);           // start serial for output
    }
    
    void loop()
    {
      delay(100);
    }
    
    // function that executes whenever data is received from master
    // this function is registered as an event, see setup()
    void receiveEvent(int howMany)
    {
      while (1 < Wire.available()) // loop through all but the last
      {
        char c = Wire.read(); // receive byte as a character
        Serial.print(c);         // print the character
      }
      int x = Wire.read();    // receive byte as an integer
      Serial.println(x);         // print the integer
    }
    

    Two Satshakits (fabduino) with I2C wire connection

    Files available here

  • Master sketch
  • Slave sketch