Cayenne IoT + ESP8266: driving a mini kit Pan-Tilt FPV SG90 in WiFi with a smartphone or tablet

In this new tutorial on Cayenne IoT, we will learn how to control an articulated Pan-Tilt PTZ SG90 system in WiFi. In the previous tutorial, we saw how to do with the Blynk library and application. Cayenne IoT is fairly similar. It is necessary to pass through the servers of myDevices.com which can cause a small delay of latency (quality of Internet connection, server load …).

What do you need ?

Unlike Blynk, Cayenne IoT does not offer (yet?) Local server. It is therefore necessary to have a user account. You can create one directly from mydevices.com or from the iOS or Android app.

If you have purchased a Pan-Tilt PTZ SG90 kit, follow the previous tutorial for installation.

Equipment used

I suggest you here to pilot the Pan / Tilt mini kit in WiFi. You can use any ESP8266.

esp8266 Wemos D1 mini Wemos D1 Mini
chargeur raspbery pi 3 5v 3000ma 5/3A micro-usb power supply
mini kit fpv pan tilt sg90 Mini Kit FPV Pan Tilt with SG90 servos
jumper dupont Jumper Dupont
breadboard Breadboard

Circuit

The circuit is exactly the same as the Blynk version.

mini kit pan tilt servo wemos d1 mini wifi cayenne iot mydevices

Preparing the Device

First, we need to add a Device. Unlike Blynk, Cayenne needs to be connected to the object at any time during setup.

Cayenne proposes to create a Device of type Raspberry or Arduino. This is not a problem, the ESP8266 is very well managed even if it is not in the list.

cayenne mydevices add device raspberry arduino

You can retrieve by email a small code example for Arduino

 cayenne mydevices add arduino device

Select Arduino Uno then WiFi Shield. A Token is generated. From now on, Cayenne is waiting for the Arduino (or the ESP8266 in this case) to connect to the mydevices.com servers before continuing. It is a little frustrating, but it is the current mode of operation.

cayenne mydevices esp8266 wemos d1 mini nodemcu

Prepare the Arduino IDE

Launch the Arduino IDE and open the library manager. In the search field, search the keyword Cayenne. Install the Cayenne library by myDevices. Also install the servo library.

ide arduino install cayenne mydevices library

Arduino Code

Paste the Device Token into the following code and change the connection settings (ssid, password) to your WiFi network. Upload the code and open the serial monitor to make sure everything is going well.


Configuring Axis Commands on the Cayenne App

Go back to the Cayenne application. As soon as the ESP8266 has authenticated itself to Cayenne servers, the application will automatically switch to the next screen.

 cayenne iot mydevices authenticate

Click ADD at the center of the screen to add the axis commands. Unlike Blynk, there is no joystick widget. It will be necessary to settle for 2 sliders (which is not really a problem, it is not so simple to control the axes precisely with the joystick: -?). Add a Motor Device.

cayenne mydevices add motor

Then Servo Motor

cayenne mydevices servo motor

Configure it like this

  • Name: Pan or Tilt
  • I/O: Virtual
  • Pin: V0 for Pan, V1 for Tilt (for example)
  • Widget: slider
  • Activate min / max and set 0..180 (degrees)
  • Finish by Save

Do the same for the 2nd axis.

cayenne mydevices pan virtual v0

Here’s what we get

cayenne mydevices sliders pan tilt

Since Cayenne only accepts configuring Devices when connected to the Arduino / ESP8266, the axis control is immediately functional.

If you lose connection to your device, this is the type of message that will appear at the top of the screen

cayenne mydevices device offline

With a small video, it’s simpler 😉

On the video, you will notice a slight delay between the movement of a slider and the execution of the command by the ESP8266. Cayenne is a recent project which still presents defects of youth but it will be forgiven quite easily because it is proposed totally free (until when?).

Subscribe to the weekly newsletter

No spam and no other use will be made of your email. You can unsubscribe anytime.