How do I get main.py to run when the WiPy board boots?
I am just starting out with the Getting Started tutorial, on the "My First Pymakr Project" section. I am using Pymakr for Atom. I have created a main.py file and put into it the following example code from the tutorial:
import pycom import time pycom.heartbeat(False) while True: print("Program is running...") pycom.rgbled(0x161600) # Red time.sleep(1) pycom.rgbled(0x001616) # Green time.sleep(1) pycom.rgbled(0x160016) # Blue time.sleep(1)
When I click "run" the program runs exactly as expected. However, when I click "upload", the files appear to upload succesfully, but when the board reboots, it reverts to the default heartbeat LED pattern and nothing is printed to the console. This suggests my main.py program is not being started when the board reboots.
I have checked the contents of main.py on the board via Filezilla and they are correct, which suggests that there is no problem with Pymakr syncing the project files on the board.
So unless I am misunderstanding, when the board boots up it should execute boot.py (which I have not put any code into) and then main.py automatically, and I should not have to do anything else? The pycom and time modules are built into the firmware, so it could not be that they are missing and preventing main.py from running. Any ideas what might be causing this?
timh last edited by
dan last edited by
That is the case,
main.pyruns automatically (just tried it)
@robert-hh I see. Perhaps they should make this more obvious in the "Getting Started" guide.
@xykon I updated the firmware to the latest version with the Expansion Board 2.0, but that did not help. It was only when I tried @james-matthews's suggestion that I got it to work, which seems strange. The "getting started" guide gives the impression that once uploaded to the board, main.py should run automatically without needing a boot.py.
@flatmop That is the expected behavior, which you should get after an update of the firmware.
@james-matthews Ok thanks, created a boot.py with this code in it, and it now runs my RGB program when the WiPy is reset. Success! I feel as though this is some sort of hack or workaround however, as nowhere in the "Getting Started" guide does it say that you need a boot.py for this, it suggests as though main.py should run anyway.
You need to update the firmware first.
The WiPy2 firmware that is flashed during production is very old and from what I remember there was indeed an issue with loading the
main.pyin that version.
james.matthews last edited by
boot.py tells the board what to do. If nothing is in boot then nothing will happen.
Add this to boot.py:
from machine import UART import machine import os uart = UART(0, baudrate=115200) os.dupterm(uart) machine.main('main.py')
@robert-hh I ordered from RS Components.
@flatmop I don't know whether you get an expansion board 2. AFAIK, they are not sold any more by PyCom. But distributors may have them still on stock.
@robert-hh I don't have a USB to UART bridge with 3.3V TTL output to hand at the moment. I though it safer to just order the Expansion Board 2.0. When it arrives (despatch tommorow and next working day delivery, so Monday...), I will update the firmware and see if that fixes the issue. If it doesn't I guess my board must have some hardware defect, perhaps ESD damage to the flash memory or something.
@flatmop That's strange. And that version also does not reboot on Ctrl-F. Besides that, upgrading the firmware is advisable. You do not need an expansion board. Any USB/UART bride with TTL output at 3.3V level will do as well. You have to connect
connect P2 to GND and push reset. Then the device is in upload mode and you can run the firmware updater to do its magic.
This is my firmware version:
So I don't understand how main.py is not running unless there is a problem with the firmware...
@flatmop main.py should run in any version. In Filezilla it should get visible at /flash/main.py.
You can also telnet to the device to get an REPL prompt. When you push Ctrl-B at the REPL prompt or issue the commands:
import uos uos.uname()
you will see the version number(s).
@robert-hh Ok, I tried resetting the device by pressing the pushbutton but it made no difference. I also tried grounding P12 with a wire but this also made no difference.
Is it possible to determine or change from the REPL whether or not the board is running in Safe Boot mode?
Might be worth mentioning that I have not updated the firmware yet as I don't have any expansion boards. I guess I will have to order an Expansion Board 2.0 and update to the latest firmware, see if that makes any difference.
@flatmop Then it should be executed, unless the device is in safeboot mode. That is caused by.
- booting with P12 at High level
- software reboot from REPL with Ctrl-F.
The latter method is used by pymakr, as far as I know (I'm not using pymakr). To exclude that, close pymakr and reboot by pushing the reset button on the device.
@flatmop I assume that the file was not uploaded permanently to the device. Please check with tools like ftp, that it was.