2

I'm running into this weird problem. My code is working just fine when I upload it to an ESP32 from Arduino IDE. That same code is not working when I upload it using PlatformIO IDE. The same libraries versions are being used on both environments.

I've been reading that in PlatformIO you might have to make use of forward declaration (something that Arduino IDE solves out of the box). I do not know if this is the case. And if it is... I do not know how to apply it.

Can someone help me out with this?

#include <Arduino.h>
#include <DHT.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

#define DHTPIN 23
#define DHTTYPE DHT11

LiquidCrystal_I2C lcd(0x27,16,2);

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  
  lcd.init();
  lcd.backlight();

  Serial.begin(115200);
  dht.begin();
}

void loop() {
  delay(2000);
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  if (isnan(h) || isnan(t)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }

  Serial.print(F("Humedad: "));
  Serial.print(h);
  Serial.print(F("% Temperatura: "));
  Serial.print(t);
  Serial.println(F("°C "));

  lcd.setCursor(0,0);
  lcd.print("Humedad: ");
  lcd.println(String(h));
  lcd.setCursor(0,1);
  lcd.print("Temp.: ");
  lcd.print(String(t));
}

EDIT:

platformio.ini

[env:fm-devkit]
platform = espressif32
board = fm-devkit
framework = arduino
monitor_speed = 115200
upload_port = COM9
lib_deps = 
    adafruit/DHT sensor library@^1.4.3
    adafruit/Adafruit Unified Sensor@^1.1.5
    marcoschwartz/[email protected]
9
  • 4
    What exactly does "not working" mean here? Do you get compilation errors? Or uploading errors? Or is the behavior of the code different than expected after successfull compilation and upload? Commented May 31, 2022 at 22:26
  • can you post your platformio.ini file? The problem could be that you are using a different version of the ESP-IDF which is pre-compiled in the arduino environment (which is not neccessarily the case when working with platformio). Commented May 31, 2022 at 23:07
  • @chrisl The code just compiles and runs... but it does not print anything to the display Commented May 31, 2022 at 23:45
  • @SimSon I added the plaformio.ini Commented May 31, 2022 at 23:47
  • 1
    Verbose compile and link output for both environments might be of some use. Commented Jun 6, 2022 at 1:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.