Typical Errors Using MicroPython on Pico2
When programming the Raspberry Pi Pico2 with MicroPython, you may encounter various errors. Below are some common errors and how to resolve them.
1. Syntax Errors
Example:
Error Message:
Cause: Missing parentheses in print() (MicroPython uses Python 3 syntax).
Fix:
2. Indentation Errors
Example:
Error Message:
Cause: Python requires proper indentation for blocks of code.
Fix:
3. Name Errors
Example:
Error Message:
Cause: The variable msg has not been defined before being used.
Fix:
4. Type Errors
Example:
Error Message:
Cause: Concatenating a string and an integer directly.
Fix: Convert the integer to a string:
5. Import Errors
Example:
Error Message:
Cause: The module does not exist or is incorrectly named.
Fix: Check for the correct module name:
6. Memory Errors
Example:
Error Message:
Cause: Trying to allocate too much memory on the Pico2.
Fix: Use smaller data structures or optimize memory usage:
7. Device Not Found (USB Connection Issues)
If the the device is not responding or just looks the new code not uploading to device or get an error message that
Error Message:
or
Cause: The Pico2 is not properly connected, or the serial port is not detected.
Fix: - Check that the USB cable supports data transfer. - Ensure the Pico2 is in bootloader mode (hold BOOTSEL while plugging in). - Restart your development environment (Thonny, MPRemote, etc.).
8. Pin doesn't have ADC capabilities
Example:
import machine
ADC_CHANNEL = 5 #ADC channel 5 does not exist.
temp_sensor = machine.ADC(ADC_CHANNEL)
Cause: A non-existing ADC channel was selected, or a port without ADC capabilities.
Fix: Refer the datasheet for ADC channels and ports.
Pinout

If the correct ADC channel or Pin object is selected and it is not working, perform a firmware update to the latest version.
9. Bound Method
Example:
import machine
import time
Battery = machine.ADC(28)
while True:
raw_battery_voltage = Battery.read_u16
print(raw_battery_voltage)
time.sleep(1)
Cause:
This error is often caused by a missing pair of parentheses () at the end of a method.
Fix: