Toit is a language for embedded development on microcontrollers, targeting the ESP32. Like CircuitPython or TinyGo, language libraries provide access to microcontroller peripherals and developers are insulated from the OS. Toit goes significantly further, by addressing device onboarding/lifecycle, monitoring and fleet management, with both a command line and web console interfaces.

Programming on the device is in the Toit language, including drivers for devices connected over SPI or I2C, as described in the Write a driver guide. Drivers are provided in the SDK for several devices, as documented in the drivers page.

To get a sense of the driver development process, I thought it would be sensible to re-implement a fragment of the BME280 driver, which is provided in the SDK (without source). A complete application sample is included in the tutorial, outlining code and deployment. The circuit was easily wired on a protoboard as shown below:


Searching on GitHub for “BME280” yields over 1,700 repositories, but I reviewed the first result Adafruit_BME280_Library. Simply re-coding parts of the .cpp and .h files associated with temperature, yielded the code.

Several observations:

  • naive re-coding is simple, readable and fast, thanks to Toit’s clean syntax
  • working in Visual Studio Code, with the Toit plugin, is pleasant … the syntax highlighting and static analysis really helps learning
  • the “toy driver” worked first time, what happens when you crib good code
  • results match the production driver to at least 1 decimal place (note, t_fine_adjust is ignored)
  • there is no test code as would be necessary in any production driver … the purpose here was only to get a sense of the process
  • classes (such as Sensor_Sampling ) and named constructors was modeled after Attaching Values to Java Enum The getter .x was a terse alternative to the Smalltalk <instance> value idiom. Comments welcome.

Overall, the experience was very good for an environment that has only been generally available for several months.