ESP-32-C3 0.42 OLED ESP-NOW Wifi PWM

Jateu_01
Posts: 2
Joined: Sun Jul 27, 2025 5:10 pm

ESP-32-C3 0.42 OLED ESP-NOW Wifi PWM

Postby Jateu_01 » Sun Jul 27, 2025 6:06 pm

Hi all,

I get to the point right now I have various learning difficulties. I can do anything hands on, but coding is troublesome. I've dabbled with electronics but coding certainly Isn't my thing.

It would be amazing if I could get some guidance and help regarding my project.

Essentially the project is ESP-NOW based, Master detects analogue input from hall effect sensor and sends signal to slave to output a pwm signal.

Is there any projects out there that do this or anyone will to advise.

Again I am not skilled or expert at coding. Please excuse and issues.

Many Thanks.

horace99
Posts: 34
Joined: Mon Oct 14, 2024 10:38 am

Re: ESP-32-C3 0.42 OLED ESP-NOW Wifi PWM

Postby horace99 » Mon Jul 28, 2025 4:59 am

test ESP-NOW, WiFI, OLD, switches, PWM, etc in a separate programs - when all is working start building your project

e.g. initially get the ESP-NOW communications working then worry about connecting sensors etc
start with example library code from File>Examples>ESP_NOW
once you have working example code you can adapt it to suit your project

can you give a link to your OLED display?
for PWM have a look at https://lastminuteengineers.com/esp32-pwm-tutorial/

horace99
Posts: 34
Joined: Mon Oct 14, 2024 10:38 am

Re: ESP-32-C3 0.42 OLED ESP-NOW Wifi PWM

Postby horace99 » Mon Jul 28, 2025 8:07 am

found an example ESP-NOW code which may help
NOTE: ESP-NOW has changed from ESP32 core 2.x to 3.x - see https://docs.espressif.com/projects/esp ... p_now.html
you may find some of the example code online is using ESP32 core V2

ESP-NOW transmitter works using a ESP32-C3-MINI-1 IDE 2.3.5 ESP32 core 3.3.0

Code: Select all

// ESP32 Transmitter - two way communication using ESP_NOW
// NOTE: updated to use ESP32 core V3.x
//  note- no sensors so test data structure transmitted

// original code from
/*
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com/esp-now-two-way-communication-esp32/
  
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files.
  
  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
*/

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

//#include <Wire.h>
//#include <Adafruit_Sensor.h>
//#include <Adafruit_BME280.h>


//Adafruit_BME280 bme;

// initially test with broadcast address - sends to all receivers
//uint8_t broadcastAddress[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};  // ESP-NOW broadcast address
// REPLACE WITH THE MAC Address of your receiver
uint8_t broadcastAddress[] = { 0x68, 0xB6, 0xB3, 0x2C, 0x16, 0x08};

// Define variables to store BME280 readings to be sent
float temperature = 3.14159;
float humidity = 90.0;
float pressure = 10.0;

// Define variables to store incoming readings
float incomingTemp;
float incomingHum;
float incomingPres;

// Variable to store if sending data was successful
String success;

//Structure example to send data
//Must match the receiver structure
typedef struct struct_message {
  float temp;
  float hum;
  float pres;
} struct_message;

// Create a struct_message called BME280Readings to hold sensor readings
struct_message BME280Readings;

// Create a struct_message to hold incoming sensor readings
struct_message incomingReadings;
bool incomingReadingsOK = false;

esp_now_peer_info_t peerInfo;

// Callback when data is sent
void OnDataSent(const esp_now_send_info_t* mac_addr, esp_now_send_status_t status) {
  Serial.print("Last Packet Send Status:\t");
  Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
  if (status == 0) success = "Delivery Success :)";
  else success = "Delivery Fail :(";
}

// Callback when data is received
void OnDataRecv(const esp_now_recv_info_t* mac, const unsigned char* incomingData, int len) {
  memcpy(&incomingReadings, incomingData, sizeof(incomingReadings));
  Serial.printf("From %02X:%02X:%02X:%02X:%02X:%02X",
                mac->src_addr[0], mac->src_addr[1], mac->src_addr[2], mac->src_addr[3], mac->src_addr[4], mac->src_addr[5]);
  Serial.printf(" Bytes received: %d\n", len);
  incomingTemp = incomingReadings.temp;
  incomingHum = incomingReadings.hum;
  incomingPres = incomingReadings.pres;
  incomingReadingsOK = true;
}

