solvaholic / micropython

@solvaholic's MicroPython scripts
MIT License
0 stars 0 forks source link

Build and upload outside of Arduino IDE #4

Closed solvaholic closed 8 months ago

solvaholic commented 9 months ago

I like the Arduino IDE, it makes all the steps super easy. For editing code, tho, I prefer using VS Code. I'd also like to lint, build, and test regardless of IDE, for example on a GitHub Actions runner. How to build a sketch and upload it, without using the Arduino IDE?

### Tasks
- [x] Understand [the sketch build process](https://arduino.github.io/arduino-cli/sketch-build-process/)
- [x] Build and upload with `arduino-cli`
- [x] Build and upload with VS Code (/cc https://github.com/solvaholic/arduino/issues/4#issuecomment-1826360930)
- [ ] Lint and build in a Codespace
- [ ] Lint and build in an Actions workflow
- [ ] What sort of testing is possible locally, without uploading?
solvaholic commented 9 months ago

Maybe helpful

If you find yourself thinking a Makefile will help, check out sudar/Arduino-Makefile and Sudar's blog.

If you find yourself wanting to run builds in a container, check out some prior art: https://hub.docker.com/r/arduinoci/ci-arduino-esp32 https://hub.docker.com/r/domatic/arduino

solvaholic commented 9 months ago

Understand the sketch build process

I think that's sort of like:

solvaholic commented 9 months ago

Build and upload with arduino-cli

I think I'd like to have arduino-cli download and install libraries in my clone of this repo. And I'd like to control which configuration file it uses. Docs say arduino-cli will use the config file specified by --config-file option, or the one stored in directories.data.

Can you guess where directories.data is written? It seems like I'll need to either overwrite the default config file or specify a --config-file each time I run arduino-cli.

8052acab71 creates script/bootstrap.sh to set up the local arduino-cli configuration file, arduino-cli.yaml.

solvaholic commented 9 months ago

Build and upload with arduino-cli

f97260bde5 updates script/bootstrap.sh to install Arduino core and libraries. After that, this seems to do the trick:

cd ~/repos/arduino
./script/bootstrap.sh

_port=/dev/cu.usbserial-0001
_board=Heltec-esp32:esp32:wifi_kit_32
_sketch=esp32_hello

arduino-cli --config-file ./arduino-cli.yaml \
compile -b $_board $_sketch 

arduino-cli --config-file ./arduino-cli.yaml \
board attach -p $_port -b $_board \
--board-options "UploadSpeed=115200" \
$_sketch

arduino-cli --config-file ./arduino-cli.yaml \
upload $_sketch
solvaholic commented 9 months ago

Build and upload with VS Code

Microsoft's extension looks like it should Just Work: https://github.com/microsoft/vscode-arduino

For me, however, it did not. In case I come back to it, or you're facing similar challenges, here are a few of the issues I was unable to pass:

Using Arduino IDE costs me less time and attention than troubleshooting that mess.

solvaholic commented 9 months ago

Using Arduino IDE costs me less time and attention than troubleshooting that mess.

And maintaining my own build and upload scripts costs even less, so 5fdb9189ef introduces those. Now my environment is easily reproducible, I don't have to remember the steps, and I can work in my preferred editor.