Wifi TinyShield Tutorial (with Cayenne IoT)

by TinyCircuits Staff February 01, 2017

Wifi TinyShield Tutorial (with Cayenne IoT)

Our newest version of the Wifi TinyShield provides users with the ability to easily connect their TinyDuino stack to the internet! This tutorial covers using the Wifi TinyShield as an IoT (Internet of Things) device via Cayenne. Using a Proto Board TinyShield, a TinyLily LED 1206, and a TinyDuino with a USB TinyShield we can wirelessly blink and fade some LEDs. 


Installing Arduino Libraries

To program the TinyDuino, you'll need to download a few libraries. Open the Arduino IDE and go to: Sketch - Include Library - Manage Libraries.

The Library Manager window will appear, allowing you to search for and download/update your Arduino libraries. In the search bar, type in Cayenne. Select 'Cayenne by myDevices' and install the most recent version.

Next, type Wifi101 into the search bar. 'Wifi101 by Arduino' should appear. Install the most recent version. 


Getting Started with Cayenne

Cayenne is an online site that simplifies IoT (Internet of Things) projects using a simple drag and drop interface.

To use Cayenne, we'll start by visiting their homepage and signing up for a free account. After you've made your profile, the interface will guide you through connecting to your processor board. In our case, we'll be connecting to the TinyDuino.

Select Arduino as your Hardware. The next page will prompt you to configure and connect your device. 

After your device is connected, the next page that comes up will generate your token and prompt you for your Arduino board type. (You'll use the token in your code). Select Arduino Pro Mini 3.3v 8MHz.

Cayenne will wait until it finds your device on the network before proceeding further.


Programming the TinyDuino

Once you have the libraries installed, go to File - Examples - Cayenne - Internet Connections - Wifi101 Shield, and click on it.

The example code will open and we'll modify a few lines. Change the 'token', 'SSID' and 'password' values to match your Cayenne-generated token, your WiFi network's name (this is also known as an SSID), and WiFi password. The last step required is to add an additional line of code that determines what pins to use with the wifi chip. In the void setup block, add the line:

WiFi.setPins(8, 2, A3, -1); //Tells the processor to use these pins to talk to the WiFi chip

That's all you need! Compile and upload the code to your TinyDuino via the USB TinyShield and allow it to run. (Once you've uploaded the code, you no longer need the USB TinyShield attached and can go wireless with a lithium battery.) 


Connecting Hardware 

Next, we'll be soldering on our TinyLily LEDs (1206). I've selected a red one and a green one. The green LED can be soldered with its positive (+) terminal on pin D4 of the Proto Board TinyShield and the negative (-) terminal soldered onto pin A2. The red LED can be soldered with the positive (+) terminal on pin D5 and the negative (-) terminal onto pin A1. (You can also choose your own pin assignments). 

Note: The I/O pins that are not available are: D0, D1, D2, D8, D11, D12, D13, A3, A4 and A5. These are already dedicated to Serial, Wifi, SPI and I2C. 


Adding Control via Cayenne

Now that we have both Cayenne and our TinyDuino configured, Cayenne should recognize the device on the network and prompt us to the next screen where we can begin to add some control! Here, we are working with Arduino Pro (we can rename this later).

Select Add New on the drop down then click Device/Widget. 

The screen will then populate with available options for various types of sensors, actuators, etc. To control our LEDs, we will use the Actuators - Light Switch and Luminosity for dimming control. 

Adjust the settings on the right to match your selected I/O and choose an image to match your desired function. For obvious reasons, I have chosen the lightbulb icon. 

NOTE: You will not need to update your sketch file! The file that Cayenne generates contains no additional code to put on your processor. Scroll down to 'Add Actuator' and click on it. This will add your light switch control.

As you can see, we have added our light control (which I have assigned to our Green LED), and separately, I have added dimming control for the Red LED, which is connected to a PWM pin. We can now control our two LEDs wirelessly via Cayenne! Click the light button to turn it on or off, or move the slider to dim the red LED. 


Control and Scheduling Events

Now that you're familiar with Cayenne and our new Wifi TinyShield, you can begin implementing more complicated sensors, actuators, and even schedule events to make your creation fully automated. Their calendar allows you to set dates and times for which the I/O signals will automatically be output to the device. You can also check out their great mobile app, pictured below:

The excellent video tutorials produced by Cayenne will walk you the rest of the way through renaming your device, creating a Project, and so forth. Keep in mind, so long as you don't delete your device from your Cayenne account or reprogram your TinyDuino, you can power the device down and Cayenne will resume control over it once it is turned on again. If you do happen to reprogram your stack, just go through Cayennes' device setup again - you will be assigned a new access token to put into your sketch.


What's Next?

Show us what you've built with the new Wifi TinyShield! We love seeing what you build with TinyCircuits tech. You can mention us on Twitter or post on our Facebook page, and if we like what we see, we may feature it in a future blog post or email. Please send an email to info@tinycircuits.com if you need us to update or modify any part of this tutorial. Happy building!



TinyCircuits Staff
TinyCircuits Staff

Author



Also in Learn

New Tiny Arcade - Assembly Instructions (With Rev5 Boards)
New Tiny Arcade - Assembly Instructions (With Rev5 Boards)

by TinyCircuits Staff July 27, 2017

We are super excited to release our latest version of the beloved Tiny Arcade kit! This assembly tutorial features our...

View full article →

New Tiny Arcade - Assembly Instructions
New Tiny Arcade - Assembly Instructions

by TinyCircuits Staff July 25, 2017

We are super excited to release our latest version of the beloved Tiny Arcade kit! We've updated the design for...

View full article →

TinySaber Reprogramming - A How-To Guide
TinySaber Reprogramming - A How-To Guide

by TinyCircuits Staff July 18, 2017

This tutorial will walk you through how to reprogram your TinySaber to include custom POV text, special colors, lighting effects,...

View full article →