Getting Started
In this guide, you will find instructions on how to start programming software for microcontrollers in AssemblyScript and Rust by using WARDuino.
📦️ Prerequisites
- node and npm
- arduino toolchain: see our guide
✨ Installation
To start writing programs for WARDuino in your favorite language you need to install the WARDuino language library.
Prerelease libraries
The WARDuino library packages for AssemblyScript and Rust have not been released officially yet. You can download them from GitHub.
npm install 'https://gitpkg.now.sh/TOPLLab/WARDuino-libs/glue/assemblyscript?main'
cargo install warduino
The language library provides access to the primitives of WARDuino directly from AssemblyScript or Rust. Once you have written your program and compiled it to WebAssembly, you need to install WARDuino and the toolchains of the platform you are targeting.
cd $HOME/Arduino/libraries/
git clone --recurse-submodules --branch v0.5.1 git@github.com:TOPLLab/WARDuino.git
WARDuino currently supports both the Arduino and ESP-IDF toolchains. To use Arduino, you need to install the arduino-cli. For ESP-IDF you need to install the full toolchain, instructions can be found on the official website.
🎉 Your First Project
To get started quickly, you can use the AssemblyScript template.
git clone git@github.com:TOPLLab/as-warduino-template.git
cd as-warduino-template
npm i
Now you can compile the example program.
npm run build
Now you can flash your program.
cd ~/Arduino/libraries/WARDuino/
📸 Flashing using Arduino
After setting up the Arduino toolchain, you can upload your programs with the Makefile in the platforms/Arduino
folder of the WARDuino virtual machine. You can supply all the arguments through the command-line, or write all of them in a .config
file in the same directory as the Makefile.
PORT = /dev/ttyUSB0
FQBN = esp32:esp32:esp32wrover
PAUSED = true
BINARY = /path/to/test.wasm
Starting from the root of the WARDuino repository, run the following commands:
cd platforms/Arduino
make compile
make flash
Command-line arguments always overwrite commands in the .config
file.
📸 Flashing using ESP-IDF
Under construction
Primitive support for IDF is incomplete (see implementation status).
Before you can compile and flash with ESP-IDF, you must install and enable the toolchain. You also need to disable the watchdog timer:
- Go to the root folder of the WARDuino repo
- Run
idf.py menuconfig
- Under Component config → ESP System Settings disable the following options:
- Interrupt watchdog
- Initialize Task Watchdog Timer on startup
- Save and quit the menu
To flash with the ESP-IDF toolchain perform the following steps starting from the project root folder. Make sure the ESP-IDF tools are enabled, or they will not work.
mkdir build
cd build
cmake .. -D BUILD_ESP=ON
make flash
Or simply run idf.py flash
.
🛠️ Arduino Toolchain Setup
In order to setup the Arduino toolchain for WARDuino, you need to first install the arduino-cli. You will also need python3
with the pyserial
package.
Second, create the config file:
arduino-cli config init
If you need additional boards, such as the esp32 boards, you can add them in the generated config file.
To find the location of your config file you can run:
arduino-cli config dump --verbose
Add the ESP32 board manager URL to the config file:
board_manager:
additional_urls:
- https://espressif.github.io/arduino-esp32/package_esp32_index.json
Then, update the index and install the ESP32 platform.
arduino-cli core update-index
arduino-cli core install esp32:esp32
WARNING
To use ESP32 boards with WARDuino you need at least version 2.0.2 of the board manager.
Thirdly, make sure you install the PubSubClient
and Adafruit NeoPixel
library, which are used by some primitives.
arduino-cli lib install "PubSubClient" # for MQTT
arduino-cli lib install "Adafruit NeoPixel"
If you haven't done so already, clone (or symlink) the WARDuino repository to ~/Arduino/libraries/WARDuino
to make it available to Arduino. (see #installation)