Upload Failure Blues

I am working on the following code to send BME280 data to a remote client. I am using a Seeeduino ESP32C3 microprocessor. This is a variation on code that worked fine when I was using UUID shortcuts ( i.e. 0x181A). I changed the upload rate to 115,200 and I have played with some of the toggles under “Tools” to no avail. If anyone sees the reason for the failure, I would be grateful for a heads-up regarding the error of my ways.

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

#define BLE_NAME "Psychrometer"
#define SERVICE_UUID "19B10000-E8F2-537E-4F6C-D104768A1214"
#define TEMPERATURE_UUID "19B10001-E8F2-537E-4F6C-D104768A1214"
#define HUMIDITY_UUID "19B10002-E8F2-537E-4F6C-D104768A1214"
#define PRESSURE_UUID "19B10003-E8F2-537E-4F6C-D104768A1214"

Adafruit_BME280 bme;

BLEService bmeService(SERVICE_UUID);
BLEFloatCharacteristic temperatureCharacteristic(TEMPERATURE_UUID, BLERead | BLENotify);
BLEFloatCharacteristic humidityCharacteristic(HUMIDITY_UUID, BLERead | BLENotify);
BLEFloatCharacteristic pressureCharacteristic(PRESSURE_UUID, BLERead | BLENotify);

void setup() {
  Serial.begin(9600);
  while (!Serial);

  if (!bme.begin()) {
    Serial.println("Could not find BME280 sensor, check wiring!");
    while (1);
  }

  if (!BLE.begin()) {
    Serial.println("Failed to start BLE!");
    while (1);
  }

  BLE.setLocalName(BLE_NAME);
  BLE.setAdvertisedService(bmeService);

  bmeService.addCharacteristic(temperatureCharacteristic);
  bmeService.addCharacteristic(humidityCharacteristic);
  bmeService.addCharacteristic(pressureCharacteristic);

  BLE.addService(bmeService);

  temperatureCharacteristic.writeValue(0);
  humidityCharacteristic.writeValue(0);
  pressureCharacteristic.writeValue(0);

  BLE.advertise();

  Serial.println("BLE peripheral is now active");
}

void loop() {
  BLEDevice central = BLE.central();

  if (central) {
    Serial.print("Connected to central: ");
    Serial.println(central.address());

    while (central.connected()) {
      float temperature = bme.readTemperature();
      float humidity = bme.readHumidity();
      float pressure = bme.readPressure() / 100.0F;

      Serial.print("Temperature: ");
      Serial.print(temperature);
      Serial.println(" °C");

      Serial.print("Humidity: ");
      Serial.print(humidity);
      Serial.println(" %");

      Serial.print("Pressure: ");
      Serial.print(pressure);
      Serial.println(" hPa");

      temperatureCharacteristic.writeValue(temperature);
      humidityCharacteristic.writeValue(humidity);
      pressureCharacteristic.writeValue(pressure);

      delay(1000);
    }

    Serial.print("Disconnected from central: ");
    Serial.println(central.address());
  }
}

I received the following error code which I do not understand:

Sketch uses 420096 bytes (32%) of program storage space. Maximum is 1310720 bytes.
Global variables use 19844 bytes (6%) of dynamic memory, leaving 307836 bytes for local variables. Maximum is 327680 bytes.
esptool.py v4.5.1
Serial port COM43
Connecting…
Chip is ESP32-C3 (revision v0.4)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 34:85:18:06:2f:64
Uploading stub…
Running stub…
Stub running…

A fatal error occurred: Unable to verify flash chip connection (No serial data received.).
Failed uploading: uploading error: exit status 2

Hi there,
Is the unit in Bootloader mode prior to upload?
GL :slight_smile: PJ :v:

Thank you, that did the trick. After working with the 2040 series, the ESP is so very squirrelly.

1 Like