# Alvik Printing Battery Percentage

**URL:** <https://forum.arduino.cc/t/alvik-printing-battery-percentage/1377445>\
**Category:** Alvik\
**Created:** [April 28, 2025, 11:44pm UTC](https://forum.arduino.cc/t/alvik-printing-battery-percentage/1377445 "2025-04-28T23:44:12Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mfusco](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/mfusco/32/1098565_2.png) [@mfusco](https://forum.arduino.cc/u/mfusco)\
**Post date:** [April 28, 2025, 11:44pm UTC](https://forum.arduino.cc/t/alvik-printing-battery-percentage/1377445/1 "2025-04-28T23:44:12Z")

</div>

Hi,

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

```arduino
#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

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [April 29, 2025, 5:20am UTC](https://forum.arduino.cc/t/alvik-printing-battery-percentage/1377445/2 "2025-04-29T05:20:01Z")

</div>

> [@mfusco](#):
>
> battery percentage

This is part of `Arduino_Alvik.cpp` found here: [Arduino\_Alvik/src/Arduino\_Alvik.cpp at main · arduino-libraries/Arduino\_Alvik · GitHub](https://github.com/arduino-libraries/Arduino_Alvik/blob/main/src/Arduino_Alvik.cpp)

```arduino
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);
}

```

---

<div class="post-metadata">

**Author:** ![gilshultz](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gilshultz](https://forum.arduino.cc/u/gilshultz)\
**Post date:** [April 29, 2025, 4:52pm UTC](https://forum.arduino.cc/t/alvik-printing-battery-percentage/1377445/3 "2025-04-29T16:52:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mfusco](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/mfusco/32/1098565_2.png) [@mfusco](https://forum.arduino.cc/u/mfusco)\
**Post date:** [May 13, 2025, 10:47pm UTC](https://forum.arduino.cc/t/alvik-printing-battery-percentage/1377445/4 "2025-05-13T22:47:33Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [May 14, 2025, 2:28am UTC](https://forum.arduino.cc/t/alvik-printing-battery-percentage/1377445/5 "2025-05-14T02:28:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mfusco](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/mfusco/32/1098565_2.png) [@mfusco](https://forum.arduino.cc/u/mfusco)\
**Post date:** [May 14, 2025, 7:03pm UTC](https://forum.arduino.cc/t/alvik-printing-battery-percentage/1377445/6 "2025-05-14T19:03:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [May 14, 2025, 7:11pm UTC](https://forum.arduino.cc/t/alvik-printing-battery-percentage/1377445/7 "2025-05-14T19:11:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mfusco](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/mfusco/32/1098565_2.png) [@mfusco](https://forum.arduino.cc/u/mfusco)\
**Post date:** [May 14, 2025, 7:33pm UTC](https://forum.arduino.cc/t/alvik-printing-battery-percentage/1377445/8 "2025-05-14T19:33:43Z")

</div>

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.

```arduino
#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);
}

```

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [May 14, 2025, 10:30pm UTC](https://forum.arduino.cc/t/alvik-printing-battery-percentage/1377445/9 "2025-05-14T22:30:29Z")

</div>

> [@mfusco](#):
>
> LED blinks red

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

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [November 10, 2025, 10:30pm UTC](https://forum.arduino.cc/t/alvik-printing-battery-percentage/1377445/10 "2025-11-10T22:30:50Z")

</div>

Closed on November 10, 2025, 10:30pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