void setup() {
  // Init Serial Monitor
  Serial.begin(115200);
  delay(3000);
  Serial.println("\n\n **** ESP-NOW transmitter *****");
  // Init BME280 sensor
  /*bool status = bme.begin(0x76);  
  if (!status) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
   // while (1);
  }*/

  // Set device as a Wi-Fi Station
  WiFi.mode(WIFI_STA);
  delay(100);  // short delay for initialisation
  Serial.print("WiFi MAC address ");
  Serial.println(WiFi.macAddress());
  // Init ESP-NOW
  if (esp_now_init() != ESP_OK) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }
  delay(100);  // short delay for initialisation
  byte mac[6];
  WiFi.macAddress(mac);
  Serial.printf("ESP-NOW initialised MAC address %02X:%02X:%02X:%02X:%02X:%02X\n",
                mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  // Once ESPNow is successfully Init, we will register for Send CB to
  // get the status of Trasnmitted packet
  esp_now_register_send_cb(OnDataSent);

  // Register peer
  memcpy(peerInfo.peer_addr, broadcastAddress, 6);
  peerInfo.channel = 0;
  peerInfo.encrypt = false;

  // Add peer
  if (esp_now_add_peer(&peerInfo) != ESP_OK) {
    Serial.println("Failed to add peer");
    return;
  }
  // Register for a callback function that will be called when data is received
  esp_now_register_recv_cb(OnDataRecv);
}

void loop() {
  getReadings();
  // Set values to send
  BME280Readings.temp = temperature;
  BME280Readings.hum = humidity;
  BME280Readings.pres = pressure;
  // Send message via ESP-NOW
  esp_err_t result = esp_now_send(broadcastAddress, (uint8_t*)&BME280Readings, sizeof(BME280Readings));
  if (result == ESP_OK) Serial.println("esp_now_send() returns ESP_OK");
  else                  Serial.println("esp_now_send() returns Error");
  updateDisplay();
  delay(10000);
}

void getReadings() {
  static int x = 1;
  temperature = 23.5 + x;  //bme.readTemperature();
  humidity = 78 + x;       //bme.readHumidity();
  pressure = 21 + x;       //(bme.readPressure() / 100.0F);
  x++;
}

void updateDisplay() {
  if (!incomingReadingsOK) return;
  // Display Readings in Serial Monitor
  Serial.println("INCOMING READINGS");
  Serial.print("Temperature: ");
  Serial.print(incomingReadings.temp);
  Serial.println(" ºC");
  Serial.print("Humidity: ");
  Serial.print(incomingReadings.hum);
  Serial.println(" %");
  Serial.print("Pressure: ");
  Serial.print(incomingReadings.pres);
  Serial.println(" hPa");
  Serial.println();
}

ESP_NOW receiver using a ESP32-S3-DevKitC-1

Code: Select all

// ESP32 Receiver - two way communication using ESP_NOW
//  NOTE: updated to use ESP32 core V3.x
//  waits to receive packet from transmitter then transmits data back
//  note- no sensors so test data structure transmitted

// original code from
/*
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com/esp-now-two-way-communication-esp32/
  
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files.
  
  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
*/

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

//#include <Wire.h>
//#include <Adafruit_Sensor.h>
//#include <Adafruit_BME280.h>
//Adafruit_BME280 bme;

// this will be setup when a packet is received with transmitter MAC adddress
uint8_t broadcastAddress[] = { 0, 0, 0, 0, 0, 0 };  //{ 0xEC, 0x64, 0xC9, 0x82, 0x7D, 0x34 };  //{0x84, 0xCC, 0xA8, 0x7A, 0x56, 0x6C};

// Define variables to store BME280 readings to be sent
float temperature;
float humidity;
float pressure;

// Define variables to store incoming readings
float incomingTemp;
float incomingHum;
float incomingPres;

// Variable to store if sending data was successful
String success;

//Structure example to send data
//Must match the receiver structure
typedef struct struct_message {
  float temp;
  float hum;
  float pres;
} struct_message;

// Create a struct_message called BME280Readings to hold sensor readings
struct_message BME280Readings;

// Create a struct_message to hold incoming sensor readings
struct_message incomingReadings;

esp_now_peer_info_t peerInfo;

// Callback when data is sent
void OnDataSent(const esp_now_send_info_t* mac_addr, esp_now_send_status_t status) {
  Serial.print("Last Packet Send Status:\t");
  Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail");
  if (status == 0) success = "Delivery Success :)";
  else success = "Delivery Fail :(";
}

