The peripheral device has been tested with an ESP32 DevKitc V4 (The new design uses ESP32C3-WROOM-02 module), is writen in MicroPython, and is designed to run on bare metal. The code makes use of its bluetooth and uasyncio libraries. The code also relies on
- aioble, an asynchronous wrapper for MicroPython's
ubluetoothAPI. - a modified version of micropython-ota-updater, which allows for automatic code updates from GitHub
Micropython is just a barebone version of Python. The libraries availiable to you can be found here and here.
If you ever get a new microcontroller, you will need to make sure that micropython is installed on the device. First, install esptool.py by downloading it from the source or running pip install esptool. Then, download the appropriate firmware. Simply follow the directions found on the download page to update firmware.
Make sure to plug in your device and replace ttyUSB0 with the actual serial port that the controller is plugged into. The list of ports on Linux can be found by running ls /dev. If you are using WSL, open your Windows Device Manager and look under the Ports category. You should see the microntontroller connected to a COM port, such as COM4. In this case, the correct path to the device should be /dev/ttyS4.
So many things go wrong, and if they do, this is the place for you.
You have the serial connected with some other program. Since only one program can access the serial port at a time, you have to disconnect the other program.
This could be so, so many things, but first try changing the baud rate to 115200. If that doesn't work, the device may not be in boot mode. To enable boot mode, hold both the BOOT and EN, then release EN. Check out this thread for more information.
Uploading code to the microcontroller will either work the first time or be the most painful experience you've had for a while. Hopefully, the VS Code method simply works for you. However, there have been issues in the past. If it doesn't work for you, don't spend too much time on it and just use the second method.
Before proceding, make sure you have the following installed:
To start, plug the microcontroller in and open VScode. Type ctrl + shift+ p and select the Get Started: Open Walkthrough... > Pymakr 2 - Getting Started option. Follow the Connect a Device tutorial to gain access to the microcontroller. To then run files:
- Download this repo to your local device.
- Open the project folder
../hfs.main/sensor/client(you may be prompted to create a new project, which is okay, just make sure you don't select any of the default package options... ALL of them will eraseboot.pyandmain.pywhich just kinda sucks). - Enable
dev-modefor the project in the pymakr window (optional). - Click the sync project to device button to upload and run your file (not required if
dev-modeis enabled).
So many things go wrong, and if they do, this is the place for you.
This error is a generic
resource is busyerror. To resolve it, try hard resetting the device in VS Code. You will probably have to do this everytime you pressctrl + cto stop the program.
On boot, the device will automatically load the boot.py then main.py files. On boot, main.py will begin scanning for peripherals and connect to them if everything works. Currently, programs are halted via ctrl + c.
If you have found yourself here, I am very sorry. However, things can still work (kinda)! Your first goal is to access the serial prompt of the device so that you can see your debug statements. This isn't required, but really really helps in debugging and making sure things are running properly. On Linux, this can be done via the command line tool picocom (sudo apt-get install picocom) or minicom (sudo apt-get install minicom). On Windows, TeraTerm is reccomended.
You can also try and access the webrepl, which is technically enabled upon boot by the device. However, it refuses to connect over https, so that method doesn't work too well. Technically, the ESP32 is also supposed to advertise a Wi-Fi network when it doesn't connect to one, but I have found that it simply does not for whatever reason. You can find tutorials walking through these methods here and here, though don't have much hope for them.
Once you have a serial connection of some sort, switch over to the dev-deploy branch and follow the directions found there. The dev-deploy branch allows you to upload your code to GitHub and have the microcontroller automatically download the update.
There also should be some way to copy files directly over the REPL, but I haven't looked into it too much. Feel free to explore this if you dare!
It's python...... It would run boot.py upon booting before entering main.py, from which it will be running.
- Set up pin-config in
device_pin.py - Create an install script for the microcontroller code
- Integrate L0 ToF into the program