hey guys, im trying to get these boards to communicate with each other but im getting no where with it.
the project is split into 2 parts, a master board and a slave board. (which when i eventually get them talking to each other i need to expand to 2 master boards that sync the led on/off state together and expand the slave boards to 6)
anyway, here is the master code
#include <esp_now.h>
#include <WiFi.h>
#include <esp_wifi.h>
#define BUTTON_PIN 4
uint8_t slaveMAC[] = {0xB8, 0x50, 0xD8, 0x84, 0x44, 0xFC};
bool ledsOn = false;
bool lastButtonState = HIGH;
bool buttonHandled = false;
uint32_t lastDebounce = 0;
const uint16_t DEBOUNCE_MS = 50;
esp_now_peer_info_t peerInfo;
void onSent(const wifi_tx_info_t *info, esp_now_send_status_t status) {
Serial.println(status == ESP_NOW_SEND_SUCCESS ? "ACK received" : "ACK not received");
}
void setup() {
Serial.begin(115200);
delay(1000);
pinMode(BUTTON_PIN, INPUT_PULLUP);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
Serial.print("Master MAC: ");
Serial.println(WiFi.macAddress());
if (esp_now_init() != ESP_OK) {
Serial.println("ESP-NOW init failed");
while (1);
}
esp_wifi_set_channel(1, WIFI_SECOND_CHAN_NONE);
esp_now_register_send_cb(onSent);
memcpy(peerInfo.peer_addr, slaveMAC, 6);
peerInfo.channel = 1;
peerInfo.encrypt = false;
esp_now_add_peer(&peerInfo);
}
void loop() {
bool reading = digitalRead(BUTTON_PIN);
if (reading != lastButtonState) {
lastDebounce = millis();
buttonHandled = false;
}
if (!buttonHandled && (millis() - lastDebounce) > DEBOUNCE_MS && reading == LOW) {
ledsOn = !ledsOn;
uint8_t msg = ledsOn ? 1 : 0;
Serial.print("Sending: LEDs ");
Serial.println(ledsOn ? "ON" : "OFF");
esp_now_send(slaveMAC, &msg, sizeof(msg));
buttonHandled = true;
}
lastButtonState = reading;
}```
here is the slave code
#include <esp_now.h>
#include <WiFi.h>
#include <esp_wifi.h>
#include <FastLED.h>
#define STRIP1_PIN 3
#define STRIP2_PIN 4
#define NUM_LEDS 4
CRGB strip1\[NUM_LEDS\];
CRGB strip2\[NUM_LEDS\];
bool ledsOn = false;
uint8_t bright1 = 128, bright2 = 128;
uint32_t lastChange1 = 0, lastChange2 = 0;
uint16_t interval1 = 100, interval2 = 100;
void onReceive(const esp_now_recv_info_t \*info, const uint8_t \*data, int len) {
Serial.printf("Packet received! len=%d data\[0\]=%d\\n", len, data\[0\]);
if (len < 1) return;
ledsOn = (data\[0\] == 1);
if (!ledsOn) {
fill_solid(strip1, NUM_LEDS, CRGB::Black);
fill_solid(strip2, NUM_LEDS, CRGB::Black);
FastLED.show();
}
}
void setup() {
Serial.begin(115200);
delay(1000);
FastLED.addLeds<WS2812B, STRIP1_PIN, GRB>(strip1, NUM_LEDS);
FastLED.addLeds<WS2812B, STRIP2_PIN, GRB>(strip2, NUM_LEDS);
FastLED.setBrightness(255);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
Serial.println("======================");
Serial.print("Slave MAC Address: ");
Serial.println(WiFi.macAddress());
Serial.println("Copy the above MAC into master slaveMAC\[\]");
Serial.println("======================");
if (esp_now_init() != ESP_OK) {
Serial.println("ESP-NOW init failed");
while (1);
}
esp_wifi_set_channel(1, WIFI_SECOND_CHAN_NONE);
esp_now_register_recv_cb(onReceive);
}
void loop() {
if (!ledsOn) return;
uint32_t now = millis();
if (now - lastChange1 >= interval1) {
bright1 = random8(40, 255);
interval1 = random(50, 151);
lastChange1 = now;
fill_solid(strip1, NUM_LEDS, CRGB::Red);
for (auto& led : strip1) led.nscale8(bright1);
}
if (now - lastChange2 >= interval2) {
bright2 = random8(40, 255);
interval2 = random(50, 151);
lastChange2 = now;
fill_solid(strip2, NUM_LEDS, CRGB(255, 165, 0));
for (auto& led : strip2) led.nscale8(bright2);
}
FastLED.show();
}
now, when i connect both boards to individual ides i get these responces from them
master:
Master MAC: B8:50:D8:6C:39:87
slave
Slave MAC Address: B8:50:D8:84:44:FC
Copy the above MAC into master slaveMAC[]
======================
when i press the button, i get no responce on the slave chip and this returned on the master chip
Sending: LEDs ON
ACK not received
as best i can tell, (because the leds arent lighting up) the slave isnt receiving the "on" command. but i dont know why.
the mac address matches.
im using esp32family device ozobotDRVKIT boards, i have the ides set to esp32c3dev module.
not sure what other information i can provide to help but im going in circles, the arduino ai is running around in circles as well like a dog chasing its tail, it obviously has no idea whats broken.
i need help with this so badly