Connection Problem with Arduino LilyPad: Code Upload Problem

Hello,

We are currently working on a project that uses Arduino Lilypad for an assistive technology device. I am not an expert in electronics. We participated in the Accessible Life Technologies competition in Turkey with an elementary school student. We used the Arduino LilyPad USB Atmega32U4 board in one of our devices, a headband developed for visually impaired individuals.

However, we encountered an issue with our Arduino Lilypad that we could not solve.

The general purpose of our project is to measure distance using an Infrared Distance Measuring Module attached to the headband. When it gets too close to an object, it alerts the visually impaired person using a buzzer and vibration module.

Components we used:

  1. Arduino Lilypad USB Atmega32U4 Development Board
  2. GY-530 Infrared Distance Measuring Module with VL53L0 infrared sensor
  3. Lilypad Compatible Buzzer
  4. Vibration Module

We connected the components correctly and then uploaded the following code:

#include <Wire.h>
#include <Adafruit_VL53L0X.h>

Adafruit_VL53L0X lox = Adafruit_VL53L0X();

#define BUZZER_PIN 9
#define VIBRATION_PIN 10
#define WARNING_DISTANCE_1 60
#define WARNING_DISTANCE_2 40
#define DANGER_DISTANCE 20

void setup() {
    pinMode(BUZZER_PIN, OUTPUT);
    pinMode(VIBRATION_PIN, OUTPUT);
    Serial.begin(9600);

    // Start the VL53L0X sensor
    if (!lox.begin()) {
        Serial.println(F("Failed to start VL53L0X"));
        while (1); // Enter infinite loop in case of error
    }
    Serial.println(F("VL53L0X API Simple Range Test"));

    // Play the C5 note on the buzzer for a whole note
    tone(BUZZER_PIN, 523, 1000); // 523 Hz = C5, 1000 ms = whole note

    // Turn the vibration motor on for 1 second, then off
    digitalWrite(VIBRATION_PIN, HIGH);
    delay(1000);
    digitalWrite(VIBRATION_PIN, LOW);
}

// Alert function: Buzzer plays the C5 note for an eighth note, and the vibration motor vibrates
void uyari() {
    tone(BUZZER_PIN, 523, 125); // 523 Hz = C5, 125 ms = eighth note
    digitalWrite(VIBRATION_PIN, HIGH);
    delay(125);
    digitalWrite(VIBRATION_PIN, LOW);
}

void loop() {
    VL53L0X_RangingMeasurementData_t measure;

    // Take a measurement
    lox.rangingTest(&measure, false);

    // Check if the measurement is valid
    if (measure.RangeStatus != 4) {
        float distance = measure.RangeMilliMeter / 10.0;
        Serial.print("Distance (cm): "); Serial.println(distance);

        if (distance >= WARNING_DISTANCE_2 && distance < WARNING_DISTANCE_1) {
            uyari();
            delay(600); // Wait for 0.6 seconds
        } else if (distance >= DANGER_DISTANCE && distance < WARNING_DISTANCE_2) {
            uyari();
            delay(300); // Wait for 0.3 seconds
        } else if (distance < DANGER_DISTANCE) {
            uyari(); // No waiting
        }
    } else {
        Serial.println("Out of range");
    }
}

After uploading this code to the board, I could no longer connect to it or upload new code. When I tried to upload new code, I observed that the connection was lost right after the compilation step.

I am using a device with Windows 11 installed. To resolve this issue, I tried the following steps:

  1. Press the Reset Button: Hold the “Reset” button while connecting the USB cable to the computer to put the board into reset mode.
  2. Enter Bootloader Mode: Quickly press the “Reset” button twice to put the Arduino Lilypad Atmega32U4 into bootloader mode.
  3. Tried updating the drivers.
  4. Tested on different computers and with different USB cables.
  5. Tried with another Lilypad board.
  6. Ensured the correct board and COM port were selected (in Arduino IDE: Tools > Board, “LilyPad Arduino USB” was selected).
  7. Tried uploading the code through PlatformIO as well.