// Callback when data is received
void OnDataRecv(const esp_now_recv_info_t* mac, const unsigned char* incomingData, int len) {
  memcpy(&incomingReadings, incomingData, sizeof(incomingReadings));
  // if no broadcast address set it up to transmitter MAC
  if (broadcastAddress[0] == 0) {
    memcpy(broadcastAddress, mac->src_addr, 6);       // set broadcasrAddress to received MAC address
    memcpy(peerInfo.peer_addr, broadcastAddress, 6);  // Register peer
    peerInfo.channel = 0;
    peerInfo.encrypt = false;
    // Add peer
    if (esp_now_add_peer(&peerInfo) != ESP_OK) {
      Serial.println("Failed to add peer");
      return;
    }
  }
  // display transmitter MAC address and copy data
  Serial.printf("From %02X:%02X:%02X:%02X:%02X:%02X",
                mac->src_addr[0], mac->src_addr[1], mac->src_addr[2], mac->src_addr[3], mac->src_addr[4], mac->src_addr[5]);
  Serial.printf(" Bytes received: %d\n", len);
  incomingTemp = incomingReadings.temp;
  incomingHum = incomingReadings.hum;
  incomingPres = incomingReadings.pres;
}

void setup() {
  // Init Serial Monitor
  Serial.begin(115200);
  delay(3000);
  // Init BME280 sensor
  //bool status = bme.begin(0x76);
  //if (!status) {
  //  Serial.println("Could not find a valid BME280 sensor, check wiring!");
  // while (1);
  //}
  Serial.println("\n\n **** ESP-NOW receiver *****");
  // Set device as a Wi-Fi Station
  WiFi.mode(WIFI_STA);
  delay(100);  // short delay for initialisation
  Serial.print("WiFi MAC address ");
  Serial.println(WiFi.macAddress());
  // Init ESP-NOW
  if (esp_now_init() != ESP_OK) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }
  Serial.print("ESP-NOW initialised");
  // Once ESPNow is successfully Init, we will register for Send CB to
  // get the status of Trasnmitted packet
  esp_now_register_send_cb(OnDataSent);
  // Register for a callback function that will be called when data is received
  esp_now_register_recv_cb(OnDataRecv);
}

void loop() {
  delay(10000);
  getReadings();
  // Set values to send
  BME280Readings.temp = temperature;
  BME280Readings.hum = humidity;
  BME280Readings.pres = pressure;
  // Send message via ESP-NOW
  if (broadcastAddress[0] == 0)
    Serial.println("no MAC address to transmit too");
  else {
    esp_err_t result = esp_now_send(broadcastAddress, (uint8_t*)&BME280Readings, sizeof(BME280Readings));
    Serial.printf("Send too %02X:%02X:%02X:%02X:%02X:%02X ",
                  broadcastAddress[0], broadcastAddress[1], broadcastAddress[2], broadcastAddress[3], broadcastAddress[4], broadcastAddress[5]);
   if (result == ESP_OK) Serial.println("esp_now_send() returns ESP_OK");
  else                  Serial.println("esp_now_send() returns Error");
    updateDisplay();
  }
}
void getReadings() {
  static int x = 1;
  temperature = 33.5 + x;  //bme.readTemperature();
  humidity = 88 + x;       //bme.readHumidity();
  pressure = 212 + x;      //(bme.readPressure() / 100.0F);
  x++;
}

void updateDisplay() {
  // Display Readings in Serial Monitor
  Serial.println("INCOMING READINGS");
  Serial.print("Temperature: ");
  Serial.print(incomingReadings.temp);
  Serial.println(" ºC");
  Serial.print("Humidity: ");
  Serial.print(incomingReadings.hum);
  Serial.println(" %");
  Serial.print("Pressure: ");
  Serial.print(incomingReadings.pres);
  Serial.println(" hPa");
  Serial.println();
}
test run transmitter output

Code: Select all

**** ESP-NOW transmitter *****
WiFi MAC address 10:91:A8:02:00:E8
ESP-NOW initialised MAC address 10:91:A8:02:00:E8
esp_now_send() returns ESP_OK
Last Packet Send Status:	Delivery Success
From 68:B6:B3:2C:16:08 Bytes received: 12
esp_now_send() returns ESP_OK
INCOMING READINGS
Temperature: 36.50 ºC
Humidity: 91.00 %
Pressure: 215.00 hPa

Last Packet Send Status:	Delivery Success
From 68:B6:B3:2C:16:08 Bytes received: 12
esp_now_send() returns ESP_OK
INCOMING READINGS
Temperature: 37.50 ºC
Humidity: 92.00 %
Pressure: 216.00 hPa

