Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    How do I get main.py to run when the WiPy board boots?

    Scheduled Pinned Locked Moved WiPy 2&3
    main.pywipybooterrorbug
    19 Posts 6 Posters 2.9k Views 7 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F Offline
      flatmop
      last edited by

      Hi guys

      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?

      Thanks

      robert-hhR 1 Reply Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @flatmop
        last edited by

        @flatmop I assume that the file was not uploaded permanently to the device. Please check with tools like ftp, that it was.

        F 1 Reply Last reply Reply Quote 0
        • F Offline
          flatmop @robert-hh
          last edited by

          @robert-hh It seems it was uploaded to the board correctly, I checked with Filezilla (FTP client) and the main.py file on the board contained my code correctly.

          robert-hhR 1 Reply Last reply Reply Quote 0
          • robert-hhR Offline
            robert-hh @flatmop
            last edited by

            @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.

            F 1 Reply Last reply Reply Quote 0
            • F Offline
              flatmop @robert-hh
              last edited by

              @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.

              robert-hhR 1 Reply Last reply Reply Quote 0
              • robert-hhR Offline
                robert-hh @flatmop
                last edited by

                @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).

                F 1 Reply Last reply Reply Quote 0
                • F Offline
                  flatmop @robert-hh
                  last edited by

                  This is my firmware version:

                  0_1532028438554_7d9d5e56-c314-4318-b9e8-46c305f50d6d-image.png

                  So I don't understand how main.py is not running unless there is a problem with the firmware...

                  robert-hhR 1 Reply Last reply Reply Quote 0
                  • robert-hhR Offline
                    robert-hh @flatmop
                    last edited by

                    @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
                    GND,
                    RX(P0)->TX(bridge) and
                    TX(P1)->RX(bridge),
                    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.

                    F 1 Reply Last reply Reply Quote 0
                    • F Offline
                      flatmop @robert-hh
                      last edited by

                      @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.

                      robert-hhR 1 Reply Last reply Reply Quote 0
                      • robert-hhR Offline
                        robert-hh @flatmop
                        last edited by

                        @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.

                        F 1 Reply Last reply Reply Quote 0
                        • F Offline
                          flatmop @robert-hh
                          last edited by

                          @robert-hh I ordered from RS Components.

                          1 Reply Last reply Reply Quote 0
                          • J Offline
                            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')
                            
                            1 Reply Last reply Reply Quote 1
                            • X Offline
                              Xykon administrators
                              last edited by

                              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.py in that version.

                              Christian Ehlers

                              F 1 Reply Last reply Reply Quote 0
                              • F Offline
                                flatmop
                                last edited by

                                @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.

                                robert-hhR 1 Reply Last reply Reply Quote 0
                                • robert-hhR Offline
                                  robert-hh @flatmop
                                  last edited by

                                  @flatmop That is the expected behavior, which you should get after an update of the firmware.

                                  F 1 Reply Last reply Reply Quote 0
                                  • F Offline
                                    flatmop @Xykon
                                    last edited by

                                    @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.

                                    danD 1 Reply Last reply Reply Quote 0
                                    • F Offline
                                      flatmop @robert-hh
                                      last edited by

                                      @robert-hh I see. Perhaps they should make this more obvious in the "Getting Started" guide.

                                      1 Reply Last reply Reply Quote 0
                                      • danD Offline
                                        dan @flatmop
                                        last edited by

                                        Hi @flatmop,

                                        That is the case, main.py runs automatically (just tried it)

                                        T 1 Reply Last reply Reply Quote 0
                                        • T Offline
                                          timh @dan
                                          last edited by

                                          @dan Yep I have never put anything in boot.py, have always had main.py run without intervention.

                                          1 Reply Last reply Reply Quote 0

                                          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                          With your input, this post could be even better 💗

                                          Register Login
                                          • 1 / 1
                                          • First post
                                            Last post

                                          Pycom on Twitter

                                          Pycom