The error I received consists of outputs similar to the following:

Processing LilyPadUSB (platform: atmelavr; board: LilyPadUSB; framework: arduino)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/LilyPadUSB.html
PLATFORM: Atmel AVR (5.0.0) > Arduino LilyPad USB
HARDWARE: ATMEGA32U4 8MHz, 2.50KB RAM, 28KB Flash
DEBUG: Current (simavr) External (simavr)
PACKAGES: 
 - framework-arduino-avr @ 5.2.0 
 - tool-avrdude @ 1.60300.200527 (6.3.0) 
 - toolchain-atmelavr @ 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder -> https://BANNED/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 9 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Adafruit_VL53L0X @ 1.2.4+sha.23dc309
|-- Wire @ 1.0
Building in release mode
Compiling .pio\build\LilyPadUSB\src\main.cpp.o
Compiling .pio\build\LilyPadUSB\lib192\Wire\Wire.cpp.o
Compiling .pio\build\LilyPadUSB\lib192\Wire\utility\twi.c.o
Compiling .pio\build\LilyPadUSB\lib9ae\Adafruit_VL53L0X\Adafruit_VL53L0X.cpp.o
Compiling .pio\build\LilyPadUSB\lib9ae\Adafruit_VL53L0X\core\src\vl53l0x_api.cpp.o
Compiling .pio\build\LilyPadUSB\lib9ae\Adafruit_VL53L0X\core\src\vl53l0x_api_calibration.cpp.o
Compiling .pio\build\LilyPadUSB\lib9ae\Adafruit_VL53L0X\core\src\vl53l0x_api_core.cpp.o
Compiling .pio\build\LilyPadUSB\lib9ae\Adafruit_VL53L0X\core\src\vl53l0x_api_ranging.cpp.o
.pio\libdeps\LilyPadUSB\Adafruit_VL53L0X\src\core\src\vl53l0x_api_core.cpp: In function 'uint32_t VL53L0X_isqrt(uint32_t)':
.pio\libdeps\LilyPadUSB\Adafruit_VL53L0X\src\core\src\vl53l0x_api_core.cpp:124:23: warning: left shift count >= width of type [-Wshift-count-overflow]
   uint32_t bit = 1 << 30;
                       ^~
.pio\libdeps\LilyPadUSB\Adafruit_VL53L0X\src\core\src\vl53l0x_api_core.cpp: In function 'VL53L0X_Error VL53L0X_calc_sigma_estimate(VL53L0X_DEV, VL53L0X_RangingMeasurementData_t*, FixPoint1616_t*, uint32_t*)':
.pio\libdeps\LilyPadUSB\Adafruit_VL53L0X\src\core\src\vl53l0x_api_core.cpp:1716:22: warning: left shift count >= width of type [-Wshift-count-overflow]
     pwMult *= ((1 << 16) - xTalkCorrection);
                      ^~
.pio\libdeps\LilyPadUSB\Adafruit_VL53L0X\src\core\src\vl53l0x_api_core.cpp:1722:21: warning: left shift count >= width of type [-Wshift-count-overflow]
     pwMult += (1 << 16);
                     ^~
.pio\libdeps\LilyPadUSB\Adafruit_VL53L0X\src\core\src\vl53l0x_api_calibration.cpp: In function 'VL53L0X_Error VL53L0X_perform_xtalk_calibration(VL53L0X_DEV, FixPoint1616_t, FixPoint1616_t*)':
.pio\libdeps\LilyPadUSB\Adafruit_VL53L0X\src\core\src\vl53l0x_api_calibration.cpp:115:52: warning: left shift count >= width of type [-Wshift-count-overflow]
         (FixPoint1616_t)((uint32_t)(sum_ranging << 16) / total_count);
                                                    ^~
.pio\libdeps\LilyPadUSB\Adafruit_VL53L0X\src\core\src\vl53l0x_api_calibration.cpp:117:50: warning: left shift count >= width of type [-Wshift-count-overflow]
         (FixPoint1616_t)((uint32_t)(sum_spads << 16) / total_count);
                                                  ^~
