Skip to content

Embedded Networking and Communications

Group assignment requirements

The group assignment for this week is the following:
- Send a message between two projects
- Document your work to the group work page and reflect on your individual page what you learned

FAQ

What does “two projects” mean in the group assignment
Answer: You need to send a message between any combination of boards, computers and/or mobile devices, including commercial board(s). You need to write code that sends and/or receives the message in question.

Communication method

Select your communication method: Serial Communication –> (I2C Protocol) . I2C stands for Inter-Integrated Circuit. It is a bus interface connection protocol incorporated into devices for serial communication. –> It uses only 2 bi-directional open-drain lines for data communication called SDA and SCL.

A picture / diagram showcasing the communication method

Node 1

Arduino Board connected to it a Potentiometer –> This Potentiometer are connected to one of the Analog pins to be sent over wire to another system.

A picture of "project" 1

code

#include <Wire.h>
#define V A0
int x = 0;
void setup() {
  // Start the I2C Bus as Master
  Wire.begin(); 
  pinMode(V,INPUT);
}
void loop() {
  x=analogRead(V);delay(10);
  x=map(x,0,1023,0,255);
  Wire.beginTransmission(9); // transmit to device #9
  Wire.write(x);              // sends x 
  Wire.endTransmission();    // stop transmitting

}

This is the master code, I want here to establish an I2C communication to Client connected on the address (9).

I want to send to the client the data of a potentiometer { connected on the analog pin (A0)}

The data coming from pin (A0) are stored in the variable (X), then the data of the Variable (X) are mapped to be between (0 and 255)

Conclusion

The data sent to the Address (9) are mapped from (0 , 1024) to (0 , 255) so a digital pin can demonstrate them easily.

Node 2

LED connected to Arduino which receives data from another system to control the brightness of the LED.

A picture of "project" 1

code

#include <Wire.h> //Wire library which contains the I2C protocol 
#define LED 6 //LED is on PWM pin to control the brightness 

int x = 0;
void setup() {
  // Define the LED pin as Output
  pinMode (LED, OUTPUT);
  // Start the I2C Bus as Slave on address 9
  Wire.begin(9); 
  // Attach a function to trigger when something is received.
  Wire.onReceive(receiveEvent);
}
void receiveEvent(int bytes) {
  x = Wire.read();    // read one character from the I2C
}
void loop() {
  analogWrite(LED,x); //To output different values between 0 and 255 
  delay(10);
}

This is the client code which is connected to I2C communication bus and having an Address (9).

The MCU is connected to LED on the PIN (6).

The data received from the I2C bus are saved in the Variable (X) and then are reflected on the digital PIN (6) which will be translated as the brightness of the LED connected on this PIN.

Conclusion

The data received are the brightness of the LED connected on the PIN (6).

Result

p1 + p2

In this video We can see the master is sending the (potentiometer) reading to the client through I2C bus and the client is translating the values as the brightness for the LED connected to PIN (6).