Skip to content

Networking and Communications

Group assignments

  • send a message between two projects

My group assignments


Individual Assignments

  • design, build, and connect wired or wireless node(s) with network or bus addresses and local input &/or

Have you answered these questions?

  • Linked to the group assignment page
  • Documented your project and what you have learned from implementing networking and/or communication protocols.
  • Explained the programming process(es) you used.
  • Ensured and documented that your addressing for boards works
  • Outlined problems and how you fixed them.
  • Included design files (or linked to where they are located if you are using a board you have designed and fabricated earlier) and original source code.
  • Included a ‘hero shot’ of your network and/or communications setup

PC working environment

  • PC: MacBook Pro(16-inch,2019)
  • OS: Sonoma 14.7.2
  • Terminal: zsh

hero video

ESP-NOW is used for wireless communication.

alt text

ESP-NOW

This time we tried using two XIAO ESP32C3s.

  • Pinout alt text

1.DFplayer

  • Pinout alt text

1.0 connection

The instructor told me to connect the power from the receiver when wiring.

  • sender

alt text

  • receiver

alt text

sprogramming

I asked ChatGPT the following question

SP-NOW to communicate wirelessly and play the sound on the receiving side DFplayer.
Sound when the value of the piezo element exceeds 1500.

IDE : Arduino IDE 
Board : XIAO ESP32C3(both transmitter and receiver)

input devece : piezo device (connect to A0 on transmitter side)
output devece : DFplayer (connect to TX and RX on the receiving side)

MAC address 
- 68:67:25:EC:27:B4 (transmitting side)
- 58:CF:79:EC:63:34 (receiving side)

Please write a program with the above conditions.

Sender(XIAO ESP32C3)

#include <WiFi.h>
#include <esp_now.h>

#define PIEZO_PIN A0  // Pin where the piezo sensor is connected

// MAC address of the receiver (peer device)
uint8_t peerAddress[] = {0x58, 0xCF, 0x79, 0xEC, 0x63, 0x34};

// Structure to hold the data to be sent
typedef struct struct_message {
  int piezoValue;
} struct_message;

// Message data
struct_message myData;

void setup() {
  // Initialize Serial Monitor
  Serial.begin(115200);

  // Initialize Wi-Fi (required for ESP-NOW)
  WiFi.mode(WIFI_STA);
  esp_now_init();

  // Set up the receiver's MAC address as a peer
  esp_now_peer_info_t peerInfo;
  memcpy(peerInfo.peer_addr, peerAddress, 6);
  peerInfo.channel = 0;  // Auto channel selection
  peerInfo.encrypt = false;  // No encryption
  esp_now_add_peer(&peerInfo);
}

void loop() {
  // Read the value from the piezo sensor
  int piezoValue = analogRead(PIEZO_PIN);

  // Set the value in the data to be sent
  myData.piezoValue = piezoValue;

  // Send the data to the receiver
  esp_now_send(peerAddress, (uint8_t *)&myData, sizeof(myData));

  // Debug output
  Serial.print("Piezo Value: ");
  Serial.println(piezoValue);

  // Send data every 300 milliseconds
  delay(300);
}

Receiver(XIAO ESP32C3)

##include <WiFi.h>
#include <esp_now.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>

#define RX_PIN 20  // RX pin for DFPlayer Mini
#define TX_PIN 21  // TX pin for DFPlayer Mini

// Structure of the received data
typedef struct struct_message {
  int piezoValue;
} struct_message;

// Variable to store received data
struct_message receivedData;

SoftwareSerial mySoftwareSerial(RX_PIN, TX_PIN);  // SoftwareSerial for DFPlayer Mini
DFRobotDFPlayerMini myDFPlayer;  // Instance of DFPlayer Mini

void setup() {
  // Initialize Serial Monitor
  Serial.begin(115200);

  // Initialize DFPlayer Mini serial communication
  mySoftwareSerial.begin(9600);
  if (!myDFPlayer.begin(mySoftwareSerial)) {
    Serial.println("DFPlayer Mini initialization failed!");
    while (true);
  }
  Serial.println("DFPlayer Mini online.");

  // Initialize Wi-Fi (required for ESP-NOW)
  WiFi.mode(WIFI_STA);
  esp_now_init();

  // Set up sender's MAC address as peer
  uint8_t peerAddress[] = {0x68, 0x67, 0x25, 0xEC, 0x27, 0xB4};
  esp_now_peer_info_t peerInfo;
  memcpy(peerInfo.peer_addr, peerAddress, 6);
  peerInfo.channel = 0;  // Auto channel selection
  peerInfo.encrypt = false;  // No encryption
  esp_now_add_peer(&peerInfo);

Result

Wireless communication appears to be working well, but the value detected by the piezoelectric element may be too small to respond. I thought it was necessary to consider how much to set the value from now on, taking resistance and other factors into consideration.

impressions

  • I thought wireless could be used for my FINAL project.
  • I would need to find out how many piezo element values to use.