.pio\libdeps\LilyPadUSB\Adafruit_VL53L0X\src\core\src\vl53l0x_api_calibration.cpp:159:18: warning: left shift count >= width of type [-Wshift-count-overflow]
           ((1 << 16) - (xTalkStoredMeanRange / xTalkCalDistanceAsInt));
                  ^~
.pio\libdeps\LilyPadUSB\Adafruit_VL53L0X\src\core\src\vl53l0x_api_calibration.cpp: In function 'VL53L0X_Error VL53L0X_perform_offset_calibration(VL53L0X_DEV, FixPoint1616_t, int32_t*)':
.pio\libdeps\LilyPadUSB\Adafruit_VL53L0X\src\core\src\vl53l0x_api_calibration.cpp:240:52: warning: left shift count >= width of type [-Wshift-count-overflow]
         (FixPoint1616_t)((uint32_t)(sum_ranging << 16) / total_count);
                                                    ^~
.pio\libdeps\LilyPadUSB\Adafruit_VL53L0X\src\core\src\vl53l0x_api_calibration.cpp: In function 'VL53L0X_Error VL53L0X_get_offset_calibration_data_micro_meter(VL53L0X_DEV, int32_t*)':
.pio\libdeps\LilyPadUSB\Adafruit_VL53L0X\src\core\src\vl53l0x_api_calibration.cpp:317:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (RangeOffsetRegister > cMaxOffset)
         ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
.pio\libdeps\LilyPadUSB\Adafruit_VL53L0X\src\core\src\vl53l0x_api.cpp: In function 'VL53L0X_Error VL53L0X_GetInterruptThresholds(VL53L0X_DEV, VL53L0X_DeviceModes, FixPoint1616_t*, FixPoint1616_t*)':        
.pio\libdeps\LilyPadUSB\Adafruit_VL53L0X\src\core\src\vl53l0x_api.cpp:2610:64: warning: left shift count >= width of type [-Wshift-count-overflow]
   *pThresholdLow = (FixPoint1616_t)((0x00fff & Threshold16) << 17);
                                                                ^~
.pio\libdeps\LilyPadUSB\Adafruit_VL53L0X\src\core\src\vl53l0x_api.cpp:2615:67: warning: left shift count >= width of type [-Wshift-count-overflow]
     *pThresholdHigh = (FixPoint1616_t)((0x00fff & Threshold16) << 17);
                                                                   ^~
