<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Toit on Medium]]></title>
        <description><![CDATA[Stories by Toit on Medium]]></description>
        <link>https://medium.com/@toit.io?source=rss-9d2e47e7cc50------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*A76mmdnPd-SM0M3WMdtDZg.png</url>
            <title>Stories by Toit on Medium</title>
            <link>https://medium.com/@toit.io?source=rss-9d2e47e7cc50------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 00:46:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@toit.io/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Writing a driver in Toit is easier than you may think]]></title>
            <link>https://medium.com/the-toit-take/writing-a-driver-in-toit-is-easier-than-you-may-think-f3dfee9cc747?source=rss-9d2e47e7cc50------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3dfee9cc747</guid>
            <category><![CDATA[hardware]]></category>
            <category><![CDATA[iot-platform]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[esp32]]></category>
            <category><![CDATA[firmware]]></category>
            <dc:creator><![CDATA[Toit]]></dc:creator>
            <pubDate>Fri, 01 Oct 2021 12:19:59 GMT</pubDate>
            <atom:updated>2021-10-04T09:59:00.891Z</atom:updated>
            <content:encoded><![CDATA[<h4>Just a few lines of Toit code are needed to reap the full benefits of the Toit ecosystem — without having to rely on firmware developers.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZpHgVZIYD4BQFmmRJRBScg.png" /></figure><p>Choosing <a href="http://toit.io/">Toit</a> for your IoT project means that your ESP32-based devices become as easy to program as smartphones: develop your app, deploy it to the devices of your choice, and then update and reinstall as often as needed, even on a shaky connection — all that while the other apps on the device keep running. Welcome to the 21st century, IoT!</p><p>With a new ecosystem also comes the possibility of making drivers the right way, that is with a high-level language easy to use and designed specifically for IoT. We already have drivers for some common peripherals in our <a href="http://libs.toit.io/">firmware</a> and <a href="http://pkg.toit.io/">package registry</a>, but Toit is still a young platform and it can be that we don’t yet have the driver for your particular sensor.</p><p>Luckily, writing a driver in Toit is easy.</p><p>To demonstrate this, we have chosen a really fun and versatile addition to any project, the <a href="https://www.sparkfun.com/products/15168">SparkFun Qwiic Joystick</a>, that we connect to the <a href="https://www.olimex.com/Products/IoT/ESP32/ESP32-DevKit-LiPo/open-source-hardware">ESP32</a> with a <a href="https://www.sparkfun.com/products/17261">Qwiic cable</a> and a simple I2C setup — here using pin 21 for SDA (blue) and pin 22 for SCL (yellow).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SYv9NItX8smnA1FtaCd-bg.png" /><figcaption>A SparkFun Qwiic Joystick connected with a Qwiic cable to an ESP32</figcaption></figure><h3>Out of the box peripheral interfaces</h3><p>A Toit driver takes advantage of high-level libraries that reduce boilerplate as much as possible. For typical peripheral interfaces, such as UART, I2C, or SPI, some pre-existing libraries already take care of the connection. In fact, we believe a good driver should be connection agnostic: the connection to the device is established outside the driver, and the driver just receives an object which allows it to talk to the device.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dmaterial%26wt%3Dnone%26l%3Dgroovy%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D0px%26ph%3D0px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dimport%252520gpio%25250Aimport%252520serial.protocols.i2c%25250A%25250Amain%25253A%25250A%252520%252520bus%252520%25253A%25253D%252520i2c.Bus%25250A%252520%252520%252520%252520--sda%25253Dgpio.Pin%25252021%25250A%252520%252520%252520%252520--scl%25253Dgpio.Pin%25252022%25250A&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dmaterial%26wt%3Dnone%26l%3Dgroovy%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D0px%26ph%3D0px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dimport%25252520gpio%2525250Aimport%25252520serial.protocols.i2c%2525250A%2525250Amain%2525253A%2525250A%25252520%25252520bus%25252520%2525253A%2525253D%25252520i2c.Bus%2525250A%25252520%25252520%25252520%25252520--sda%2525253Dgpio.Pin%2525252021%2525250A%25252520%25252520%25252520%25252520--scl%2525253Dgpio.Pin%2525252022%2525250A&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e165d8ca6a389703eae8f807d26b187/href">https://medium.com/media/3e165d8ca6a389703eae8f807d26b187/href</a></iframe><p>In our example, the joystick uses I2C on pins 21 and 22. With that information, we can start setting up the peripheral communication in the program `main.toit`.</p><p>The bus object created here in the main function needs the I2C address of the device which will be in the driver.</p><p>By looking at the documentation (or at an existing driver) we can see that the device is normally found at address 0x20.</p><p>We can now fully establish the connection by adding to `main.toit`:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dmaterial%26wt%3Dnone%26l%3Dgroovy%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D0px%26ph%3D0px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dimport%252520gpio%25250Aimport%252520serial.protocols.i2c%25250A%25250Amain%25253A%25250A%252520%252520bus%252520%25253A%25253D%252520i2c.Bus%25250A%252520%252520%252520%252520--sda%25253Dgpio.Pin%25252021%25250A%252520%252520%252520%252520--scl%25253Dgpio.Pin%25252022%25250A%252520%252520%25250A%252520%252520device%252520%25253A%25253D%252520bus.device%2525200x20&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dmaterial%26wt%3Dnone%26l%3Dgroovy%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D0px%26ph%3D0px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dimport%25252520gpio%2525250Aimport%25252520serial.protocols.i2c%2525250A%2525250Amain%2525253A%2525250A%25252520%25252520bus%25252520%2525253A%2525253D%25252520i2c.Bus%2525250A%25252520%25252520%25252520%25252520--sda%2525253Dgpio.Pin%2525252021%2525250A%25252520%25252520%25252520%25252520--scl%2525253Dgpio.Pin%2525252022%2525250A%25252520%25252520%2525250A%25252520%25252520device%25252520%2525253A%2525253D%25252520bus.device%252525200x20&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce4228264fcbecc7d987d7bc87d3b3fd/href">https://medium.com/media/ce4228264fcbecc7d987d7bc87d3b3fd/href</a></iframe><h3>Driver skeleton</h3><p>Following best practices, a driver does not care how the peripheral is connected but just takes the sensor `device` as argument.</p><p>A typical skeleton for a device that communicates over a serial connection looks as follows:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dbase16-dark%26wt%3Dnone%26l%3Dgroovy%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D0px%26ph%3D0px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dimport%252520serial%25250A%25250Aclass%252520SparkFunJoystick%25253A%25250A%252520%252520static%252520REG_DEFAULT_ADDRESS_%252520%25253A%25253A%25253D%2525200x00%25250A%252520%252520static%252520I2C_ADDRESS%252520%25253A%25253A%25253D%2525200x20%25250A%25250A%252520%252520registers_%25252Fserial.Registers%25250A%25250A%252520%252520constructor%252520device%25252Fserial.Device%25253A%25250A%252520%252520%252520%252520registers_%252520%25253D%252520device.registers%25250A%25250A%252520%252520on%25253A%25250A%25250A%252520%252520off%25253A%25250A&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dbase16-dark%26wt%3Dnone%26l%3Dgroovy%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D0px%26ph%3D0px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dimport%25252520serial%2525250A%2525250Aclass%25252520SparkFunJoystick%2525253A%2525250A%25252520%25252520static%25252520REG_DEFAULT_ADDRESS_%25252520%2525253A%2525253A%2525253D%252525200x00%2525250A%25252520%25252520static%25252520I2C_ADDRESS%25252520%2525253A%2525253A%2525253D%252525200x20%2525250A%2525250A%25252520%25252520registers_%2525252Fserial.Registers%2525250A%2525250A%25252520%25252520constructor%25252520device%2525252Fserial.Device%2525253A%2525250A%25252520%25252520%25252520%25252520registers_%25252520%2525253D%25252520device.registers%2525250A%2525250A%25252520%25252520on%2525253A%2525250A%2525250A%25252520%25252520off%2525253A%2525250A&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e531799ddd30b85e65d1fe78feaf452/href">https://medium.com/media/5e531799ddd30b85e65d1fe78feaf452/href</a></iframe><p>Here we find the I2C slave address (0x20) again. We have also added a first register address: REG_DEFAULT_ADDRESS_, set to 0x00.</p><p>All these addresses — and more — are described in the Joystick <a href="https://learn.sparkfun.com/tutorials/qwiic-joystick-hookup-guide?_ga=2.51633257.1779594476.1617796948-1318130652.1611579032">hookup guide</a> (or can be found in the datasheet, or another existing driver).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yBNxoZXtL9XuqJrylrvc2g.png" /><figcaption>A screenshot of the SparkFun Qwiic Joystick hookup guide</figcaption></figure><p>At this point we can implement our first method: `on`</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dbase16-dark%26wt%3Dnone%26l%3Dgroovy%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D0px%26ph%3D0px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3D%25252F%25252F%252520...%25250A%25250A%252520%252520on%25253A%25250A%252520%252520%252520%252520reg%252520%25253A%25253D%252520registers_.read_u8%252520REG_DEFAULT_ADDRESS_%25250A%252520%252520%252520%252520if%252520reg%252520%2521%25253D%252520I2C_ADDRESS%25253A%252520throw%252520%252522INVALID_CHIP%252522%25250A%252520%252520%25250A&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dbase16-dark%26wt%3Dnone%26l%3Dgroovy%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D0px%26ph%3D0px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3D%2525252F%2525252F%25252520...%2525250A%2525250A%25252520%25252520on%2525253A%2525250A%25252520%25252520%25252520%25252520reg%25252520%2525253A%2525253D%25252520registers_.read_u8%25252520REG_DEFAULT_ADDRESS_%2525250A%25252520%25252520%25252520%25252520if%25252520reg%25252520%252521%2525253D%25252520I2C_ADDRESS%2525253A%25252520throw%25252520%25252522INVALID_CHIP%25252522%2525250A%25252520%25252520%2525250A&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/934d0ce8457ad284b7641d8a20d40335/href">https://medium.com/media/934d0ce8457ad284b7641d8a20d40335/href</a></iframe><p>The `on` method of this driver is expected to be run at the beginning of the program, before the device is used. As can be seen from the few lines of code above, it just implements a simple check to ensure that we are talking to the correct device. According to the specification, register 0x00 (REG_DEFAULT_ADDRESS_) should return the default I2C slave address. If we don’t receive that value we assume that we are talking to a different peripheral and abort with an exception.</p><p>We can now update our ‘main’ function:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dmaterial%26wt%3Dnone%26l%3Dgroovy%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D0px%26ph%3D0px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dimport%252520gpio%25250Aimport%252520serial.protocols.i2c%25250Aimport%252520.spark_fun_joystick%25250A%25250Amain%25253A%25250A%252520%252520bus%252520%25253A%25253D%252520i2c.Bus%25250A%252520%252520%252520%252520--sda%25253Dgpio.Pin%25252021%25250A%252520%252520%252520%252520--scl%25253Dgpio.Pin%25252022%25250A%252520%252520%25250A%252520%252520device%252520%25253A%25253D%252520bus.device%252520SparkFunJoystick.I2C_ADDRESS%25250A%25250A%252520%252520joystick%252520%25253A%25253D%252520SparkFunJoystick%252520device%25250A%25250A%252520%252520joystick.on%25250A%252520%252520print%252520%252522SparkFunJoystick%252522%25250A%25250A&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dmaterial%26wt%3Dnone%26l%3Dgroovy%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D0px%26ph%3D0px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dimport%25252520gpio%2525250Aimport%25252520serial.protocols.i2c%2525250Aimport%25252520.spark_fun_joystick%2525250A%2525250Amain%2525253A%2525250A%25252520%25252520bus%25252520%2525253A%2525253D%25252520i2c.Bus%2525250A%25252520%25252520%25252520%25252520--sda%2525253Dgpio.Pin%2525252021%2525250A%25252520%25252520%25252520%25252520--scl%2525253Dgpio.Pin%2525252022%2525250A%25252520%25252520%2525250A%25252520%25252520device%25252520%2525253A%2525253D%25252520bus.device%25252520SparkFunJoystick.I2C_ADDRESS%2525250A%2525250A%25252520%25252520joystick%25252520%2525253A%2525253D%25252520SparkFunJoystick%25252520device%2525250A%2525250A%25252520%25252520joystick.on%2525250A%25252520%25252520print%25252520%25252522SparkFunJoystick%25252522%2525250A%2525250A&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/05e25357b8effb0969527522573fe0ad/href">https://medium.com/media/05e25357b8effb0969527522573fe0ad/href</a></iframe><p>To validate that the joystick and the ESP32 are communicating, save both the driver `driver.toit` and the `main.toit` in the same location on your local machine. Then run the main.toit code on your device (called `mydemokit` here) by typing the following command in the Toit CLI:</p><pre>$ toit device -d mydemokit run main.toit</pre><p>or by using the Toit extension in VSCode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cO1Gym6I4SV8CfGPqeiHEA.png" /><figcaption>Run the main.toit on any of your devices directly from Visual Studio Code with a Toit extension installed.</figcaption></figure><h3>Add additional methods</h3><p>We can now implement all features the joystick supports. Looking at the hookup guide we can see that we simply need to read the correct registers to read out the joystick&#39;s state.</p><p>As an example, let’s implement the method that shows whether a button is pressed:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dbase16-dark%26wt%3Dnone%26l%3Dgroovy%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D0px%26ph%3D0px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dclass%252520SparkFunJoystick%25253A%25250A%252520%252520static%252520REG_BUTTON_POSITION_%252520%25253A%25253A%25253D%2525200x07%25250A%25250A%25252F%25252F%252520...%25250A%25250A%252520%252520%25252F%252A%252A%25250A%252520%252520Whether%252520the%252520button%252520is%252520pressed.%25250A%252520%252520%252A%25252F%25250A%252520%252520pressed%252520-%25253E%252520bool%25253A%25250A%252520%252520%252520%252520return%252520%2528registers_.read_u%252520REG_BUTTON_POSITION_%2529%252520%25253D%25253D%2525200%25250A&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dbase16-dark%26wt%3Dnone%26l%3Dgroovy%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D0px%26ph%3D0px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dclass%25252520SparkFunJoystick%2525253A%2525250A%25252520%25252520static%25252520REG_BUTTON_POSITION_%25252520%2525253A%2525253A%2525253D%252525200x07%2525250A%2525250A%2525252F%2525252F%25252520...%2525250A%2525250A%25252520%25252520%2525252F%25252A%25252A%2525250A%25252520%25252520Whether%25252520the%25252520button%25252520is%25252520pressed.%2525250A%25252520%25252520%25252A%2525252F%2525250A%25252520%25252520pressed%25252520-%2525253E%25252520bool%2525253A%2525250A%25252520%25252520%25252520%25252520return%25252520%252528registers_.read_u%25252520REG_BUTTON_POSITION_%252529%25252520%2525253D%2525253D%252525200%2525250A&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c54ef6cd38ef4b1d9e0b0f4c6beb92c1/href">https://medium.com/media/c54ef6cd38ef4b1d9e0b0f4c6beb92c1/href</a></iframe><p>We read out the register value 0x07 (see datasheet), and compare it to 0. Note that once again, the meaning of the register value can be found through experimentation, the datasheet, or another driver.</p><p>Let’s use this new method in `main.toit`:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dmaterial%26wt%3Dnone%26l%3Dgroovy%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D0px%26ph%3D0px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dmain%25253A%25250A%25250A%25252F%25252F%252520...%25250A%25250A%252520%252520joystick.on%25250A%252520%252520while%252520true%25253A%25250A%252520%252520%252520%252520print%252520%252522pressed%25253A%252520%252524joystick.pressed%252522%25250A%252520%252520%252520%252520sleep%252520--ms%25253D250%25250A&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dmaterial%26wt%3Dnone%26l%3Dgroovy%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D0px%26ph%3D0px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dmain%2525253A%2525250A%2525250A%2525252F%2525252F%25252520...%2525250A%2525250A%25252520%25252520joystick.on%2525250A%25252520%25252520while%25252520true%2525253A%2525250A%25252520%25252520%25252520%25252520print%25252520%25252522pressed%2525253A%25252520%25252524joystick.pressed%25252522%2525250A%25252520%25252520%25252520%25252520sleep%25252520--ms%2525253D250%2525250A&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a3928e7f00da209b1da63d8ad1eed458/href">https://medium.com/media/a3928e7f00da209b1da63d8ad1eed458/href</a></iframe><p>And just like that, we have a working driver for the SparkFun Qwiic Joystick. A little bit more effort would be needed to support all of its features, but the rest is just a small matter of coding. Access the full joystick driver and the example app in our <a href="https://docs.toit.io/hardware/drivers/write/sparkfun_joystick">tutorial</a>.</p><p>If writing a driver still feels like a daunting endeavor for you, reach out to us on <a href="https://stackoverflow.com/questions/tagged/toit">Stack Overflow</a> or <a href="https://chat.toit.io/">Slack</a>. We will be more than happy to help you get started with <a href="https://toit.io/">Toit</a> on your hardware. Alternatively, if you have written a driver in Toit, feel free to <a href="https://docs.toit.io/language/package/pkgguide">share</a> it with the Toit community by adding it to our <a href="http://pkg.toit.io/">package registry</a>.</p><p>Happy hacking!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YE7qFQHH12waHII_uGx7og.gif" /><figcaption>Deploying a joystick app using the VS Code extension, and checking the logs react to moving and pressing the joystick in the Toit console.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3dfee9cc747" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-toit-take/writing-a-driver-in-toit-is-easier-than-you-may-think-f3dfee9cc747">Writing a driver in Toit is easier than you may think</a> was originally published in <a href="https://medium.com/the-toit-take">The Toit Take</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OTA updates that let you sleep at night]]></title>
            <link>https://medium.com/the-toit-take/otas-that-let-you-sleep-at-night-614fb8bedff7?source=rss-9d2e47e7cc50------2</link>
            <guid isPermaLink="false">https://medium.com/p/614fb8bedff7</guid>
            <category><![CDATA[application-development]]></category>
            <category><![CDATA[over-the-air-update]]></category>
            <category><![CDATA[cellular]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[firmware-update]]></category>
            <dc:creator><![CDATA[Toit]]></dc:creator>
            <pubDate>Tue, 07 Sep 2021 09:57:39 GMT</pubDate>
            <atom:updated>2021-09-07T10:38:27.050Z</atom:updated>
            <content:encoded><![CDATA[<p>As one of our customers said when talking about his previous embedded setup on cellular connectivity: “The OTA updates kept me awake at night”. Read here how Toit’s design handles flaky cellular connectivity to allow continuous firmware delivery and safe upload of all your data to the cloud.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A_0hVrbstvGgnsZeIboh1w.png" /></figure><p>There are many arguments in favor of using cellular connectivity for embedded systems: the “plug-and-play” setup, having an external operator taking responsibility for the network, and of course global coverage. Having said that, a cellular connection simply is not as stable as a cabled one, or even a connection over WiFi, especially in rural areas or inside solid structures. In some IoT setups, an interruption of the connectivity means that an OTA update has to be restarted from the beginning, with no more guarantees of success than the first time. Each attempt adds up both on developers’ workload, on devices’ power usage, and on the connectivity bill. A system that can handle flaky cellular connectivity is thus crucial for the success of cellular connectivity for embedded systems.</p><p><strong>Small, modular, and resumable OTA updates</strong></p><p>Contrarily to traditional IoT systems where all functionality is lumped together into one big piece of code, Toit lets you run separate applications and install and uninstall them runtime without affecting your underlying system. Toit applications have a size ranging from 40 to 100KB, and to update them, we only send patches to the previously installed version so an app update can be as small as 20KB. Similarly, firmware patches on Toit are between 100 and 500KB. With sizes that small, apps or firmware updates are happening in seconds, so the risk of running into a connectivity drop is very low.</p><p>And even if connectivity is lost during the update, Toit automatically resumes the transfer as soon as the cellular connection is back on. Also, the updates resume from the last data received — and not from the start. This is because we have built our connectivity’s logic as a stand-alone feature, easily configurable in a few clicks in the <a href="https://console.toit.io/">Toit console</a> and completely isolated from application code. Each time a device comes online, it automatically picks up configuration changes and software updates so that you only need to schedule these once. We take care of making sure that they will happen.</p><p><strong>No data loss over connectivity issues</strong></p><p>Cellular connectivity challenges also affect data transfer from the devices to the cloud in traditional IoT systems where programs are built as a single loop that first prepares data and then uploads it to the cloud. This tight coupling means that when the connectivity lags, the data collection is paused. If the connectivity is completely interrupted, the program fails and the data collected is lost.</p><p>Since Toit connectivity is isolated from application code, a Toit app focuses only on producing data and saving it on the device. The data is then uploaded to the cloud each time a device comes online. How often this happens is configured from our console for a whole fleet of devices at once: it can be set as time intervals, but it is also triggered if the storage on a device is close to being full.</p><p><strong>Ease of use and flexibility</strong></p><p>Toit offers a great choice in cellular technology and operator, so you can choose whatever works best for your project. We support Ublox Sara, Sequans Monarch, and Quectel cellular modules directly in our standard firmware, allowing <a href="https://docs.toit.io/hardware/connectivity/cellular">plug-and-play implementation</a> of cellular connectivity. We also let you work with the operator of your choice, so you can choose one based on each project’s coverage needs and pricing requirements.</p><p><strong>Summary</strong></p><p>Toit designed its OTA functionality with slow and flaky internet connections in mind.</p><ul><li>From the cloud to the device, we reduce the data amount required for an OTA update to a minimum. Plus OTA updates resume automatically if they fail halfway.</li><li>From the device to the cloud, the platform decouples connectivity and apps: configure the connectivity once in the console, and focus on developing apps while we take care of the rest.</li></ul><p>This makes a Toit device extremely robust, accessible, and power-efficient even on slow and flaky internet connections. With us, you literally can go to bed and expect that in the morning your whole fleet of devices is updated and all your data is nicely saved on our cloud, waiting for you to ingest it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=614fb8bedff7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-toit-take/otas-that-let-you-sleep-at-night-614fb8bedff7">OTA updates that let you sleep at night</a> was originally published in <a href="https://medium.com/the-toit-take">The Toit Take</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hack an Air Wick]]></title>
            <link>https://medium.com/the-toit-take/hack-an-air-wick-324844da5b35?source=rss-9d2e47e7cc50------2</link>
            <guid isPermaLink="false">https://medium.com/p/324844da5b35</guid>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[hacks]]></category>
            <category><![CDATA[home-automation]]></category>
            <category><![CDATA[makers]]></category>
            <category><![CDATA[hacking]]></category>
            <dc:creator><![CDATA[Toit]]></dc:creator>
            <pubDate>Thu, 26 Aug 2021 11:44:57 GMT</pubDate>
            <atom:updated>2021-08-26T12:06:09.390Z</atom:updated>
            <content:encoded><![CDATA[<p>Toit is designed to handle large amount of devices in production, but it is also a good fit for makers to build home automation solutions. Case in point, Florian — one of the Toit founders — has modified an <a href="https://www.airwick.us/products/automatic-sprays">Air Wick Auto Spray</a> to release a “burst of fresh fragrance” not automatically as it is initially set up to do, but on demand.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sqO_yXVf5-JCSWdYBARN-g.png" /></figure><p>The Air Wick Auto Spray has 3 settings: it can release fragrances every 9, 18, or 36 minutes, in which case a refill will last at most 60 days. Florian wasn’t happy with these restricted settings, so he connected the Air Wick electronic board to an ESP32 and used Toit as development platform. Note that in this tutorial, you will get to use the three development tools Toit offers: the console, the CLI, and the VS Code Toit extension.</p><p><strong>Hardware</strong></p><p>Here is what you need to get started:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*Oa2U-sFd1HHh8KXiorpE-A.jpeg" /><figcaption>An Air Wick in action.</figcaption></figure><ul><li>An <a href="https://www.airwick.us/products/automatic-sprays">Air Wick Auto Spray</a></li><li>An ESP32 (you can buy one <a href="https://www.banggood.com/Keyes-ESP32-WROOM-32-Module-Core-Board-ESP32-ESP-32-bluetooth-and-WIFI-MCU-p-1756083.html?cur_warehouse=CN&amp;rmmds=search">here</a>)</li><li>A <a href="https://www.banggood.com/Vention-USB-2_0-A-Male-to-Micro-B-Male-0_25-or-0_5-or-1-or-1_5-or-2-or-3m-Data-Cable-For-Samsung-Huawei-Android-Phone-p-1760506.html?cur_warehouse=CN&amp;ID=523602&amp;rmmds=search">micro B to USB</a> or <a href="https://www.sparkfun.com/products/15806">micro B to USB-C</a> cable for connecting the ESP32 to your computer</li><li><a href="https://www.banggood.com/60pcs-2W-180R-Metal-Film-Resistor-Resistance-1-180-ohm-Resistor-p-1610951.html?cur_warehouse=CN&amp;rmmds=search">180 Ohm resistors</a></li><li><a href="https://www.banggood.com/search/soldering-kit.html">Soldering tools</a></li><li>A <a href="https://auth.toit.io/signup">Toit account</a> (signing up is free)</li><li>Visual studio code with the <a href="https://blog.toit.io/toit-meets-visual-studio-code-f98bffdefece">Toit extension</a> to write your apps</li></ul><p><strong>Provisioning</strong></p><p>As soon as you have an account in Toit, connect the ESP32 to your computer and use the <a href="https://blog.toit.io/flash-your-esp32-from-the-browser-using-web-serial-5eccb1483b9c">Serial</a> feature available in the <a href="https://console.toit.io/serial">Toit console</a>. You should be up and running within a couple of minutes, and see your newly claimed device in the console. Select your device, and in the Code tab click on the “Run on Device” button. This will run a hello-world program on the ESP32. Note that from now on, all communication with your ESP32 happens over WiFi, using the credentials you specified during provisioning.</p><p><strong>Soldering</strong></p><p>The soldering to connect the Air Wick board and the ESP32 follows the schematic below, and you can see how to proceed in the <a href="https://www.youtube.com/watch?v=ZQgbDpcWhUI">video</a> at the end of this post.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/306/1*dn5lzetdoDoP6YxEDBXauA.png" /><figcaption>Schematic of the circuit.</figcaption></figure><p>When you are done with soldering, go to the console and run the hello-world program again to check that all is still in order after the soldering.</p><p><strong>Accessing the GPIO pins</strong></p><p>The ESP32 is now connected to the Air Wick through its GPIO pins. Florian measured that the motor needs to be run for 700 milliseconds in order to activate the spray. This is achieved by setting the connected pin to 1 for that amount of time. Replace the hello-world program with the following short code:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dmaterial%26wt%3Dnone%26l%3Dpython%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D0px%26ph%3D0px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dimport%252520gpio%25250A%25250Amain%25253A%25250A%252520%252520pin%252520%25253A%25253D%252520gpio.Pin%25252018%252520--output%25250A%252520%252520pin.set%2525201%25250A%252520%252520sleep%252520--ms%25253D700%25250A%252520%252520pin.set%2525200%25250A&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dmaterial%26wt%3Dnone%26l%3Dpython%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D0px%26ph%3D0px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dimport%25252520gpio%2525250A%2525250Amain%2525253A%2525250A%25252520%25252520pin%25252520%2525253A%2525253D%25252520gpio.Pin%2525252018%25252520--output%2525250A%25252520%25252520pin.set%252525201%2525250A%25252520%25252520sleep%25252520--ms%2525253D700%2525250A%25252520%25252520pin.set%252525200%2525250A&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/26343b798f586cdd0cb139e3af4a5426/href">https://medium.com/media/26343b798f586cdd0cb139e3af4a5426/href</a></iframe><p>Click on &quot;Run on device&quot; to test the program. The motor should turn. We haven&#39;t yet sprayed anything, but we are close. Reassemble the device, this time with our ESP32 inside as well. Run the program again, and you should now smell the result.</p><p>At this point, the Airwick is fully connected to the cloud. We are now moving on to making controlling the Airwick a bit easier.</p><p><strong>Getting started with PubSub</strong></p><p>Toit’s API includes <a href="https://docs.toit.io/apis/pubsub">PubSub</a>, a messaging service that lets apps (Toit apps but also mobile apps) communicate with each other. For this example, you will just use the <a href="https://docs.toit.io/getstarted/installation">CLI</a> to send the PubSub message that will trigger the spray.</p><p>First, use the <a href="https://console.toit.io/pubsub">console’s PubSub page</a> to create a subscription with the topic cloud:airwick, and the subscription name “Spray”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RH1z6qhbMCs-01wkjVGgng.png" /><figcaption>Create a PubSub subscription in the Toit console.</figcaption></figure><p>In a second step, start VSCode to create an app from the toit program you just tested. A Toit app consists of two files: a .toit file with a program like the one you used above to spray, and a .yaml file that specifies when the program should run (see <a href="https://github.com/floitsch/airwick">https://github.com/floitsch/airwick</a>).</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dmaterial%26wt%3Dnone%26l%3Dyaml%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D0px%26ph%3D0px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dname%25253A%252520Airwick%25250Aentrypoint%25253A%252520airwick.toit%25250A%25250Atriggers%25253A%25250A%252520%252520on_pubsub_topic%25253A%25250A%252520%252520%252520-%252520%252522cloud%25253Aairwick%252522&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dmaterial%26wt%3Dnone%26l%3Dyaml%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D0px%26ph%3D0px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dname%2525253A%25252520Airwick%2525250Aentrypoint%2525253A%25252520airwick.toit%2525250A%2525250Atriggers%2525253A%2525250A%25252520%25252520on_pubsub_topic%2525253A%2525250A%25252520%25252520%25252520-%25252520%25252522cloud%2525253Aairwick%25252522&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2b3d3af74d19e2430e1c40ad1c7d0bd/href">https://medium.com/media/a2b3d3af74d19e2430e1c40ad1c7d0bd/href</a></iframe><p>In this case, the airwick.yaml starts the airwick.toit file every time there is a message on the cloud:airwick topic.</p><p>The airwick.toit file contains the code listening to the specified topic.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dmaterial%26wt%3Dnone%26l%3Dpython%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D0px%26ph%3D0px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dimport%252520gpio%25250Aimport%252520pubsub%25250Atopic%252520%25253A%25253A%25253D%252520%252522cloud%25253Aairwick%252522%25250A%25250Amain%25253A%25250A%252520%252520print%252520%252522wakeup%252520-%252520checking%252520messages%252522%25250A%252520%252520already_sprayed%252520%25253A%25253D%252520false%25250A%252520%252520pubsub.subscribe%252520topic%252520--blocking%25253Dfalse%25253A%252520%25257C%252520msg%25252Fpubsub.Message%252520%25257C%25250A%252520%252520%252520%252520if%252520already_sprayed%25253A%252520continue.subscribe%25250A%252520%252520%252520%252520already_sprayed%252520%25253D%252520true%25250A%252520%252520%252520%252520pin%252520%25253A%25253D%252520gpio.Pin%25252018%252520--output%25250A%252520%252520%252520%252520pin.set%2525201%25250A%252520%252520%252520%252520sleep%252520--ms%25253D700%25250A%252520%252520%252520%252520pin.set%2525200%25250A%252520%252520%252520%252520print%252520%252522sprayed%252522%25250A%252520%252520print%252520%252522done%252520processing%252522&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dmaterial%26wt%3Dnone%26l%3Dpython%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D0px%26ph%3D0px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dimport%25252520gpio%2525250Aimport%25252520pubsub%2525250Atopic%25252520%2525253A%2525253A%2525253D%25252520%25252522cloud%2525253Aairwick%25252522%2525250A%2525250Amain%2525253A%2525250A%25252520%25252520print%25252520%25252522wakeup%25252520-%25252520checking%25252520messages%25252522%2525250A%25252520%25252520already_sprayed%25252520%2525253A%2525253D%25252520false%2525250A%25252520%25252520pubsub.subscribe%25252520topic%25252520--blocking%2525253Dfalse%2525253A%25252520%2525257C%25252520msg%2525252Fpubsub.Message%25252520%2525257C%2525250A%25252520%25252520%25252520%25252520if%25252520already_sprayed%2525253A%25252520continue.subscribe%2525250A%25252520%25252520%25252520%25252520already_sprayed%25252520%2525253D%25252520true%2525250A%25252520%25252520%25252520%25252520pin%25252520%2525253A%2525253D%25252520gpio.Pin%2525252018%25252520--output%2525250A%25252520%25252520%25252520%25252520pin.set%252525201%2525250A%25252520%25252520%25252520%25252520sleep%25252520--ms%2525253D700%2525250A%25252520%25252520%25252520%25252520pin.set%252525200%2525250A%25252520%25252520%25252520%25252520print%25252520%25252522sprayed%25252522%2525250A%25252520%25252520print%25252520%25252522done%25252520processing%25252522&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/358a3d08c8d52fe778d012d88b450816/href">https://medium.com/media/358a3d08c8d52fe778d012d88b450816/href</a></iframe><p>Voilà! You have written a Toit app that subscribes to PubSub. Deploy it onto the device using the commands in the left-hand side menu in VS Code (available once the Toit extension is installed in VS Code).</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*ywPPaSIabJ12rIO1" /><figcaption>Deploying an app from VS Code.</figcaption></figure><p>Then check in the console that the Airwick app is in the list of installed apps.</p><p>Now test your app by sending a message from the Toit CLI to the PubSub topic:</p><pre>toit pubsub write cloud:airwick “from the CLI” -- Spray</pre><p>The “from the CLI” and “Spray” are the sender and the content of the PubSub message. The actual values of these arguments don’t really matter as long as a message is sent.</p><p><strong>Configuring your device</strong></p><p>As it is, the device is set to be online all the time to check for messages on the topic airwick. This can drain the battery too fast, which is why Florian decided to configure his ESP32 to come online only once every 10 minutes. This is easily done from the Toit console by going to the Configuration page of your Toit device, and changing the Max offline to 10 minutes (or more). That way, you will get a spray within 10 minutes of having sent a PubSub message.</p><p>Being able to configure how often — or rather how seldom — a device should be online is one of the key strengths of the Toit platform, enabling devices to run on batteries for years. Instead of having to include connectivity as one task of many in a single program, it is handled by the platform, and configured with just a click in the console. The apps you develop focus only on the task at hand: measuring data, triggering an actuator, or listening to a PubSub subscription.</p><p>Want to keep going? Why not create a motion-detecting device that triggers the Airwick when a person is detected? Or add an air quality sensor that sends a PubSub message when the CO2<strong> </strong>measurements reach a defined threshold? Check the list of drivers that are included in our <a href="https://pkg.toit.io/">package registry</a>, or reach out to our team directly at <a href="/service/mailto:contact@toit.io">contact@toit.io</a> to get help writing your own.</p><p>Happy hacking!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FZQgbDpcWhUI%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DZQgbDpcWhUI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FZQgbDpcWhUI%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/334cb1644c72e51ee49122fe9e2bd2b0/href">https://medium.com/media/334cb1644c72e51ee49122fe9e2bd2b0/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=324844da5b35" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-toit-take/hack-an-air-wick-324844da5b35">Hack an Air Wick</a> was originally published in <a href="https://medium.com/the-toit-take">The Toit Take</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Toit package registry and more]]></title>
            <link>https://medium.com/the-toit-take/toit-package-registry-and-more-620b71b9aa8e?source=rss-9d2e47e7cc50------2</link>
            <guid isPermaLink="false">https://medium.com/p/620b71b9aa8e</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[esp32]]></category>
            <category><![CDATA[iot-development]]></category>
            <category><![CDATA[toit]]></category>
            <category><![CDATA[iot]]></category>
            <dc:creator><![CDATA[Toit]]></dc:creator>
            <pubDate>Wed, 18 Aug 2021 12:27:48 GMT</pubDate>
            <atom:updated>2021-08-18T12:27:48.126Z</atom:updated>
            <content:encoded><![CDATA[<p>The latest release of the Toit platform introduces a lot of new features intended to make your life as an IoT developer easier. We would like to advertise the Toit way of developing IoT applications, so read ahead and learn what the team has built for you lately.</p><h3>Growing ecosystem</h3><p>Going from the idea of an IoT product, to developing a prototype, and eventually converting that into IoT devices in production should be fast and easy for all IoT developers. To facilitate this process, we see the need for a thriving community that contributes to everyone’s success by sharing packages to a public registry.</p><p>Therefore, we are happy to announce that we launched the public <a href="https://pkg.toit.io/">Toit package registry</a> where you can explore existing packages, search for a given package, and even publish your own package via the <a href="https://pkg.toit.io/publish">publish</a> page. The packages currently available can be used to control IoT sensors connected to an ESP32 microcontroller.</p><p>The Toit CLI provides <a href="https://docs.toit.io/language/package/pkgguide">commands</a> for the package manager, such as listing all packages, searching, installing selected packages, and updating installed packages.</p><p>When you have found the package you want to use, install it with the CLI with the command (here using the Bosch BME280 environmental sensor as an example)</p><pre>$ toit pkg install bme280</pre><p>and it’s now ready to be imported and used in your Toit apps.</p><p>Once you have written your own driver for a sensor in the Toit language, you can learn how to create your own package in the <a href="https://docs.toit.io/language/package">Toit documentation</a>.</p><p>Our goal is to make the Toit package registry the perfect place for collaboration and communication — from the Toit engineers to the Toit community, and from one Toit user to another.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cujc7qVr3eRtCc6_2H5uBA.png" /></figure><h3>Developer ergonomics</h3><p>Our mission is to let IoT developers be as productive as possible with best-in-class developer tools:</p><ul><li>The<strong> Toit CLI</strong> allows you to work from the command line.</li><li>The<strong> Toit Console</strong> offers a web-based user interface from where you can access your devices, get an overview of the device status and health, change device configurations etc.</li><li>The<strong> Visual Studio Code extension</strong> for the Toit language, publicly available from the VSCode marketplace, concentrates all the <a href="https://blog.toit.io/toit-meets-visual-studio-code-f98bffdefece">tools</a> needed for a smooth development experience: get syntax highlighting and code completion when writing in Toit, and the Toit language server finds compile-time errors. You also have access to your IoT devices in the VSCode extension: after you provisioned your hardware via a serial connection, you can get an overview of your active devices, and <a href="https://docs.toit.io/platform/deploy/runordeploy">run and deploy</a> your Toit programs on the devices directly from VSCode.</li></ul><h3>User-friendly Toit console</h3><p>In the <a href="https://console.toit.io/">Toit Console</a>, we have worked to get a more user-centric look and feel, together with better guidance for new users. The new features in the Toit Console include the<a href="https://console.toit.io/profile"> Profile view</a> accessible from the upper right corner. There, you can change various user settings, subscribe to the Toit newsletter, or change your password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ECgL7k0YdRoZXfXZDU3Jbg.png" /></figure><p>The <a href="https://blog.toit.io/flash-your-esp32-from-the-browser-using-web-serial-5eccb1483b9c">Serial</a> page in the Toit console allows you to communicate with a serial-connected device through your browser. We have enhanced the Web Serial function with additional help and guidance in cases where provisioning doesn’t go as expected.</p><h3>Cellular connectivity</h3><p>We have added a <a href="https://docs.toit.io/hardware/connectivity/cellular">description of</a> how to set up the cellular configuration settings when using Toit. If you plan to use cellular connectivity to get your microcontrollers connected to the Internet, try it out and <a href="http://chat.toit.io/">contact us</a> if you encounter any problems.</p><h3>Google and Github sign-in option</h3><p>Last but not least, if you haven’t noticed already, we have integrated Google sign-in and Github sign-in for seamless sign-up and sign-in to the Toit cloud using your existing Google or Github account.</p><p>The Toit CLI and the VSCode extension for Toit also use the new sign-in process, making the sign-in experience consistent and easy across all Toit properties.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=620b71b9aa8e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-toit-take/toit-package-registry-and-more-620b71b9aa8e">Toit package registry and more</a> was originally published in <a href="https://medium.com/the-toit-take">The Toit Take</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Toit meets Visual Studio Code]]></title>
            <link>https://medium.com/the-toit-take/toit-meets-visual-studio-code-f98bffdefece?source=rss-9d2e47e7cc50------2</link>
            <guid isPermaLink="false">https://medium.com/p/f98bffdefece</guid>
            <category><![CDATA[vscode]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[vscode-extension]]></category>
            <dc:creator><![CDATA[Toit]]></dc:creator>
            <pubDate>Thu, 05 Aug 2021 09:33:14 GMT</pubDate>
            <atom:updated>2021-08-05T09:33:14.497Z</atom:updated>
            <content:encoded><![CDATA[<p>At Toit, we are happy to announce that the Toit VSCode extension is available at the <a href="https://marketplace.visualstudio.com/items?itemName=toit.toit">VSCode Marketplace</a> and the <a href="https://open-vsx.org/extension/toit/toit">Open VSX Marketplace</a>. This marks another milestone in our efforts to provide the best platform for IoT development.</p><p>The Toit programming language pushes the frontier for programming languages for the ESP32 microcontroller with features such as garbage collection, fault isolation, and easy updates — which most developers are accustomed to in the context of normal software development. However, a great development experience takes more than a good programming language, it also requires tooling that makes development smooth.</p><p>This is where the Toit VSCode extension comes into the picture. The extension allows VSCode to provide a rich view of your programs as well as easy access to common functionality like running and deploying apps. In the following, we give a quick tour of the extension.</p><h3>LSP and syntax highlighting</h3><p>The Toit extension enhances the experience of writing Toit programs by adding syntax highlighting and autocompletion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Caz3tNPuf5MKv8dJ.png" /></figure><h3>Device view</h3><p>The device view provides an overview of devices in an organization, and the apps running on each device. Each device either has a pulse or a flatline icon to indicate whether the device is active or not. The device view can be accessed from the activity bar by clicking the Toit logo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/0*tldRTTHk12Q-Lcam.png" /><figcaption>The device view.</figcaption></figure><p>With Toit, apps are installed over the air, and they run in isolation, so developers can feel safe trying out programs on a device during development. To emphasize this, we have added run and deploy buttons to the device view, so it is easy to try out programs on a device, wherever that device may be located.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FmjD6irW1nfya7ui.gif" /><figcaption>Run and deploy apps from the device view.</figcaption></figure><p>If you have just gotten started with Toit but your ESP32s are still in the mail, then we still want you to be able to run Toit apps. From the device view, you can add a simulator that you can use like any other device. When you are done with a simulator, you can remove it from the device view with the stop button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OD56o5yhjgPYUkcA.gif" /><figcaption>Start and stop simulators from the device view.</figcaption></figure><h3>Serial view</h3><p>Even though normal communication with Toit devices happens over the internet, you still need to connect the device to a serial port to provision it. During development, it is useful to monitor the serial output of a device to get an idea about what is happening on the device.</p><p>In the serial view, you have an overview of the active serial ports. If a serial port is connected to a known device, then the device name will show. If you click the device name, then the device is revealed in the device view, so you can run and deploy apps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0C3vFtrhsHSeKA6U.gif" /><figcaption>Jump from the serial view to the device view.</figcaption></figure><p>Each port has a provision button and a monitor button. Both buttons open a terminal for that serial port and run the appropriate command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*esTuRpahVSrOhQzX.gif" /><figcaption>Monitor output from a Toit device serially connected.</figcaption></figure><h3>Organization status</h3><p>The status bar displays the current organization and the SDK. The organization can be changed by clicking on the organization which also updates the device view.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MnbY5bJfrfJeMXzj.gif" /><figcaption>Change organization from the status bar.</figcaption></figure><h3>Try it out</h3><p>We think this is a great addition to the Toit development experience, but we have only just gotten started. For instance, we want to support the package manager. If you have any feedback, questions, or suggestions for the extension, please feel free to reach out to us on <a href="http://toit-chat.slack.com/">slack</a> or <a href="https://github.com/toitware/ide-tools">github</a> (where you also find the source).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hfrGP35Md3_zQt0s_xuJOg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f98bffdefece" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-toit-take/toit-meets-visual-studio-code-f98bffdefece">Toit meets Visual Studio Code</a> was originally published in <a href="https://medium.com/the-toit-take">The Toit Take</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Toit lets Trifork build an IoT product with no need for firmware developers]]></title>
            <link>https://medium.com/the-toit-take/toit-lets-trifork-build-an-iot-product-with-no-need-for-firmware-developers-f1e032eb06a2?source=rss-9d2e47e7cc50------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1e032eb06a2</guid>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[vertical-farming]]></category>
            <category><![CDATA[firmware]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[aeroponics]]></category>
            <dc:creator><![CDATA[Toit]]></dc:creator>
            <pubDate>Fri, 25 Jun 2021 09:01:50 GMT</pubDate>
            <atom:updated>2021-07-07T16:02:39.774Z</atom:updated>
            <content:encoded><![CDATA[<h3>Toit lets Trifork build an IoT product without firmware developers</h3><blockquote>“Toit cancels the boundaries between firmware and software development teams by moving the full stack towards the software developer. The software development team can own the roadmap for their firmware because the Toit high-level language gives full access to the low-level hardware parts of the system, thereby changing the logic of how to develop for embedded devices.” — Stephan Henningsen and Søren Toft, Trifork developers</blockquote><p><a href="https://trifork.com/">Trifork</a> is a supplier of high-quality custom-built applications and end-to-end software solutions, also known for organizing the <a href="https://trifork.com/conferences/">GOTO conferences</a> “for developers by developers”. With sustainability at the heart of their operations, they decided to build their most recent IoT product — an aeroponics farm called the Foodbox — on the <a href="https://toit.io/">Toit platform</a>.</p><p><strong>Aeroponics indoors farming</strong></p><p>Vertical farming in a soil-free controlled environment delivers organic and fresh green produce right where it will be consumed. In aeroponics farming, plants’ roots dangle exposed in the air and get their nutrients from a solution sprayed as mist, needing only 5% of the water used in a traditional farming system. Additionally, plants grow faster in an aeroponics environment because their roots have access to more oxygen than when they are submerged in water.</p><p>However, aeroponics farms are tricky to maintain successfully. Exposed roots are very sensitive to changes in humidity, so it is crucial to monitor and control the environmental conditions of the growing chamber carefully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OzXkpg-gshAGQK691511dw.png" /><figcaption><em>Plantlet and exposed roots of a mature plant when grown in the Foodbox.</em></figcaption></figure><p><strong>Sensitive systems benefit from Toit’s agility</strong></p><p>Trifork identified that Toit’s software platform would allow for a modular and iterative approach to building, configuring, and maintaining their vertical farm.</p><p>The Foodbox consists of a cabinet with several shelves where plants are grown in individual containers. The growing chamber is built out of wood — a recyclable or even upcyclable design, as the Foodbox can become a regular cupboard at the end of its life cycle.</p><p>On the lowest shelf of the cupboard, a system made of a reservoir, a pump, a pressure accumulator, and spraying nozzles is used to spray the nutrient solution into mist. A spraying event is activated by a solenoid that opens the valve between the pressure accumulator and each compartment of the Foodbox. Artificial lighting in the Foodbox ensures optimal growth, while temperature and relative humidity are continuously monitored.</p><p>Sensors and actuators included in this system are programmed by three different Toit apps installed on an <a href="https://en.wikipedia.org/wiki/ESP32">ESP32 microcontroller</a>. One app measures the temperature and relative humidity in the Foodbox. A second app controls the lighting. A third app is used to schedule the magnetic valve openings. Finally, Trifork has built a smartphone app that can be used to configure each of the Toit apps using <a href="https://docs.toit.io/apis/pubsub/">Toit PubSub API</a>. With this smartphone app, individual users get full control over the configuration of each Toit app independently.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bQgCuoMRxvH23rr-1eELIA.png" /><figcaption><em>The ESP32 microcontroller where the Toit apps are deployed.</em></figcaption></figure><p>Having functionality deployed as self-contained apps is a key strength of using Toit to build modular systems. With Toit, running tasks in parallel and configuring them independently become possible. This makes it easier and more flexible to maintain the farm than when all functionality has to be included in a single firmware image that contains the whole monolithic application.</p><p>The Foodbox’s final design also includes an alarm system triggered by a water reservoir running low and extra sensors that monitor the quality of the nutrient solution. Toit makes it possible to add functionality progressively as new apps can be deployed without impacting the other apps or the underlying system.</p><blockquote>“The turnaround of deploying an app and updating is so fast that it is easy to debug and improve code.”</blockquote><p>In addition, working with Toit means that the software developers can handle both software and firmware — without having to rely on C or C++ experts.</p><blockquote>“SPI and I2C connection protocols are already included in Toit’s API standard library. Additional sensors or actuators support can easily be ported to Toit. And once it is done, it is really nice not to have to dig in C code any longer.”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZM9Uj2RBd-PDfTKZb8B1TA.jpeg" /><figcaption><em>Trifork’s full design can be implemented incrementally.</em></figcaption></figure><p>Trifork is an active<strong> </strong>Toit implementation partner. Contact <a href="http://toit.io/">us</a> or <a href="http://trifork.com/">them</a> so we can help you get your IoT solutions up and running.</p><p><em>Authors: Céline Materna, Content and UX Research Manager at Toit.</em></p><p><em>All quotes from this blog post are from Stephan Henningsen and Søren Toft, Trifork developers.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u9WyXHwra1TuuKBsIUTo7A.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1e032eb06a2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-toit-take/toit-lets-trifork-build-an-iot-product-with-no-need-for-firmware-developers-f1e032eb06a2">Toit lets Trifork build an IoT product with no need for firmware developers</a> was originally published in <a href="https://medium.com/the-toit-take">The Toit Take</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Toit v1.1]]></title>
            <link>https://medium.com/the-toit-take/toit-v1-1-a4ef0e57b00b?source=rss-9d2e47e7cc50------2</link>
            <guid isPermaLink="false">https://medium.com/p/a4ef0e57b00b</guid>
            <category><![CDATA[firmware-update]]></category>
            <category><![CDATA[http-client]]></category>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[release-notes]]></category>
            <category><![CDATA[tls]]></category>
            <dc:creator><![CDATA[Toit]]></dc:creator>
            <pubDate>Wed, 23 Jun 2021 14:43:49 GMT</pubDate>
            <atom:updated>2021-06-25T05:59:05.353Z</atom:updated>
            <content:encoded><![CDATA[<p>At Toit, we’re always working on bringing the best of IoT to your devices. In this post, we share some of the great improvements we have made to the latest release of Toit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FpETJSo8auDOoXu6aRHRGA.png" /></figure><h3>Application watchdog</h3><p>The Toit firmware goes to great lengths to ensure your devices always recover, both from foreseeable and unforeseeable events. One class of security guards we apply is watchdogs. Up until now, we had used a watchdog to detect if the device is not making computational progress and if so abort and restart the system. This is a great way to save devices from bad behavior, but without much context, it remained very hard to understand what actually went wrong.</p><p>To help our users understand what went wrong, we’ve added a new level of watchdogs: Application Watchdogs. The first application watchdog we have added will interrupt the execution of Toit applications if they don’t yield processing time for more than 10 seconds.</p><p>To better illustrate this functionality, run the following code on a device:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g2EQovC_F2JwafHnNkYqfg.png" /></figure><p>The output makes it very trivial to identify, and fix, unexpected behavior.</p><h3>TLS support</h3><p>While devices have always been using a strongly encrypted TLS connection towards the Toit cloud, we’ve now exposed the TLS library. This allows applications to securely connect to other devices on the local network and remote servers. Check out the <a href="https://libs.toit.io/tls/library-summary">TLS</a> and <a href="https://libs.toit.io/http/library-summary">HTTP</a> libraries for more information.</p><h3>Performance</h3><p>We love VMs, and we love making them fast! This time, we’ve spent time optimizing the hashed collections like sets and maps. The results are quite impressive, and we are going to follow up with a dedicated blog post to explain exactly what we did — stay tuned!</p><h3>SDK libraries</h3><p>Some of our SDK libraries are so essential to Toit developers that we decided to promote them by giving them shorter names! But don’t worry — while we moved the libraries, we’ve also added references for backward compatibility, so you can continue to import them the old way:</p><ul><li>serial.protocols.spi renamed to spi</li><li>serial.protocols.i2c renamed to i2c</li><li>serial.protocols.i2s renamed to i2s</li><li>serial.ports.uart renamed to uart</li></ul><p>Many <a href="https://libs.toit.io/">libraries</a> now also have much more documentation and examples.</p><h3>Toit language improvements</h3><p>The language also received a lot of improvements for this release, the biggest of them listed here.</p><ul><li>We have added syntax for slices to the Toit language. A slice, written as object[from..to], generally returns a view of a smaller part of the original object. It is implemented for Lists, ByteArrays, and strings.<br>For example ”This is a nice string”[10..14] returns the slice ”nice”.<br>Note that slices are not copies, but just views into the original object.</li><li>Better completion:<br>The LSP server now hides private identifiers of other packages, and it provides completion for $ references in toitdocs.</li><li>Package manager improvements.</li><li>Better error message for bad imports. The error message now gives an indication of what exactly went wrong.</li><li>We also improved the error messages when a method wasn’t correctly called. There is now a distinction between providing the wrong arguments (wrong number, or wrong named arguments), and between the method not even being there.</li><li>We added Duration.abs, yielding the absolute value of a duration.</li><li>We removed the log function. Use print instead.</li><li>We now allow optional parameters in abstract methods. At the same time, we improved the error checking for ambiguous method declarations (where two methods in a class would accept the same arguments).</li><li>The IDE completion now hides private identifiers of other packages.</li><li>The IDE now emits deprecation warnings.<br>If a Toitdoc has a paragraph that starts with “Deprecated”, then the analyzer warns users when they call this method.</li><li>The prefix for imports has changed from the first segment to the last segment.<br>For example, import foo.bar.gee used to have foo as prefix, and now has gee as prefix.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ecAXUqhcYQMn7c4HXnJiJQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a4ef0e57b00b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-toit-take/toit-v1-1-a4ef0e57b00b">Toit v1.1</a> was originally published in <a href="https://medium.com/the-toit-take">The Toit Take</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Become an IoT developer in 15 minutes]]></title>
            <link>https://medium.com/the-toit-take/become-an-iot-developer-in-15-minutes-7df26ad5c0e1?source=rss-9d2e47e7cc50------2</link>
            <guid isPermaLink="false">https://medium.com/p/7df26ad5c0e1</guid>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[makers]]></category>
            <category><![CDATA[toit]]></category>
            <category><![CDATA[esp32]]></category>
            <category><![CDATA[microcontrollers]]></category>
            <dc:creator><![CDATA[Toit]]></dc:creator>
            <pubDate>Fri, 23 Apr 2021 09:19:34 GMT</pubDate>
            <atom:updated>2021-05-05T14:00:10.567Z</atom:updated>
            <content:encoded><![CDATA[<h4>From signing up to a working IoT product in 15 minutes? It is possible with Toit.</h4><p>Implementing IoT solutions in 2021 is not exactly pleasant: Developing in C is complex and error-prone and updates on remote devices are too risky. We knew that to make IoT development efficient, we had to start from scratch with a new language, a robust and efficient virtual machine, and great developer tools. Everything Toit is optimized for iterative app deployment and seamless firmware updates.</p><p>To demonstrate how easy it is to become an IoT developer with Toit, we will show you how to set up a minimalist weather station measuring temperature, humidity, and atmospheric pressure — all within minutes of signing up.</p><h3>Hardware</h3><p>Here is what you need to get started:</p><ul><li>An ESP32 (you can buy one <a href="https://www.digikey.com/en/products/detail/espressif-systems/ESP32-DEVKITC-32D/9356990">here</a>, <a href="https://www.olimex.com/Products/IoT/ESP32/ESP32-DevKit-LiPo/open-source-hardware">here</a>, or <a href="https://www.banggood.com/Keyes-ESP32-WROOM-32-Module-Core-Board-ESP32-ESP-32-bluetooth-and-WIFI-MCU-p-1756083.html?cur_warehouse=CN&amp;rmmds=search">here</a>)</li><li>A <a href="https://www.sparkfun.com/products/13676">BME280</a> sensor</li><li>A <a href="https://www.sparkfun.com/products/13244">micro B to USB</a> or <a href="https://www.sparkfun.com/products/15806">micro B to USB-C</a> cable for connecting the ESP32 to your computer</li><li>A <a href="https://www.sparkfun.com/products/14988">Qwiic</a> cable with female jumpers to connect the sensor to the microcontroller (no soldering needed)</li></ul><p>You just have to connect the sensor to the ESP32 and the ESP32 to your computer, which is done in a few steps. Then you are good to go.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y97RuhTgBy2FpOYvltOCsA.jpeg" /><figcaption>We connect the Qwiic cable to the BME280 breakout board with the red wire to 3.3V (3V3) and the black wire to Ground. We chose to connect the blue (I2C SDA) to the GPIO pin 21 and the yellow (I2C SCL) to pin 22.</figcaption></figure><h3>Sign up</h3><p>Sign up on the Toit website and follow the <a href="https://docs.toit.io/quick_start_guide/">instructions</a> that will guide you through Toit installation and the provisioning of your device with the latest Toit firmware. You should be up and running within 5 minutes, and see your newly claimed device in the console. We called ours the-15-minutes-weather-station, so if you pick something else note it down.</p><h3>Validate your setup</h3><p>The <a href="https://cdn.sparkfun.com/assets/learn_tutorials/4/1/9/BST-BME280_DS001-10.pdf">BME280</a> sensor is connected to the microcontroller via <a href="https://docs.toit.io/getstarted/gpio/">GPIO</a> pins, and the sensor supports both <a href="https://libs.toit.io/serial/protocols/i2c/library-summary">I2C</a> and <a href="https://libs.toit.io/serial/protocols/spi/library-summary">SPI</a> connection modes. All the code needed to handle the pins and the connection is already included in the Toit libraries, so that the only thing left to do is to write apps.</p><p>Once your ESP32 is available in the list of devices, select it and go to the Code tab to paste the following program, written to check that the sensor is correctly connected:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dmaterial%26wt%3Dnone%26l%3Dgroovy%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D0px%26ph%3D0px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dimport%252520gpio%25250Aimport%252520serial.protocols.i2c%252520as%252520i2c%25250A%25250Amain%25253A%25250A%252520%252520bus%252520%25253A%25253D%252520i2c.Bus%25250A%252520%252520%252520%252520--sda%25253Dgpio.Pin%25252021%25250A%252520%252520%252520%252520--scl%25253Dgpio.Pin%25252022%25250A%25250A&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dmaterial%26wt%3Dnone%26l%3Dgroovy%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D0px%26ph%3D0px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dimport%25252520gpio%2525250Aimport%25252520serial.protocols.i2c%25252520as%25252520i2c%2525250A%2525250Amain%2525253A%2525250A%25252520%25252520bus%25252520%2525253A%2525253D%25252520i2c.Bus%2525250A%25252520%25252520%25252520%25252520--sda%2525253Dgpio.Pin%2525252021%2525250A%25252520%25252520%25252520%25252520--scl%2525253Dgpio.Pin%2525252022%2525250A%2525250A&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/de62793612edb9da65dbb715888d93bc/href">https://medium.com/media/de62793612edb9da65dbb715888d93bc/href</a></iframe><p>Click on “Run on device” and check the output. If the sensor is not connected correctly, you will get an error message that will help you fix your hardware (did you use the right pins?).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7-bxmpHl5qUrlMVBy-r0uA.png" /><figcaption>No error message? Your sensor is properly connected and you are good to go!</figcaption></figure><p>As you can see from the program above, a simple Toit program follows a structured skeleton:</p><ul><li>First, you import the libraries you need;</li><li>Then you define your variables, functions, and classes.</li></ul><h3>Write your first program</h3><p>With the bus correctly configured, make the following additions to the program:</p><ul><li>In the import section, tell the program where to find the <a href="https://libs.toit.io/drivers/bme280/class-Bme280">driver</a> for the sensor with import drivers.bme280</li><li>In the main function, use the BME280 I2C address found in the sensor <a href="https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bme280-ds002.pdf">datasheet</a> to configure the device via device := bus.device 0x77 and construct the driver using bme := drivers.Bme280 device</li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dmaterial%26wt%3Dnone%26l%3Dcrystal%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D0px%26ph%3D0px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3D%252520%252520bme.on%25250A%252520%252520print%252520%252522Temperature%25253A%252520%252524bme.read_temperature%252520C%252522%25250A%252520%252520print%252520%252522Humidity%25253A%252520%252524bme.read_humidity%252520%252525%252522%25250A%252520%252520print%252520%252522Pressure%25253A%252520%252524bme.read_pressure%252520Pa%252522%25250A%252520%252520bme.off&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dmaterial%26wt%3Dnone%26l%3Dcrystal%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D0px%26ph%3D0px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3D%25252520%25252520bme.on%2525250A%25252520%25252520print%25252520%25252522Temperature%2525253A%25252520%25252524bme.read_temperature%25252520C%25252522%2525250A%25252520%25252520print%25252520%25252522Humidity%2525253A%25252520%25252524bme.read_humidity%25252520%25252525%25252522%2525250A%25252520%25252520print%25252520%25252522Pressure%2525253A%25252520%25252524bme.read_pressure%25252520Pa%25252522%2525250A%25252520%25252520bme.off&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/694423f7ae0bc834f8c3daa967d37816/href">https://medium.com/media/694423f7ae0bc834f8c3daa967d37816/href</a></iframe><p>Finally, in main use the API provided by the driver to read out the data and print it to the logs.</p><p>Voilà! You have written your first Toit program. You can see the full program on <a href="https://github.com/toitware/posts/tree/main/bme280/weather-station">GitHub</a>. Paste it in the Code tab of your device, and see the data in the output window below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WZyFhHhnSkIC5L0DqvFKdw.png" /><figcaption>In the Code tab of the device, you can read the output of a program right below the code that generated it. This makes it easy to try things out and improve your Toit programs.</figcaption></figure><h3>Deploy your first app</h3><p>Now that your program is working, you can create your first app.</p><p>An app consists of two files: a .toit file with a program like you just wrote, and a .yaml file that designates the program and <a href="https://docs.toit.io/deploy/appspec/">specifies</a> when it should run. Copy all the code from the Code tab above and put it into a file called weather-station.toit. Then create a weather-station.yaml file next to it with this content:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcarbon.now.sh%2Fembed%3Fbg%3Drgba%2528171%252C%2B184%252C%2B195%252C%2B1%2529%26t%3Dbase16-light%26wt%3Dnone%26l%3Dyaml%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D0px%26ph%3D0px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%2525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dname%25253A%252520THP%25250A%25250Aentrypoint%25253A%252520weather-station.toit%25250Atriggers%25253A%25250A%252520%252520%252520%252520on_install%25253A%252520true%25250A%252520%252520%252520%252520on_interval%25253A%25252030s&amp;display_name=Carbon&amp;url=https%3A%2F%2Fcarbon.now.sh%2F%3Fbg%3Drgba%252528171%25252C%2B184%25252C%2B195%25252C%2B1%252529%26t%3Dbase16-light%26wt%3Dnone%26l%3Dyaml%26ds%3Dtrue%26dsyoff%3D20px%26dsblur%3D68px%26wc%3Dtrue%26wa%3Dtrue%26pv%3D0px%26ph%3D0px%26ln%3Dfalse%26fl%3D1%26fm%3DHack%26fs%3D14px%26lh%3D133%252525%26si%3Dfalse%26es%3D2x%26wm%3Dfalse%26code%3Dname%2525253A%25252520THP%2525250A%2525250Aentrypoint%2525253A%25252520weather-station.toit%2525250Atriggers%2525253A%2525250A%25252520%25252520%25252520%25252520on_install%2525253A%25252520true%2525250A%25252520%25252520%25252520%25252520on_interval%2525253A%2525252030s&amp;image=https%3A%2F%2Fcarbon.now.sh%2Fstatic%2Fbrand%2Fbanner.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;scroll=auto&amp;schema=carbon" width="1024" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0a6c8689aa76358956716da9dcc69f0/href">https://medium.com/media/c0a6c8689aa76358956716da9dcc69f0/href</a></iframe><p>In this example, the app is called THP—short for temperature, humidity, and pressure. It will run the weather-station.toit program at installation and every 30 seconds after that.</p><p>Remember that the weather-station.toit file should be in the same folder as the corresponding .yaml file. Now to deploy your app on your aptly named device (you did note the name down, right?), run the following command using the Toit command line interface from that folder:</p><pre>toit device -d the-15-minutes-weather-station deploy weather-station.yaml</pre><p>Your app is now installed on your device and you can see it in the list of apps in the console. It runs and produces log entries every 30 seconds, just like you told it to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b734BVFofcXu2YdEEYmKhw.gif" /></figure><p>And here you are, an IoT developer in Toit with a minimalist weather station, all within 15 minutes of getting started.</p><p>Want to keep going? Find the full code for this app and more on <a href="https://github.com/toitware/posts">GitHub</a>. Check the list of <a href="https://libs.toit.io/drivers/library-summary">drivers</a> that are included in the Toit libraries or find one in our <a href="https://gist.github.com/floitsch/a18ded12517e5acddbc72253b42304b5">registry</a>, and get hacking! Sign up on <a href="https://toit.io/">toit.io</a> or reach out to our team directly at <a href="/service/mailto:contact@toit.io">contact@toit.io</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7df26ad5c0e1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-toit-take/become-an-iot-developer-in-15-minutes-7df26ad5c0e1">Become an IoT developer in 15 minutes</a> was originally published in <a href="https://medium.com/the-toit-take">The Toit Take</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Did you think true multitasking was impossible on a $2 microcontroller? Watch how Toit does it!]]></title>
            <link>https://medium.com/the-toit-take/did-you-think-true-multitasking-was-impossible-on-a-2-microcontroller-watch-how-toit-does-it-3c0f01de538e?source=rss-9d2e47e7cc50------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c0f01de538e</guid>
            <category><![CDATA[iot-platform]]></category>
            <category><![CDATA[firmware-update]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[esp32-programming]]></category>
            <category><![CDATA[iot-development]]></category>
            <dc:creator><![CDATA[Toit]]></dc:creator>
            <pubDate>Thu, 25 Mar 2021 12:43:13 GMT</pubDate>
            <atom:updated>2021-07-19T17:59:03.756Z</atom:updated>
            <content:encoded><![CDATA[<p>Why does IoT development in 2021 feel like software development in the seventies? <a href="http://toit.io/">Toit</a> has tackled the issue and makes deploying apps on your IoT devices as easy as it is on a smartphone.</p><p>Watch Nils, our Lead Product Manager, deploy, update and uninstall three apps - including one that would crash any other IoT device - on an ESP32 microcontroller.</p><p><a href="http://toit.io/">Sign up</a> on our website to try it yourself.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FNh83qoq0nKU%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DNh83qoq0nKU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FNh83qoq0nKU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/56ca21dfac103fa635ab2923bcd1477c/href">https://medium.com/media/56ca21dfac103fa635ab2923bcd1477c/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a8LOmmtw4xJ-hKp5lRDBdg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c0f01de538e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-toit-take/did-you-think-true-multitasking-was-impossible-on-a-2-microcontroller-watch-how-toit-does-it-3c0f01de538e">Did you think true multitasking was impossible on a $2 microcontroller? Watch how Toit does it!</a> was originally published in <a href="https://medium.com/the-toit-take">The Toit Take</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>