Getting started with Toit on your ESP32 #244
kasperl
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
1. Set up your development environment
Install Jaguar
Start by downloading and installing the
jag
binary for your host platform:On macOS, you can also use Homebrew to mange the installation of
jag
:If you download the archive, you should unpack it and put the embedded
jag
orjag.exe
binary somewhere on yourPATH
. The same applies when you extract thejag
binary from the macOSjag.dmg
file.Next step is to let
jag
download and configure the Toit SDK and the associated tools for flashing the Jaguar application onto your ESP32:If the
jag
setup completes successfully, you have the tools you need to work with Toit code installed.Install Visual Studio Code
Visual Studio Code is the preferred editing experience for Toit. If you don't already have VS Code installed, go ahead and download and install it. Then start it:
You're now ready to install the Toit extension. Choose
View > Extension
from the menu and search for Toit. Click theInstall
button next to the Toit extension in the list. You should now have the extension installed:Create a new folder and open it in Visual Studio Code. In the new folder, create a new file called
hello.toit
and put some basic Toit code in it:The Toit extension provides syntax highlighting, static analysis, and autocompletions, so you now have a great editing environment for tinkering with Toit code.
2. Run code on your ESP32
Start a terminal in Visual Studio Code and make sure you can run
jag version
from within there. If that works, you're ready to connect your ESP32 to your host machine using a serial link and flash the initial firmware onto it throughjag flash
:Your host machine must be on the same network as your ESP32. Jaguar uses UDP broadcast from the ESP32 to support scanning for devices and you can find yours by running:
and select your device from the list:
Now run
jag monitor
from your terminal. This will give you access to the serial logs from the device:We're almost there. The final step is to start a new terminal using the
Terminal > New Terminal
menu. In the new terminal, start watching thehello.toit
file for changes using:You can switch back and forth between the
jag monitor
andjag watch
outputs, but the most interesting information will be in the monitor output:If you change the
hello.toit
file and save the changes, Jaguar will reload the app on your ESP32 and you will see the new output within a few seconds:3. Using packages
Toit comes with a package manager that allows you to easily pull down additional functionality from an online repository of published packages. To install your first package, you use
jag pkg
like this:You must install the
mqtt
package in the folder yourhello.toit
file resides in, because this is where the Toit compiler will look for packages.With the installed package in place, you can replace the content of
hello.toit
with a more involved example that uses MQTT to publish and subscribe. You can download the example from here or you can go to the code and simply copy and paste it in VS Code.Once you save your edits and thus the new example in
hello.toit
thejag watch
functionality (assuming you left it running from step 2) will kick in and you will start seeing output like:Drivers are one of the most common kind of packages, so take a look at the list of available packages and start contributing your own.
Beta Was this translation helpful? Give feedback.
All reactions