Compiling .pio\build\LilyPadUSB\lib9ae\Adafruit_VL53L0X\core\src\vl53l0x_api_strings.cpp.o
Compiling .pio\build\LilyPadUSB\lib9ae\Adafruit_VL53L0X\platform\src\vl53l0x_i2c_comms.cpp.o
Archiving .pio\build\LilyPadUSB\lib192\libWire.a
Compiling .pio\build\LilyPadUSB\lib9ae\Adafruit_VL53L0X\platform\src\vl53l0x_platform.cpp.o
Archiving .pio\build\LilyPadUSB\libFrameworkArduinoVariant.a
Compiling .pio\build\LilyPadUSB\FrameworkArduino\CDC.cpp.o
Compiling .pio\build\LilyPadUSB\FrameworkArduino\HardwareSerial.cpp.o
Compiling .pio\build\LilyPadUSB\FrameworkArduino\HardwareSerial0.cpp.o
Compiling .pio\build\LilyPadUSB\FrameworkArduino\HardwareSerial1.cpp.o
Compiling .pio\build\LilyPadUSB\FrameworkArduino\HardwareSerial2.cpp.o
Compiling .pio\build\LilyPadUSB\FrameworkArduino\HardwareSerial3.cpp.o
Compiling .pio\build\LilyPadUSB\FrameworkArduino\IPAddress.cpp.o
Archiving .pio\build\LilyPadUSB\lib9ae\libAdafruit_VL53L0X.a
Compiling .pio\build\LilyPadUSB\FrameworkArduino\PluggableUSB.cpp.o
Compiling .pio\build\LilyPadUSB\FrameworkArduino\Print.cpp.o
Compiling .pio\build\LilyPadUSB\FrameworkArduino\Stream.cpp.o
Compiling .pio\build\LilyPadUSB\FrameworkArduino\Tone.cpp.o
Compiling .pio\build\LilyPadUSB\FrameworkArduino\USBCore.cpp.o
Compiling .pio\build\LilyPadUSB\FrameworkArduino\WInterrupts.c.o
Compiling .pio\build\LilyPadUSB\FrameworkArduino\WMath.cpp.o
Compiling .pio\build\LilyPadUSB\FrameworkArduino\WString.cpp.o
Compiling .pio\build\LilyPadUSB\FrameworkArduino\abi.cpp.o
Compiling .pio\build\LilyPadUSB\FrameworkArduino\hooks.c.o
Compiling .pio\build\LilyPadUSB\FrameworkArduino\main.cpp.o
Compiling .pio\build\LilyPadUSB\FrameworkArduino\new.cpp.o
Compiling .pio\build\LilyPadUSB\FrameworkArduino\wiring.c.o
Compiling .pio\build\LilyPadUSB\FrameworkArduino\wiring_analog.c.o
Compiling .pio\build\LilyPadUSB\FrameworkArduino\wiring_digital.c.o
Compiling .pio\build\LilyPadUSB\FrameworkArduino\wiring_pulse.S.o
Compiling .pio\build\LilyPadUSB\FrameworkArduino\wiring_pulse.c.o
Compiling .pio\build\LilyPadUSB\FrameworkArduino\wiring_shift.c.o
Archiving .pio\build\LilyPadUSB\libFrameworkArduino.a
Linking .pio\build\LilyPadUSB\firmware.elf
Checking size .pio\build\LilyPadUSB\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=====     ]  46.5% (used 1190 bytes from 2560 bytes)
Flash: [========  ]  76.2% (used 21838 bytes from 28672 bytes)
Building .pio\build\LilyPadUSB\firmware.hex
Configuring upload protocol...
AVAILABLE: avr109
CURRENT: upload_protocol = avr109
Looking for upload port...
Using manually specified: COM15
Forcing reset using 1200bps open/close on port COM15
Waiting for the new upload port...
Error: Couldn't find a board on the selected port. Check that you have the correct port selected. If it is correct, try pressing the board's reset button after initiating the upload.
*** [upload] Explicit exit, status 1

Would be grateful for any guidance on how I can upload code to my Arduino Lilypad USB development board again and how to troubleshoot or resolve this issue.

Thank you for your help!

Best regards
Eren Mustafa Ozdal

Bootloader issue: The symptoms suggest that there might be a problem with the bootloader. When you can’t connect to the board or upload new code and see “Couldn’t find a board on the selected port” often indicates that the bootloader is not responding correctly

Here are some additional steps you can try:

  1. Bootloader reflash:
  • If possible, use another Arduino board (like an Uno) to reflash the bootloader on your LilyPad. This process is called “Arduino as ISP” (In-System Programmer).
  • You’ll need to connect the two boards and use the “Arduino as ISP” sketch on the working board to reflash the bootloader on the LilyPad.
  1. Check for hardware issues:
  • Inspect the board for any visible damage, loose connections, or signs of short circuits.
  • If you have access to a multimeter, check for continuity and proper voltage levels on key pins.
  1. Try a different IDE:
  • If you haven’t already, try using the official Arduino IDE instead of PlatformIO (or vice versa).
  1. Timing issues:
  • Some boards can be sensitive to timing during the upload process. Try pressing the reset button on the LilyPad just as the upload process begins in the IDE.
  1. Drivers:
  • Although you mentioned updating drivers, ensure you have the correct FTDI drivers installed for your specific operating system version.
  1. Baud rate:
  • Try changing the baud rate in your code (e.g., from 9600 to 115200) and in the IDE settings. Sometimes, this can help with communication issues.

Finally make sure you’ve tried othe rports/cables/PCs if possible