Last Packet Send Status:	Delivery Success
From 68:B6:B3:2C:16:08 Bytes received: 12
esp_now_send() returns ESP_OK
INCOMING READINGS
Temperature: 38.50 ºC
Humidity: 93.00 %
Pressure: 217.00 hPa

Last Packet Send Status:	Delivery Success
From 68:B6:B3:2C:16:08 Bytes received: 12
esp_now_send() returns ESP_OK
INCOMING READINGS
Temperature: 39.50 ºC
Humidity: 94.00 %
Pressure: 218.00 hPa

Last Packet Send Status:	Delivery Success
From 68:B6:B3:2C:16:08 Bytes received: 12
esp_now_send() returns ESP_OK
INCOMING READINGS
Temperature: 40.50 ºC
Humidity: 95.00 %
Pressure: 219.00 hPa
receiver output

Code: Select all

**** ESP-NOW receiver *****
WiFi MAC address 68:B6:B3:2C:16:08
ESP-NOW initialisedno MAC address to transmit too
no MAC address to transmit too
From 10:91:A8:02:00:E8 Bytes received: 12
Send too 10:91:A8:02:00:E8 esp_now_send() returns ESP_OK
INCOMING READINGS
Temperature: 24.50 ºC
Humidity: 79.00 %
Pressure: 22.00 hPa

Last Packet Send Status:	Delivery Success
From 10:91:A8:02:00:E8 Bytes received: 12
Send too 10:91:A8:02:00:E8 esp_now_send() returns ESP_OK
INCOMING READINGS
Temperature: 25.50 ºC
Humidity: 80.00 %
Pressure: 23.00 hPa

Last Packet Send Status:	Delivery Success
From 10:91:A8:02:00:E8 Bytes received: 12
Send too 10:91:A8:02:00:E8 esp_now_send() returns ESP_OK
INCOMING READINGS
Temperature: 26.50 ºC
Humidity: 81.00 %
Pressure: 24.00 hPa

Last Packet Send Status:	Delivery Success
From 10:91:A8:02:00:E8 Bytes received: 12
Send too 10:91:A8:02:00:E8 esp_now_send() returns ESP_OK
INCOMING READINGS
Temperature: 27.50 ºC
Humidity: 82.00 %
Pressure: 25.00 hPa

Last Packet Send Status:	Delivery Success
From 10:91:A8:02:00:E8 Bytes received: 12
Send too 10:91:A8:02:00:E8 esp_now_send() returns ESP_OK
INCOMING READINGS
Temperature: 28.50 ºC
Humidity: 83.00 %
Pressure: 26.00 hPa

Last Packet Send Status:	Delivery Success
From 10:91:A8:02:00:E8 Bytes received: 12
Send too 10:91:A8:02:00:E8 esp_now_send() returns ESP_OK
INCOMING READINGS
Temperature: 29.50 ºC
Humidity: 84.00 %
Pressure: 27.00 hPa

Last Packet Send Status:	Delivery Success
From 10:91:A8:02:00:E8 Bytes received: 12
Send too 10:91:A8:02:00:E8 esp_now_send() returns ESP_OK
INCOMING READINGS
Temperature: 30.50 ºC
Humidity: 85.00 %
Pressure: 28.00 hPa
initially test the transmitter using the broadcast address 0xff, 0xff, 0xff, 0xff, 0xff, 0xff then try the receiver MAC address

Jateu_01
Posts: 2
Joined: Sun Jul 27, 2025 5:10 pm

Re: ESP-32-C3 0.42 OLED ESP-NOW Wifi PWM

Postby Jateu_01 » Mon Jul 28, 2025 11:11 am

horace99 thank you for replying. Yes I've checked all of these out. However I'm still struggling. I have asked other for help but it's not worked out. With my inability to comprehend at a good rate it's causing issues. So I used AI to help come up with a code but it's not working and a bit of a mess.

Many thanks

horace99
Posts: 34
Joined: Mon Oct 14, 2024 10:38 am

Re: ESP-32-C3 0.42 OLED ESP-NOW Wifi PWM

Postby horace99 » Tue Jul 29, 2025 6:05 am

did you try the code in my previous post which worked on a ESP32-C3-MINI-1 ?
did it compile, link and upload OK? if not what errors did you get?
did it work? if not what was the serial monitor output?

Who is online

Users browsing this forum: Applebot, Bytespider, PerplexityBot and 1 guest