# Set program to run on boot

**URL:** <https://xrp.discourse.group/t/set-program-to-run-on-boot/671>\
**Category:** General\
**Created:** [April 1, 2025, 10:46am UTC](https://xrp.discourse.group/t/set-program-to-run-on-boot/671 "2025-04-01T10:46:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jabberhams](https://avatars.discourse-cdn.com/v4/letter/j/ba8739/32.png) [@jabberhams](https://xrp.discourse.group/u/jabberhams)\
**Post date:** [April 1, 2025, 10:46am UTC](https://xrp.discourse.group/t/set-program-to-run-on-boot/671/1 "2025-04-01T10:46:10Z")

</div>

Continuing the discussion from [Run program on boot](https://xrp.discourse.group/t/run-program-on-boot/78):

Is there a way to set the program to run on boot without clicking _Run_ in XRPCode?

---

<div class="post-metadata">

**Author:** ![Fgrossman](https://avatars.discourse-cdn.com/v4/letter/f/b77776/32.png) [@Fgrossman](https://xrp.discourse.group/u/Fgrossman)\
**Post date:** [April 2, 2025, 1:46am UTC](https://xrp.discourse.group/t/set-program-to-run-on-boot/671/2 "2025-04-02T01:46:34Z")

</div>

MicroPython first looks for a file called boot.py and then looks for main.py. XRPCode hides main.py for a better user experience, and modifies it when you hit run. Our main.py does a number of things including setting up the bluetooth to connect remotely and resets the XRP to a known state when a program ends or gets an exception.  
Depending on what you are trying to do.

- One way to start a program but have it wait is to put a wait\_for\_button() at the beginning of the program. There is a block for this as well.
- You can use another editor like Thonny that will allow you to edit the main.py, you can replace it with your own code, or you will see that we compile and then run a specific program and you can modify the program that it runs.
- I have not tried playing with boot.py, but you could also do that.

---

<div class="post-metadata">

**Author:** ![kayce](https://yyz1.discourse-cdn.com/flex011/user_avatar/xrp.discourse.group/kayce/32/284_2.png) [@kayce](https://xrp.discourse.group/u/kayce)\
**Post date:** [April 3, 2025, 4:39pm UTC](https://xrp.discourse.group/t/set-program-to-run-on-boot/671/3 "2025-04-03T16:39:27Z")

</div>

XRP Code doesn’t use `boot.py`, right? It’s just an option that MicroPython would support, if it existed. When I list files via the MicroPython REPL I don’t see that file:

```auto
>>> import os
>>> os.listdir()
['XRPExamples', 'lib', 'main.py']

```

Here’s what `main.py` looks like for me:

```auto
import os
import sys
import time
FILE_PATH = '/lib/ble/isrunning'
doNothing = False
x = os.dupterm(None, 0)
if(x == None):
   import ble.blerepl
else:
   os.dupterm(x,0)
try:
   with open(FILE_PATH, 'r+b') as file:
      byte = file.read(1)
      if byte == b'\x01':
         file.seek(0)
         file.write(b'\x00')
         doNothing = True
      else:
         file.seek(0)
         file.write(b'\x01')
   if(not doNothing):
       with open('/XRPExamples/installation_verification.py', mode='r') as exfile:
           code = exfile.read()
       execCode = compile(code, 'XRPExamples/installation_verification.py', 'exec')
       exec(execCode)
       with open(FILE_PATH, 'r+b') as file:
           file.write(b'\x00')
except Exception as e:
   import sys
   sys.print_exception(e)
   with open(FILE_PATH, 'r+b') as file:
      file.write(b'\x00')
finally:
   import gc
   gc.collect()
   if 'XRPLib.resetbot' in sys.modules:
      del sys.modules['XRPLib.resetbot']
   import XRPLib.resetbot

```

A fun hack might be to set up a small display and a couple buttons that let you choose what program to run at runtime. E.g. you press button A and the display shows the name of one of your scripts. Press button A again and it shows a different script. If you press button B then it executes whatever script is currently being displayed on the screen.

---

<div class="post-metadata">

**Author:** ![TFossDK](https://avatars.discourse-cdn.com/v4/letter/t/bbe5ce/32.png) [@TFossDK](https://xrp.discourse.group/u/TFossDK)\
**Post date:** [May 7, 2025, 1:42pm UTC](https://xrp.discourse.group/t/set-program-to-run-on-boot/671/4 "2025-05-07T13:42:56Z")

</div>

Hi Kace,

I put something together similar to exactly what you are describing by adding an encoder and a screen along with a buzzer. Here is the writeup on it that i put together on the build [Innovate with Ease: XRP, Qwiic Encoder, OLED, Buzzer Guide](https://www.digikey.com/en/maker/projects/streamline-robot-control-build-an-xrp-program-selector/c41d399bd58b42f99f9d9e81a07a7135)
