Alvik Printing Battery Percentage

Hi,

I have the following sketch for an Arduino ESP32 mounted on an Alvik:

#include <ArduinoBLE.h>
#include "Arduino_Alvik.h"

BLEService service("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service

// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central
BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);

Arduino_Alvik alvik;

int brakeCt, rotateLeftCt, rotateRightCt;

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

  if (!BLE.begin()) {
    Serial.println("starting Bluetooth® Low Energy module failed!");

    while (1);
  }

  BLE.setLocalName("Alvik");
  BLE.setAdvertisedService(service);
  service.addCharacteristic(switchCharacteristic);
  BLE.addService(service);
  switchCharacteristic.writeValue(0);
  BLE.advertise();

  Serial.println("BLE Alvik Peripheral");

  alvik.begin();
}

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

  if (central) {
    Serial.print("Connected to central: ");
    // print the central's MAC address:
    Serial.println(central.address());

    while (central.connected()) {
      if (switchCharacteristic.written()) {
        Serial.println(switchCharacteristic.value());

        if (switchCharacteristic.value() == 119) {  
            alvik.drive(10, 0.0);

            brakeCt = 0;

          switchCharacteristic.writeValue(0);
        } else if (switchCharacteristic.value() == 97) {  
          rotateLeftCt++;

          if (rotateLeftCt > 1)
            switchCharacteristic.writeValue(0);
          else alvik.rotate(45);
        }  else if (switchCharacteristic.value() == 100) {  
           rotateRightCt++;

           if (rotateRightCt > 1)
            switchCharacteristic.writeValue(0);
           else alvik.rotate(-45);
        } else if (switchCharacteristic.value() == 119) {
          alvik.drive(-10, 0.0);
        } else {
          brake();
        }
      } else brake();
    }
  }
}

void brake() {
   brakeCt++;

    if (brakeCt > 5) {
      alvik.brake();

      brakeCt = 0;
      rotateLeftCt = 0;
      rotateRightCt = 0;
    }

    delay(100);
}

For some reason, it prints "BLE Alvik Peripheral" but then proceeds to print the battery percentage of the Alvik instead of running the rest of the sketch. When trying to burn the boot loader I get this error:

raceback (most recent call last):
File "esptool.py", line 34, in
File "esptool/init.py", line 1032, in _main
File "esptool/init.py", line 674, in main
File "esptool/init.py", line 921, in get_default_connected_device
File "esptool/loader.py", line 640, in connect
File "esptool/loader.py", line 541, in _connect_attempt
File "serial/serialutil.py", line 591, in flushOutput
File "serial/serialposix.py", line 692, in reset_output_buffer
termios.error: (6, 'Device not configured')
[4930] Failed to execute script 'esptool' due to unhandled exception!

Failed programming: uploading error: exit status 1

This is part of Arduino_Alvik.cpp found here: Arduino_Alvik/src/Arduino_Alvik.cpp at main · arduino-libraries/Arduino_Alvik · GitHub

void Arduino_Alvik::idle(){
  digitalWrite(NANO_CHK, HIGH);
  delay(500);
  bool led_value=false;
  while(!is_on()){ // <-- WHILE ALVIK IS ON
    //read battery value
    battery = battery_measure();  // <-- READ VALUE HERE
    battery_is_charging = true;
    if (verbose_output){
      Serial.print(round(battery)); // <-- PRINT VALUE HERE
      Serial.println("%");
    }
    if (battery_soc>CHARGE_THRESHOLD){
      digitalWrite(LED_GREEN, LOW);
      digitalWrite(LED_RED, HIGH);
    }
    else{
      digitalWrite(LED_GREEN, HIGH);
      led_value = !led_value;
      digitalWrite(LED_RED, led_value);
    }
    delay(1000);
  }
  digitalWrite(LED_GREEN, HIGH);
  digitalWrite(LED_RED, HIGH);
  digitalWrite(NANO_CHK, LOW);
}

It appears you are not programing the part and what you are getting is from the previous code. That will not change until you get a successful upload. Go back to the basic blink sketch and when that loads and works go back to your sketch.

I tried to upload the firmware and then a sketch to the ESP32 mounted on the Alvik but it's still only printing the battery percentage. How can I troubleshoot this?

Do you have basic instructions from the manufacturer on how to start using the device?

I followed this documentation: https://docs.arduino.cc/tutorials/alvik/setting-alvik-arduino-ide/?queryID=b12731e73bca074d77e6f01ac369ae13

Did you sucessfully upload new code?
What do the green and red LED show?

The sketch below uploads but the code doesn't seem to run and instead the LED blinks red and the battery percentage prints to the serial monitor. I've tested this with two different ESP32 boards.

#include "Arduino_Alvik.h"

Arduino_Alvik alvik;

void setup() {
  alvik.begin();
}

void loop() {
  alvik.drive(10, 45);
  delay(10000);
  alvik.drive(10, -45);
  delay(10000);
}

Blink is not referenced in the code above. Look in your user manual for error indications.