Autorun of main.py/boot.py does not work with micropython 1.23.0 on Raspberry Pi Pico -- FIXED #15292
-
Environment
DetailsI have a number of Raspberry Pi Pico and Pico W boards purchased from Adafruit. The boards all appear to work properly, except that the Pico boards will not autorun main.py/boot.py on powerup, i.e. when the board is plugged into USB. If I use Thonny (version 4.1.4) and type [Ctrl] d in the shell, then MicroPython soft reboots and main.py works as expected. Note that the exact same code works properly on the Raspberry Pi Pico W, that is main.py autoruns when the board is plugged into USB. External ReferenceBlog post containing code listing and photo of setup is here: |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 17 replies
-
Please verify that boot.py and main.py have been uploaded to the board's file system. And if yes, try another terminal emulator instead of Thonny, like mpremote, putty, screen, picocom, depending on you PC's OS. |
Beta Was this translation helpful? Give feedback.
-
I used the official RPI_PICO-20240602-v1.23.0.uf2 with RP Pico (no Wifi). Add |
Beta Was this translation helpful? Give feedback.
-
Another way to test this is to force a full reset from the REPL when connected (using It's possible that your code is actually running at power-up but To test this theory, add a
to see what's happening without the soft-reset. |
Beta Was this translation helpful? Give feedback.
-
@wbeebe I just tried this version of your import machine as ma
import binascii
import platform
import os
import gc
import time
print("starting main.py")
time.sleep(5)
print(f" reset reason: {ma.reset_cause()}")
print(f" MEM FREE: {gc.mem_free():,} BYTES")
UNAME = os.uname().sysname.upper()
stat_vfs = os.statvfs('/')
print(f" FS TOTAL: {stat_vfs[0] * stat_vfs[2]:,} BYTES")
print(f" FS FREE: {stat_vfs[0] * stat_vfs[3]:,} BYTES")
print(f" PLATFORM: {platform.platform()}")
UNIQUE_ID = binascii.hexlify(ma.unique_id()).decode('ascii').upper()
print(f" UID: {UNIQUE_ID}")
SSID = UNAME + '-' + UNIQUE_ID[-4:]
print(f" SSID: {SSID}")
print(f" CPU FREQ: {ma.freq():,} Hz")
# Scan I2C bus for devices
#
# I2C pins for Raspberry Pi Pico W, device I2C1
#
SDA_PIN = 26
SCL_PIN = 27
SOFT_I2C = ma.SoftI2C(scl=ma.Pin(SCL_PIN), sda=ma.Pin(SDA_PIN))
print(f" I2C: {SOFT_I2C}")
i2c_scanned = SOFT_I2C.scan()
if len(i2c_scanned) == 0:
print(" I2C: No Devices Found")
else:
print(" I2C: DEVICES FOUND:", [hex(device_address)
for device_address in i2c_scanned])
# Check if there is an SSD1306 display attached.
#
import SSD1306
import framebuf
if SSD1306.OLED_ADDR in i2c_scanned:
print(" I2C: SSD1306 OLED")
#
# Create instance of SSD1306 class to control the display.
# Initialize it by clearing everything.
#
display = SSD1306.SSD1306_I2C(SOFT_I2C)
display.fill(0)
#
# Create a graphic of the Raspberry Pi logo.
# Display it twice, one logo for each RP2040 core, similar to what
# the regular Raspberry Pi does on initial boot.
# I copied the bytearray for the logo from Raspberry Pi itself:
# https://github.com/raspberrypi/pico-micropython-examples/tree/master/i2c
#
buffer = bytearray(b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x7C\x3F\x00\x01\x86\x40\x80\x01\x01\x80\x80\x01\x11\x88\x80\x01\x05\xa0\x80\x00\x83\xc1\x00\x00C\xe3\x00\x00\x7e\xfc\x00\x00\x4c\x27\x00\x00\x9c\x11\x00\x00\xbf\xfd\x00\x00\xe1\x87\x00\x01\xc1\x83\x80\x02A\x82@\x02A\x82@\x02\xc1\xc2@\x02\xf6>\xc0\x01\xfc=\x80\x01\x18\x18\x80\x01\x88\x10\x80\x00\x8c!\x00\x00\x87\xf1\x00\x00\x7f\xf6\x00\x008\x1c\x00\x00\x0c\x20\x00\x00\x03\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
raspberry_pi_logo = framebuf.FrameBuffer(buffer, 32, 32, framebuf.MONO_HLSB)
display.framebuf.blit(raspberry_pi_logo, 0, 33)
display.framebuf.blit(raspberry_pi_logo, 33, 33)
#
# Display the official MicroPython logo
#
display.framebuf.fill_rect(0, 0, 32, 32, 1)
display.framebuf.fill_rect(2, 2, 28, 28, 0)
display.framebuf.vline(9, 8, 22, 1)
display.framebuf.vline(16, 2, 22, 1)
display.framebuf.vline(23, 8, 22, 1)
display.framebuf.fill_rect(26, 24, 2, 4, 1)
#
# Print some identifying text with the graphics, such as version and
# the identifying string of the Raspberry Pi Pico.
#
display.text('MicroPython', 40, 0, 1)
display.text('-'.join(platform.platform().split('-')[1:3]), 40, 12, 1)
display.text(SSID, 40, 24, 1)
display.show()
print()
try:
import network
wifi = network.WLAN(network.STA_IF)
wifi.active(True)
access_points = wifi.scan()
networks = {}
for network in access_points:
if len(network[0]) > 0 and bytearray(network[0])[0] != 0:
ssid = network[0].decode('utf-8')
networks[ssid] = network[3]
for ssid in sorted(networks.keys()):
print(f"ssid: {ssid:24} rssi: {networks[ssid]}")
except:
print(" NETWORK: NO WIFI ON DEVICE")
print() I started the board up and hit ctrl-D, and got this:
Then I turned the power off and back on and got this:
Reset reason 1 is machine.PWRON_RESET, and 3 is machine.WDT_RESET (which is used for soft reset on the RP2). So it's definitely not that |
Beta Was this translation helpful? Give feedback.
-
@wbeebe - I tried your code, this time on a Pico W with no I2C LED attached. This is the output I get from main.py:
In order to see if the code was being run on USB connect with no terminal present, I added these lines at the end: import time
led=ma.Pin("LED", ma.Pin.OUT)
led.value(1)
time.sleep(1)
led.value(0) This flashes the internal LED for one second on successful completion of To repeat @bikeNomad's result, I tried a regular Raspberry Pi Pico and got the expected result, complete with LED flash. So I'm very much afraid to say I can't repeat your issue. One detail I did notice when I tried to add an I²C SSD1306 OLED was that the SSD1306 module you used has some incompatible methods compared to the official ssd1306 module. I installed the official module using |
Beta Was this translation helpful? Give feedback.
-
SOLUTIONThe solution is in two parts.
The code section that sets up the I2C buss now looks like this: SDA_PIN = 8 # Blue wire
SCL_PIN = 9 # Yellow wire
SOFT_I2C = ma.SoftI2C(scl=ma.Pin(SCL_PIN), sda=ma.Pin(SDA_PIN), freq=100000) UPDATE 18 June 2024One other issue I've discovered is timing. Based on several comments, I added the following at the start of the import time
time.sleep_ms(500) That half-a-second doesn't help the Pico W, but it appears to help the original Pico. With that delay at the start the original Pico starts consistently every time power is applied. I have to wonder if that half-a-second is allowing something within the RP2040 to settle after power-on. |
Beta Was this translation helpful? Give feedback.
SOLUTION
The solution is in two parts.
main.py
executed completely every time and both text and graphics were drawn on the attached …