(PLEASE HELP) Code for BME280 test not working

Hi, I have been trying to run a BME280 test using an Arduino D1_Mini however despite the code running on Arduino IDE, i get the following error running it on Platformio:

src\main.cpp: In function 'void loop()':
src\main.cpp:48:5: error: 'printValues' was not declared in this scope
48 | printValues();
| ^~~~~~~~~~~
*** [.pio\build\d1_mini\src\main.cpp.o] Error 1

this is the code used:

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

#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI

unsigned long delayTime;

void setup() {
    Serial.begin(9600);
    while(!Serial);    // time to get serial running
    Serial.println(F("BME280 test"));

    unsigned status;
    
    // default settings
    status = bme.begin(0x76);  
    // You can also pass in a Wire library object like &Wire2
    // status = bme.begin(0x76, &Wire2)
    if (!status) {
        Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
        Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16);
        Serial.print("        ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
        Serial.print("   ID of 0x56-0x58 represents a BMP 280,\n");
        Serial.print("        ID of 0x60 represents a BME 280.\n");
        Serial.print("        ID of 0x61 represents a BME 680.\n");
        while (1) delay(10);
    }
    
    Serial.println("-- Default Test --");
    delayTime = 1000;

    Serial.println();
}


void loop() { 
    printValues();
    delay(delayTime);
}


void printValues() {
    Serial.print("Temperature = ");
    Serial.print(bme.readTemperature());
    Serial.println(" °C");

    Serial.print("Pressure = ");

    Serial.print(bme.readPressure() / 100.0F);
    Serial.println(" hPa");

    Serial.print("Approx. Altitude = ");
    Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
    Serial.println(" m");

    Serial.print("Humidity = ");
    Serial.print(bme.readHumidity());
    Serial.println(" %");

    Serial.println();
}

Welcome

You need to do a forward declaration, or move the function before it is used. The Arduino IDE does this automatically, not PlatformIO.

Your sketch compiles just fine with arduino-cli. Perhaps try it with the Arduino IDE rather than PlatformIO?

arduino-cli compile -b esp8266:esp8266:d1_mini:xtal=80,vt=flash,exception=legacy,ssl=all,eesz=4M2M,ip=lm2f,dbg=Disabled,lvl=None____,wipe=none,baud=460800 --warnings all --output-dir ~/tmp --no-color (in directory: /home/me/Documents/sketchbook/Wemos_D1_mini/test)
Executable segment sizes:
Sketch uses 277476 bytes (26%) of program storage space. Maximum is 1044464 bytes.
Global variables use 27928 bytes (34%) of dynamic memory, leaving 53992 bytes for local variables. Maximum is 81920 bytes.
IROM   : 246864          - code in flash         (default or ICACHE_FLASH_ATTR)
IRAM   : 28188   / 32768 - code in IRAM          (ICACHE_RAM_ATTR, ISRs...)
DATA   : 1260  )         - initialized variables (global, static) in RAM/HEAP
RODATA : 1164  ) / 81920 - constants             (global, static) in RAM/HEAP
BSS    : 25504 )         - zeroed variables      (global, static) in RAM/HEAP
Used library            Version Path
Wire                    1.0     /home/me/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/libraries/Wire
SPI                     1.0     /home/me/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/libraries/SPI
Adafruit Unified Sensor 1.1.14  /home/me/Documents/sketchbook/libraries/Adafruit_Unified_Sensor
Adafruit BME280 Library 2.2.4   /home/me/Documents/sketchbook/libraries/Adafruit_BME280
Adafruit BusIO          1.16.1  /home/me/Documents/sketchbook/libraries/Adafruit_BusIO
Used platform   Version Path
esp8266:esp8266 2.6.3   /home/me/.arduino15/packages/esp8266/hardware/esp8266/2.6.3
Compilation finished successfully.

As guix suggested you need a forward declaration void printValues() ;

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

#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI

unsigned long delayTime;
void printValues() ;

void setup() {
    Serial.begin(9600);
    while(!Serial);    // time to get serial running
    Serial.println(F("BME280 test"));

    unsigned status;
    
    // default settings
    status = bme.begin(0x76);  
    // You can also pass in a Wire library object like &Wire2
    // status = bme.begin(0x76, &Wire2)
    if (!status) {
        Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
        Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16);
        Serial.print("        ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
        Serial.print("   ID of 0x56-0x58 represents a BMP 280,\n");
        Serial.print("        ID of 0x60 represents a BME 280.\n");
        Serial.print("        ID of 0x61 represents a BME 680.\n");
        while (1) delay(10);
    }
    
    Serial.println("-- Default Test --");
    delayTime = 1000;

    Serial.println();
}


void loop() { 
    printValues();
    delay(delayTime);
}


void printValues() {
    Serial.print("Temperature = ");
    Serial.print(bme.readTemperature());
    Serial.println(" °C");

    Serial.print("Pressure = ");

    Serial.print(bme.readPressure() / 100.0F);
    Serial.println(" hPa");

    Serial.print("Approx. Altitude = ");
    Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
    Serial.println(" m");

    Serial.print("Humidity = ");
    Serial.print(bme.readHumidity());
    Serial.println(" %");

    Serial.println();
}