This week is about network and communication.I am not an expert in electronics. So I the help of my friend. I learned from the boards they designed and decided to go for a simple board design that will help me understand networking more easily Here we have to network atleast two microcontroller boards. The commmunication can be wired or wireless.
For networking I am designing one master board and two slave boards. The master will have a button which when actiavted will cause the LED in the slave boards to glow. Below are steps for designing and fabricating the board. I'm using Attiny45 for all the boards.
The boards were made by solerding all the components promptly.
#include <TinyWireS.h>
#define LED 3
#define I2C_SLAVE_ADDR (1)
void setup() {
TinyWireS.begin(I2C_SLAVE_ADDR);
pinMode(LED, OUTPUT);
}
void loop() {
//digitalWrite(3,HIGH);
if (TinyWireS.available()){
byte data = TinyWireS.receive();
if (data == 1)
{
digitalWrite(LED, HIGH);
}
else {
digitalWrite(LED, LOW);
}
}
}
#include <TinyWireM.h>
#define device 1
#define BTN 4
#define LED 3
void setup() {
pinMode(BTN, INPUT);
pinMode(LED, OUTPUT);
TinyWireM.begin();
}
void loop() {
TinyWireM.beginTransmission(device);
int val = digitalRead(BTN);
if (val == 1)
{
TinyWireM.beginTransmission(device);
digitalWrite(LED, HIGH);
TinyWireM.send(1);
TinyWireM.endTransmission();
}
else if(val == 0)
{ TinyWireM.beginTransmission(device);
digitalWrite(LED, LOW);
TinyWireM.send(0);
TinyWireM.endTransmission();
}
}