Understanding Networking and Communication
WEEK14: NETWORKING AND COMMUNICATION
ASSIGNMENTS:
Individual assignment
- Design and build a wired &/or wireless network connecting at least two processors
Group assignment
- Send a message between two projects
- Last week we have learned how to establish connection and communication between Input and output device via interface, but with same processor/microcontroller or processor.
- This week's objective is to send/receive data from input/output devices which is installed with two different micro-controllers.
- For this to happen one multiple microcontrollers need to be connected as network.
- After referring some of tutorial I understood that this communication between boards (micro controllers) can happen by Serial communication, I2C or SPI.
- Very good tutorial to understand serial communication one can refer is sparkfun tutorial
- One can start this with what are requirements to create such network to share data such as common communication protocol between boards.
STEP01: Exploring types of communication for micro controllers
- Serial communication: Serial communication is interlinking circuits by means of sending/receiving data one bit at a time, ow hole bunch of data at a time (Parallel).
- Very good tutorial can be found here from Sparkfun tutorial on serial communication
- SERIAL PERIPHERAL INTERFACE(SPI) : Serial peripheral interface uses separate clock and data lines, along with a select line to choose the device you wish to talk to
- Very good tutorial can be found here from Sparkfun tutorial on serial communication
- INTER-INTEGRATED CIRCUIT(I2C) : I2C is somewhat same as SPI, but it can use multi-master and 1008 slave (circuit boards) to communicate with 2 wire.
- Very good tutorial can be found here from Sparkfun tutorial on serial communication
STEP02: Defining application I want to do
- As networking application I have decided to do task that, I will send signal by wireless from the application I have developed and pass that signal to 3 different boards.
- So, for this week I am going to use which I have design and fabricated in week 7, and I will provide input signal from application which I have developed in week 13
STEP03: Program the boards for Serial communication
- Now in order to send data by serial communication, I have to program my boards separately, and upload the code individually.
- In both the codes my variables will remain same but the value will be changed.
- So, I started with defining Rx pin with pin number 2 of my board. And set mySerial with Rx and Tx pins.
- After that I store value of character 'a' as number 1, and wrote the if else loop to perform required task or here to make LED low and high.
#include <SoftwareSerial.h>
#define RxD 2
#define TxD 0
#define DEBUG_ENABLED 1
#define LED_A 4
SoftwareSerial mySerial(RxD,TxD);
void setup() {
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
mySerial.begin(9600);
pinMode(LED_A,OUTPUT);
}
void loop() {
if(mySerial.available()>0)
{
int a = mySerial.read();
if (a == 1)
{
digitalWrite(LED_A,HIGH);
}
else
{
digitalWrite(LED_A,LOW);
}}}
- Program for another board will remain almost same with change in LED value low and high under
#include <SoftwareSerial.h>
#define RxD 2
#define TxD 0
#define DEBUG_ENABLED 1
#define LED_A 4
SoftwareSerial mySerial(RxD,TxD);
void setup() {
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
mySerial.begin(9600);
pinMode(LED_A,OUTPUT);
}
void loop() {
if(mySerial.available()>0)
{
int a = mySerial.read();
if (a == 0)
{
digitalWrite(LED_A,HIGH);
}
else
{
digitalWrite(LED_A,LOW);
}}}
STEP05: Wiring connection for serial network
- After uploading code in boards by FabISP, I have made wiring connection between boards by serial bus.
- I have used two FTDI cables to supply power to boards and bluetooth module.
- VCC, GND and SCK (Rx) connections are in common serial.
STEP05: Test network communication between boards
- Once boards are ready I have connected them in above pattern along with bluetooth module.
- Also I have powered up boards and bluetooth by separate FTDI cables.
- Once powered up, I have tested the network communication with application which I have developed in week 13.
- In below video working functionality can be tested as all boards in network.
COMMUNICATION BETWEEN BOARDS WITH ADDRESS CODE
- In order to make communication between my boards, I have used one master and two slave board. Whereas my master board will send digital data by means of switch i.e. High and Low.
- For communication I have taken reference from Jari Uusitalo, who has used node to transmit and receive data, by closing Rx channel in nodes by turning it into input
- Basically here, communication happens by sending specific call to particular addressed board, and that replies back accordingly.
- For programming master board I have used below code with input as switch and using SCK of master board as Tx pin. Here I am addressing board with character 1 and 2.
#define B
#include<SoftwareSerial.h>
SoftwareSerial ms(1,2); // rx , tx
void setup()
{
pinMode(2,OUTPUT);
pinMode(1,INPUT);
pinMode(4,OUTPUT);
pinMode(B,INPUT);
ms.begin(9600);
}
void loop()
{
if( digitalRead(B) == LOW)
{
digitalWrite(4,HIGH);
//digitalWrite(1,LOW);
ms.write('1');
}
else if( digitalRead(B) == HIGH)
{
digitalWrite(4,LOW);
ms.write('2');
}
}
- For programming Slave board 1, I have used below code by addressing value of board as character 1, and transmitting signal by SCK pin and receiving from MISO pin.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(1, 1); // RX, TX
int node = '1'; // network address
const int ledPin1 = 4;
int incomingByte;
void setup() {
mySerial.begin(9600);
pinMode(ledPin1, OUTPUT);
pinMode(1, INPUT);
}
void loop() {
if (mySerial.available() > 0)
{
incomingByte = mySerial.read();
if (incomingByte == node)
{
digitalWrite(ledPin1, HIGH);
pinMode(1, OUTPUT); // open line to write
mySerial.println(node);
pinMode(1, INPUT);
}
else
{
digitalWrite(ledPin1, LOW);
}
}}
- Programming second slave board is just same as above, just the addressing of this board will change to character 2.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(1, 1); // RX, TX
int node = '2'; // network address
const int ledPin1 = 4;
int incomingByte;
void setup() {
mySerial.begin(9600);
pinMode(ledPin1, OUTPUT);
pinMode(2, INPUT);
}
void loop() {
if (mySerial.available() > 0)
{
incomingByte = mySerial.read();
if (incomingByte == node)
{
digitalWrite(ledPin1, HIGH;
pinMode(2, OUTPUT); // open line to write
mySerial.println(node);
pinMode(2, INPUT);
}
else
{
digitalWrite(ledPin1, LOW);
}
}}
- Once programs have been uploaded successfully in Master and Slave board, I have checked functionality of communication as below by connecting boards as shown in wiring diagram.
- Here I have used board network connection hub made by fellow fab academy student Adhitya and designed by Jari Uusitalo
- In below video communication between board can be seen as master board input is given by switch. Also the values of responsive communication can be seen in serial monitor
- I am attaching here original files for this week as package, which includes program files which I have used for network communication.
- This can be downloaded from here
INDIVIDUAL CONTRIBUTION TO GROUP WORK
- For this week's group work we have decided to establish communication between two board, and use IR sensor as input device.
- As board we have used fellow fab academy students' board. I played major role in programming these board for communication.
- For programming I have used serial communication over two board as pin number 8 and 9 I used as input and output.
Click here for documentation on communication over two project on lab website
Go to Week 15
Go to Weekly work page