Arduino and IoT via Cayenne IoT Platform and USB Serial Connection

The Internet of Things is kinda the buzz now. But is it still possible to do IoT without the need for an Arduino-compatible wifi/ethernet shield or the ESP8266 wifi module at the least? Fret no more, because it is!

You will need the following:

  1. Arduino board (I will use an Arduino Uno compatible board)
  2. Three (3) LEDs
  3. Three (2) 220-ohm resistors (which we will use to control via the Internet)
  4. A breadboard
  5. Some jumper wires
  6. and lastly, a computer with Internet connection. This will be the gateway of the Arduino and the devices connected to it, to the Internet.

The schematics for this activity is as follows:
Arduino UNO and LED IOT

The first thing to do is (well of course, register for a FREE account at Cayenne Sign Up. Log on to your account after having set it up successfully:
Cayenne USB Serial - 01 Logon

After successfully logging on to your Cayenne account, we need to add a new device:
Cayenne USB Serial - 02 Add New Device

After clicking Device/Widget under Add New combo box, you will be shown options to choose from. Select Arduino under Microcontrollers:
Cayenne USB Serial - 03 Choose Arduino

Next, you will be shown a screen that will guide you on how to set your Arduino board Arduino IDE, and the libraries. We already covered this in our previous tutorial. Click the Next button afterwards:
Cayenne USB Serial - 04 Arduino Setup

Clicking the Next button will prompt you to the next step which will as you what type of board you are going to use. But in this activity, that will be irrelevant. We will only focus on the AUTH TOKEN FOR THIS DEVICE. The value here will be used in the sketch you will be uploading to your board. Take note of the Auth Token value. Here, it is 5lre2s21xd. But you need to replace this with the actual token you will be receiving:Cayenne USB Serial - 05 Auth token

At this stage, Cayenne IoT platform in your account will be waiting for the board to be connected to it. Follow the next steps carefully.

Open you Arduino IDE. Be sure that all Cayenne libraries are installed correctly. Will be opening up a sketch which we will be using for this project.

Go to File > Examples > Cayenne > Internet Connections > Serial USB Connection:
Cayenne USB Serial - 06 Arduino IDE USB Serial Conn

A sketch will be shown. We will use this sketch for your activity. Now, you need to change the value of the token[] array variable and assign it with the Auth Token found in your set up:
Cayenne USB Serial - 07 Change Auth Token in Code.png

After changing it, we are now ready to upload the sketch to your Arduino board (Arduino Uno in my case). After successfully uploading the sketch, we need one more thing to do. In the comment section of the sketch, you will see:

In order for this to work you must run the connection script on the machine the Arduino is connected to.
The scripts are located under the extras\scripts folder in the main library folder. This redirects the traffic
from the Arduino to the Cayenne server.

Steps:
1. Set the token variable to match the Arduino token from the Dashboard.
2. Compile and upload this sketch.
3. Launch the connection script as described below for Windows or Linux/OSX.

Windows:
1. Open the Windows command line (cmd.exe) 
2. Navigate to the scripts folder by typing "cd [path]", e.g.  "cd C:\Users\[YourUserName]\Documents\Arduino\libraries\Cayenne\extras\scripts" 
3. Run the script by typing "cayenne-ser.bat -c COM4" (where COM4 is port with your Arduino) and hitting Enter

I am using Windows, so I will focus on the steps needed for Windows.

Open the Command Line as an Administrator:
Cayenne USB Serial - 08 Command Line

Go to the Cayenne scripts folder. The highlighted text below (in red) will be different and will be your actual username in your local machine:
Cayenne USB Serial - 09 Go to Scripts folder

Now, type the command to run the script. My Arduino is connected to COM3 on may laptop, so yours might be connected to a different one.
Cayenne USB Serial - 10 Run script command

After pressing Enter, you will see something like this. This script will actually establish connection between your Arduino board and Cayenne:
Cayenne USB Serial - 11 Script running

Now, go back to your Cayenne account. The page has changed, and at the left side portion of the page is the list of configured device (Arduino board), including the new one. The icon is currently NOT grayed out, meaning it is online now:
Cayenne USB Serial - 12 Arduino board added now

At this point we will now be adding the three (3) LEDs to the board.

Go to Add New… then click Device/Wdiget:
Cayenne USB Serial - 02 Add New Device

Scroll down, and find Actuators. Select Light:
Light - Actuators

Select Light Switch:
Light - Switch

Now, lets configure the first LED. This is connected to Digital 13 on Arduino Uno. For the device, select the newly added board (Arduino in our case):
Light - LED Setting

Click Add Actuator. There’s no need for Step 1, since we already have the sketch. You will now see the new widget being added:
Light - added

Follow the same steps for the rest of the LEDs (Blue and Green). Blue LED is connected to Digital Pin 12 of the Arduino Uno, Green LED to Digital Pin 11 of the same board. The final widgets will be similar to the one below:
Light - Widget complete

We are now done. You may now click the buttons to turn the LEDs on or off. Image below shows the actual set up of my components:

img_4228

I hope this helps those beginners like me. This article will also serve as a documentation for myself. I might need this in the future if I will be trying to re-create the project.

Thank you very much.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

5 comments

  1. Thanks for ‘Arduino and IoT via Cayenne IoT Platform and USB Serial Connection ‘, excellent article. Problem with this is that it needs a PC connected and using the cayenne-ser.bat to be run every time.
    On the Cayenne Community has been a lot of discussion connecting Arduino to Cayenne through ESP8266-01 and in December code was provided to connect to a Arduino Mega but this does not seem to work for all for users of UNO and maybe NANO. One issue relates to use of Serial1.
    Of course people could use a ESP12E but this only has 8 bit analogs whereas a UNO can use 10bit analogs.
    Could you consider doing one of your articles to connect a UNO through a ESP-01 to Cayenne, I’m sure it would be appreciated by all.
    Cheers

    Like

  2. Eldon thanks for the prompt response and the link.

    Are you aware of the changes required to get Arduino working with Cayenne ? The following link is with examples http://community.mydevices.com/t/converting-cayenne-arduino-library-sketches-to-cayenne-mqtt-arduino/5759

    For the last couple of days Cayenne (i.e. mydevices.com) have been having a lot of issues with Arduino which has not helped the name of their free service but I’m sure they will overcome. Tested & well documented examples like you have done make things all so clear.

    I’m looking forward to your future posts.

    Like

    • I agree. But I am hopeful that their engineers are working hard to fix these issues. I can’t even continue to what I was doing last time because of some issues.

      Yes, I am aware of the issues, and some developers have been following these up as well.

      I will still post some more tutorials regarding IOT with Cayenne myDevices.

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s