I have a ESP32-S3-Zero (FH4R2, “Waveshare” genuine) and it works perfectly well in the Arduino IDE.
For some obscure reason, it mostly works well in the PlatformIO IDE (VSCode) BUT I am having trouble with digitalRead() on a GPIO port. The digitalRead works correctly when I run the code through the Arduino IDE, but it is always returning LOW when the same code is run through the PlatformIO IDE.
Here is my platformio.ini file:
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:esp32-s3-fh4r2]
platform = espressif32
board = esp32-s3-fh4r2
framework = arduino
Here is the code that works fine in Arduino IDE but doesn’t work in PlatformIO:
#include <Arduino.h>
// constants won't change. They're used here to set pin numbers:
const int buttonPin = 7; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup()
{
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
pinMode(buttonPin, PULLDOWN);
}
void loop()
{
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH)
{
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else
{
// turn LED off:
digitalWrite(ledPin, LOW);
}
}