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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
1. Set up your development environment
Install Jaguar
Start by downloading and installing the
jagbinary 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
jagorjag.exebinary somewhere on yourPATH. The same applies when you extract thejagbinary from the macOSjag.dmgfile.Next step is to let
jagdownload and configure the Toit SDK and the associated tools for flashing the Jaguar application onto your ESP32:If the
jagsetup 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 > Extensionfrom the menu and search for Toit. Click theInstallbutton 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.toitand 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 versionfrom 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 monitorfrom 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 Terminalmenu. In the new terminal, start watching thehello.toitfile for changes using:You can switch back and forth between the
jag monitorandjag watchoutputs, but the most interesting information will be in the monitor output:If you change the
hello.toitfile 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 pkglike this:You must install the
mqttpackage in the folder yourhello.toitfile 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.toitwith 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.toitthejag watchfunctionality (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