Skip to content

14. Networking and communications

Weekly Assignment Requirement

Group assignment

Send a message between two projects

Group Assignment

Individual assignment:

ATting 85 Master – ATtiny 85 Node SoftwareSerial Demo

Connect master Board TX to targent board RX and two board must be common ground.Aviod the wrong wiring, I draw the draft schemtic at my notebook first.

- MASTER- Node Test video

Master Code Example

#include <SoftwareSerial.h>    // Arduino SoftwareSerial class
int buttonState = 0;   
char ip;
SoftwareSerial mySerial(2, 1); //RX, TX
void setup() {
mySerial.begin(9600);       // Start serial processing      
delay(100);                // Give Serial class time to complete initialization.                        
}
// the loop function runs over and over again forever
void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(3);
  // print out the state of the button:
  //Serial.println(buttonState);
  delay(1);        // delay in between reads for stability
  if (buttonState == HIGH) {
  digitalWrite(4, LOW);   
  delay(100);                      
  digitalWrite(4, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(100);                      
  mySerial.println('1');
   } else {
  mySerial.println('2');
  // turn LED ON:
  digitalWrite(4, HIGH);
     }
}

Node Code Example

#include <SoftwareSerial.h>
int i=0;
SoftwareSerial mySerial(2, 1); //RX, TX

void setup() {
  mySerial.begin(9600);
  pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
}
void loop() {
  if (mySerial.available() > 0) {
   i=mySerial.read();
  digitalWrite(4, HIGH);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(3, LOW);
  }
    else {
    digitalWrite(4, LOW);
    digitalWrite(3, HIGH);
     }
}

ESP32 I2C Demo

Connect I2C OLED to ESP32-CAM Shield board .I need find the I2C address first.

ESP32 I2C address Scanner

#include <Wire.h>

void setup() {
  Wire.begin(15, 14);//Wire.begin(15, 14);//Wire.begin(SDA_pin, SCL_pin)
  Serial.begin(115200);
  Serial.println("\nI2C Scanner");
}

void loop() {
  byte error, address;
  int nDevices;
  Serial.println("Scanning...");
  nDevices = 0;
  for(address = 1; address < 127; address++ ) {
    Wire.beginTransmission(address);
    error = Wire.endTransmission();
    if (error == 0) {
      Serial.print("I2C device found at address 0x");
      if (address<16) {
        Serial.print("0");
      }
      Serial.println(address,HEX);
      nDevices++;
    }
    else if (error==4) {
      Serial.print("Unknow error at address 0x");
      if (address<16) {
        Serial.print("0");
      }
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0) {
    Serial.println("No I2C devices found\n");
  }
  else {
    Serial.println("done\n");
  }
  delay(5000);          
}


Last update: July 3, 2021