Multiple electronic projects with (or without) MicroControllers
For managing the different programs and libraries used for my electronic projects, I use DevBox. For installing DevBox run:
curl -fsSL https://get.jetpack.io/devbox | bash
Once installed, just execute devbox shell
to get into a Shell with all the programs a libraries you need. Within this DevBox Shell, you can still use your favourite IDEs.
The following programs are available in your DevBox shell, either provided directly by devbox
(see devbox.json
) or poetry
(via pyproject.toml
):
- Thonny
- ESPTool
- Python 3.11.
- Ruff, for code formatting.
- rshell, for remote execution of Python files.
- pre-commit, for making sure that committed files look nice.
- Poetry, for managing a Python Virtual environment with the project libraries.
- Arduino IDE
- mpremote, a command line tool or uploading files to Micro Python devices.
- pipkin, tool for installing distribution packages for MicroPython and CircuitPython.
- Fritzing, fantastic tool for creating schematics.
rshell cp program.py /pyboard/main.py
For installing libraries into the ESP32 running CircuitPython, I found easier to use [pipkin](GitHub - aivarannamaa/pipkin: Tool for installing distribution packages for MicroPython and CircuitPython) instead of circup
. Some examples:
pipkin --port /dev/ttyUSB0 install adafruit-circuitpython-mcp230xx
pipkin --port /dev/ttyUSB0 install adafruit-circuitpython-charlcd
To setup WiFi on ESP32 with CircuitPython we need to create a file called settings.toml
in the root of the file system.
-
Use Thonny to connect to the REPL of the board
-
Use the following snippet for creating the file
f = open('settings.toml', 'w')
f.write('CIRCUITPY_WIFI_SSID = "wifissid"\n')
f.write('CIRCUITPY_WIFI_PASSWORD = "wifipassword"\n')
f.write('CIRCUITPY_WEB_API_PASSWORD = "webpassword"\n')
f.close()
-
Restart the REPL using Thonny. Using the button will not work ¯_(ツ)_/¯
-
IP and MAC can be obtained using this code
import wifi
print("My MAC addr: %02X:%02X:%02X:%02X:%02X:%02X" % tuple(wifi.radio.mac_address))
print("My IP address is", wifi.radio.ipv4_address)
More details here.
For installing libraries, take the following precautions:
-
Close Thonny
-
Reconnect the ESP32 device (unplug, and plug again)
-
Install the libraries one by one
pipkin --port /dev/ttyUSB0 install adafruit-circuitpython-bme680
pipkin --port /dev/ttyUSB0 install adafruit-circuitpython-minimqtt