13. Networking and communications – Group Kuriyama¶
This is group assignment page of Computer-controlled cutting (Kuriyama Student) :
Group assignment¶
- Send a message between two projects
What we’ve done this week¶
We followed Rodrigo Shiordia assignment.
But somehow it didn’t turn on the lights with this way.
So tried one light on first
It didn’t work first because I didn’t connect the GND from light.
Here is how to work a single light.
Now connect 2 PCB to Arduino
Arduino (Master board)
#include <Wire.h>
void setup() {
Serial.begin(9600);
Wire.begin(); // join i2c bus (address optional for master)
pinMode(0, OUTPUT);
}
void loop() {
while (Serial.available()) {
char c = Serial.read();
if (c == 'H') {
Wire.beginTransmission(9);
Wire.write('H');
Wire.endTransmission();
Serial.println("writing to address 9!");
}
else if (c == 'L') {
Wire.beginTransmission(9);
Wire.write('L');
Wire.endTransmission();
Serial.println("writing to address 9!");
}
else if (c == 'G') {
Wire.beginTransmission(8);
Wire.write('G');
Wire.endTransmission();
Serial.println("writing to address 8!");
}
else if (c == 'K') {
Wire.beginTransmission(8);
Wire.write('K');
Wire.endTransmission();
Serial.println("writing to address 8!");
}
}
}
Shiowaki board
#include <Wire.h>
byte own_address = 9;
void setup() {
Wire.begin(own_address);
Wire.onReceive(receiveEvent);
pinMode(0, OUTPUT);
digitalWrite(0, LOW);
}
void loop() {
}
void receiveEvent(int howMany) {
while (Wire.available()) {
char c = Wire.read();
if(c=='H'){
digitalWrite(0,HIGH);
}
else if(c=='L'){
digitalWrite(0,LOW);
}
}
}
Nose PCB is Red light On with “H”, Off with “L”
Suzuki board
#include <Wire.h>
byte own_address = 8;
void setup() {
Wire.begin(own_address);
Wire.onReceive(receiveEvent);
pinMode(0, OUTPUT);
digitalWrite(0, LOW);
}
void loop() {
}
void receiveEvent(int howMany) {
while (Wire.available()) {
char c = Wire.read();
if(c=='G'){
digitalWrite(0,HIGH);
}
else if(c=='K'){
digitalWrite(0,LOW);
}
}
}
Suzuki PCB is Green light On with “G”, Off with “K”
Red light (from Shiowaki board) and Green light (from Suzuki board) are on and off.
Links to Files and Code¶
- Master code for Arduino[.ino]
- Slave code for Shiowaki’s board[.ino]
- Slave code for Suzuki’s board[.ino]
Appendix¶
Last update:
May 5, 2022