-
Notifications
You must be signed in to change notification settings - Fork 17
Description
Describe the bug
Recent changes to the underlying PWM library has broken the example code for the HAT Vibrator for the M5Stick. Changing the example to work with the new format causes a separate issue where after the control pin is initialized the screen of the device will go blank until it is rebooted.
To reproduce
Run this very simple sketch:
#include <M5StickCPlus2.h>
void setup() {
// 1. Initialize the M5StickCPlus2. This sets up the display.
M5.begin();
// Print a message to show the screen is working initially.
M5.Lcd.setCursor(10, 10);
M5.Lcd.println("Screen is OK.");
// Wait 3 seconds to observe the screen is working.
delay(3000);
// 2. Now, attempt to attach a PWM signal to GPIO 26.
// This is the line that we expect to cause the screen to go blank.
ledcAttach(26, 10000, 8);
// If the screen is blank now, we've proven the conflict.
// This message will likely never be seen.
M5.Lcd.println("Did this work?");
}
void loop() {
// Nothing to do here.
}
You will get the "Screen is OK." message but after ledcAttach() runs the screen will go blank and the "Did this work?" message will not appear.
Note. The device is NOT crashing. In fact the example sketch for the HAT Vibrator works but is doesn't show anything on the display.
Expected behavior
To be able to use a PWM device and not have the screen go permanently blank.
Screenshots
No response
Environment
- OS: Linux
- IDE &IDE Version: Arduino IDE 2.3.7-nightly-20250606
- Repository Version: Boards tool chain version: 3.2.0
Additional context
After some head scratching I finally ran the following sketch:
#include <M5StickCPlus2.h>
void setup() {
M5.begin();
// Start the serial monitor so we can see the frequency
Serial.begin(115200);
M5.Lcd.setCursor(10, 10);
M5.Lcd.println("Screen is OK.");
M5.Lcd.println("Reading backlight freq...");
delay(2000);
// Your idea: Read the frequency from the backlight pin (27)
double backlightFreq = ledcReadFreq(27);
// Print the discovered frequency to the serial monitor for confirmation
Serial.print("Detected Backlight Frequency on Pin 27: ");
Serial.println(backlightFreq);
M5.Lcd.setCursor(10, 40);
M5.Lcd.print("Freq is: ");
M5.Lcd.print(backlightFreq);
M5.Lcd.println(" Hz");
M5.Lcd.println("Attaching to G26 now...");
delay(3000);
// Now, attempt to attach to pin 26 using the EXACT same frequency
// If the frequency was 0 (meaning it's not a PWM pin), default to 5000 as a fallback.
if(backlightFreq == 0) {
Serial.println("Setting backlightFreq to 5000");
backlightFreq = 5000;
}
ledcAttach(26, backlightFreq, 8);
// If the screen is still on, this message will appear.
M5.Lcd.fillScreen(TFT_GREEN);
M5.Lcd.setCursor(10, 10);
M5.Lcd.println("IT WORKED!");
Serial.println("Success! The screen did not go blank.");
}
void loop() {
// Nothing to do here.
}
This reported the following on the serial console:
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 271414342, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:4888
load:0x40078000,len:16516
load:0x40080400,len:4
load:0x40080404,len:3476
entry 0x400805b4
Detected Backlight Frequency on Pin 27: 256.00
Success! The screen did not go blank.
So, basically, anyone trying to use PWM with an M5StickCPlus2 can only use 256 as the frequency.
Issue checklist
- I searched for previous reports in the issue tracker
- My report contains all necessary details