|
1 | 1 | # Setup and Using MicroPython
|
| 2 | + |
| 3 | +## Contents |
| 4 | +* [Supported Platforms](#hardware) |
| 5 | +* [Latest MicroPython Firmware Downloads](#latest-micropython-firmware-downloads) |
| 6 | +* [Suggested Development Environments](#suggested-development-environments) |
| 7 | +* [Drivers](#drivers) |
| 8 | + |
| 9 | +## Supported Platforms |
| 10 | + [SparkFun Pro Micro RP2350](https://www.sparkfun.com/sparkfun-pro-micro-rp2350.html), [SparkFun IoT RedBoard ESP32](https://www.sparkfun.com/sparkfun-iot-redboard-esp32-development-board.html), [SparkFun IoT RedBoard RP2350](https://www.sparkfun.com/sparkfun-iot-redboard-rp2350.html) |
| 11 | + |
| 12 | +## Latest MicroPython Firmware Downloads |
| 13 | +Get our latest MicroPython firmware for your board from our [MicroPython release page](https://github.com/sparkfun/micropython/releases). Different platforms have different methods of flashing: |
| 14 | + |
| 15 | + |
| 16 | +## RP2 Boards |
| 17 | +While connected to your computer, hold the "boot" button on the RP2 board while you press and release the "reset" button to enter bootloader mode. Your board will appear as a regular drive on your computer that you can add files to. Drag and drop the correct .uf2 file from the most recent release from the link above onto your board and it will reboot, now running MicroPython. |
| 18 | + |
| 19 | +Connect to it with one of the [suggested development environments](#suggested-development-environments) below. |
| 20 | + |
| 21 | +## ESP32 Boards |
| 22 | +Download the .zip archive for your board from the release link above and extract it. If you have not already, [download the esptool utility](https://docs.espressif.com/projects/esptool/en/latest/esp32/installation.html). Then, use ```esptool``` to flash your board using the command specified in the README.md contained in the .zip archive you downloaded for your board. Make sure you run the command from within that directory as well. For example, one ESP32 release contains a `bootloader.bin`, `partition-table.bin`, and `micropython.bin`. |
| 23 | + |
| 24 | +## Suggested Development Environments |
| 25 | + |
| 26 | +### Thonny |
| 27 | +[Thonny](https://thonny.org/) is an IDE that provides a GUI environment for MicroPython development. Connect your board with MicroPython firmware to your computer and then configure your interpreter by clicking the bottom right-hand corner of Thonny. |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +Select the version of MicroPython that makes the most sense for your board. Not sure? Select ```MicroPython (generic)```. |
| 32 | + |
| 33 | +This will connect to your board and show a Python REPL in the "shell" tab. To run a MicroPython program, open it from the ```MicroPython device``` tab. Then press the green arrow (Run Current Script). If you ever want to stop the running program, soft reset your board, or reconnect to your board, click the red stop sign (Stop/Restart backend). |
| 34 | + |
| 35 | +### MicroPython remote control: mpremote |
| 36 | +[mpremote](https://docs.micropython.org/en/latest/reference/mpremote.html) is a command line utility that provides tons of options for interfacing with a MicroPython board. A simple way to use it is to execute it standalone with no options. If you have installed mpremote you can simply execute ```mpremote``` in a command line to get direct access to the Python REPL on your board. A useful way to navigate the file system from this repl is to execute ```import os``` and then use the `os` methods. For example, ```os.listdir()``` will show everything in the current directory on your MicroPython board. ```os.getcwd()``` will print the name of the current directory and ```os.chdir('dir_name')``` will change the directory. An example of navigating around directories for a user who has installed the [mpy_tmp117_web_server](https://github.com/sparkfun/sparkfun-python/tree/main/examples/mpy_tmp117_web_server) demo from this repository can be seen below. |
| 37 | + |
| 38 | +``` |
| 39 | +C:\Users\qwiic_guy> mpremote |
| 40 | +
|
| 41 | +Connected to MicroPython at COM14 |
| 42 | +Use Ctrl-] or Ctrl-x to exit this shell |
| 43 | +MicroPython on SparkFun IoT RedBoard RP2350 with RP2350 |
| 44 | +Type "help()" for more information. |
| 45 | +>>> |
| 46 | +>>> |
| 47 | +>>> import os |
| 48 | +>>> os.listdir() |
| 49 | +['lib', 'static', 'tmp117_server_ap.py'] |
| 50 | +>>> os.getcwd() |
| 51 | +'/' |
| 52 | +>>> os.chdir('static') |
| 53 | +>>> os.getcwd() |
| 54 | +'/static' |
| 55 | +>>> os.listdir() |
| 56 | +['index.css', 'index.html', 'logo.png'] |
| 57 | +``` |
| 58 | + |
| 59 | +Once you have navigated to the directory containing the python script that you want to run, run it with the exec command: |
| 60 | + |
| 61 | +``` |
| 62 | +>>> exec(open('your_script.py').read()) |
| 63 | +``` |
| 64 | + |
| 65 | +To get files from your computer onto your micropython board you can use ```mpremote cp``` or install them directly from repositories that support mip installation with ```mpremote mip install github:reponame``` for example, to install our qwiic_i2c_py driver, execute |
| 66 | + |
| 67 | +``` |
| 68 | +mpremote mip install github:sparkfun/qwiic_i2c_py |
| 69 | +``` |
| 70 | + |
| 71 | +## Drivers |
| 72 | +Check out our growing list of Python Drivers: [https://github.com/topics/sparkfun-python](https://github.com/topics/sparkfun-python) |
| 73 | + |
| 74 | + |
0 commit comments