Introduction: Add Cellular Connectivity to Your Toit Project

Adding cellular internet connectivity to your IoT project definitely brings the whole project up a notch. Not being tethered to a Wifi opens up a world of new possibilities. Cheap flat-rate data plans tailor-made for IoT is becoming more and more common and getting up and running is often just a matter of plug-and-play. The Gpy from Pycom is a very nice piece of hardware that contains both an ESP32 and a cellular modem. Normally, the board is programmed using Micropython, but in this project we'll re-flash the board with Jaguar from Toit. This allows us to develop in a fraction of the time, use live-reloading of our Toit code, and reduce the amount of memory needed. The execution speed is also significantly faster with Toit compared to Micropython.

Supplies

A Gpy board from Pycom.

A SIM card with a data plan. You can add a 1NCE SIM card to your cart when buying the Gpy board from Pycom.

An FTDI programmer, 3.3V. Not that it must be able to use 3.3V logic. If you have one for your old Arduino board that uses 5V, do NOT use it for the Gpy.

A breadboard and jumper wires

Step 1: Insert SIM Card and Connect the Hardware

Start by inserting your SIM card into the dedicated slot on the Gpy. Connect the cellular antenna to the board.

NOTE: Do not power up the board without first connecting the cellular antenna. If you power up the board without antenna you run the risk of damaging the Gpy.

Connect your FTDI Tx and Rx to the Rx and Tx of the Gpy board, respectively. See attached image for Gpy GPIO pinout.

Finally, connect 5V and GND from your FTDI adapter to the corresponding pins on the Gpy.

Step 2: Download and Install Jaguar From Toit

Download the Jaguar installer from Toit. You'll find it on Github.

Install Jaguar and verify it is properly installed by running

$jag version

Now install Jaguar by running

$jag setup

Step 3: Flash Jaguar Onto Your Gpy

In order to be able to flash the Gpy, you need to put the board in boot mode. This is simple: Just connect a jumper cable from GPIO 0 (see pinout in previous step) to GND. Subsequently press and release the reset button on the GPY. Disconnect GPIO 0 from GND. Your board is now in boot mode and is ready to be flashed.

Now run

$jag flash

This command will prompt you for your Wifi credentials and flash Jaguar onto the GPY.

Restart the board by pressing the reset button. If you now run

$jag scan

you should see your Gpy. It has been given a name automatically.

NOTE: You must provide a 2G Wifi, since the ESP32 cannot connect to a 5G Wifi.

Step 4: Run Your First Example

The driver for the cellular modem comes with an example that connects to the cellular network and reads google.com. It can be found in your project-home-folder, and the file name is monarch.toit:

project-home-folder/.packages/github.com/toitware/sequans-cellular/0.1.1/examples/monarch.toit

Run

$jag watch project-home-folder/.packages/github.com/toitware/sequans-cellular/0.1.1/examples/monarch.toit

This will run the example and allow live reloading of the Toit code. Whenever you save the code, the new code will automatically be sent over Wifi and executed on the Gpy board.

Monitor your output by running

$jag monitor

in a separate terminal window. See image above for typical serial output while connecting.

Once connected, google.com will be downloaded via the cellular connection, to verify you have a working connection.