Please fix the following errors: Connection error

Just trying my first project after setting up my Aduino UNO (Cayenne Luminosity Example) but when I try to go to stage 2 I get the Error Message Please fix the following errors: Connection error. don’t know why I am getting this error. I am connected with USB Serial to my Laptop, I changed sketch to use Cayenneserial.h and followed all the instructions.see below:
/*
Cayenne Luminosity Example

This sketch sample file shows how to change the brightness on a LED
using Cayenne Dashboard.

The Cayenne Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.

Steps:

  1. In the Cayenne Dashboard add a new Custom Widget, and select Slider.
  2. Select a virtual pin number.
  3. Set min value to 0 and max value of 1.
  4. Set LED_VIRTUAL_PIN to the pin number you selected.
  5. Connect the LED’s legs to GND, and to a PWM pin (3, 5, 6, 9, 10, and 11 on most Arduino boards).
    Use a 1k resistor if possible.
    Schematic:
    [Ground] – [LED] – [1k-resistor] – [PWM Pin]
  6. Set LED_DIGITAL_PIN to the PWM pin number you selected.
  7. Set the token variable to match the Arduino token from the Dashboard.
  8. Compile and upload this sketch.
  9. Once the Arduino connects to the Dashboard you can use the slider to change LED brightness.
    */

#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space

// If you’re not using the Ethernet W5100 shield, change this to match your connection type. See Communications examples.
#include <CayenneSerial.h>

#define LED_VIRTUAL_PIN 1
#define LED_DIGITAL_PIN 6

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token = “j8gqsftp5v”;

void setup()
{
Serial.begin(9600);
Cayenne.begin(token);
}

CAYENNE_IN(LED_VIRTUAL_PIN)
{
// get value sent from dashboard
int currentValue = getValue.asInt(); // 0 to 1023
analogWrite(LED_DIGITAL_PIN, currentValue / 4); // must be from 0 to 255
}

void loop()
{
Cayenne.run();
}

Thanks in advance
Graham D Midgley

Hi @grahamdmidgley,

First of all, welcome to Cayenne!

When you first created a device in the dashboard, did you install they Cayenne library?

If not, you can follow the instructions here: http://www.cayenne-mydevices.com/docs/

Next you are going to want to follow the guidance in the Serial USB example. I have modified your sketch for that. Note that since you are using the serial port to bridge to the internet, you cannot also use it for debug:

/*
Cayenne Serial USB Example

This sketch connects to the Cayenne server using an Arduino Serial USB connection
and runs the main communication loop.

The Cayenne Library is required to run this sketch. If you have not already done so you can install it 
from the Arduino IDE Library Manager.

For Cayenne Dashboard widgets using digital or analog pins this sketch will automatically
send data on those pins to the Cayenne server. If the widgets use Virtual Pins, data
should be sent to those pins using virtualWrites. Examples for sending and receiving
Virtual Pin data are under the Basics folder.

This requires the use of the Serial USB connection so you cannot use the Serial device for
printing messages. If you need to print you can use SoftwareSerial and connect another device
to read messages via the SoftwareSerial pins.

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

Linux and OSX:
    ./cayenne-ser.sh (may need to run with sudo)
    
You can specify port, baud rate, and server endpoint like this:
    ./cayenne-ser.sh -c <serial port> -b <baud rate> -s <server address> -p <server port>

    For instance :
      ./cayenne-ser.sh -c /dev/ttyACM0 -b 9600 -s arduino.mydevices.com -p 8442

    Run cayenne-ser.sh -h for more information

    Be sure to select the right serial port (there may be multiple).

ATTENTION!
	Do not use Serial to display any output in this sketch. It will interfere with the Serial
	USB connection. When uploading sketches the Arduino IDE may complain with "programmer is
	not responding" or "Access is denied." You will need to terminate the connection script
	before uploading new sketches since it blocks access to the Serial port. Also make sure 
	the Serial Monitor is disabled in the IDE since that can prevent the Arduino from 
	connecting to the Windows/Linux/OSX machine. If you use Visual Micro for Visual Studio make
	sure Automatic Debugging is disabled. Otherwise the Serial Monitor can interfere with the
	Serial connection.
*/

#include <CayenneSerial.h>

#define LED_VIRTUAL_PIN 1
#define LED_DIGITAL_PIN 6

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "j8gqsftp5v";

void setup()
{
    Cayenne.begin(token);
}

CAYENNE_IN(LED_VIRTUAL_PIN)
{
    // get value sent from dashboard
    int currentValue = getValue.asInt(); // 0 to 1023
    analogWrite(LED_DIGITAL_PIN, currentValue / 4); // must be from 0 to 255
}

void loop()
{
    Cayenne.run();
}

Thanks for the swift reply. Yes i loaded the library files, I will try the modified sketch tomorrow, I will let you know how I get on.

Manny Thanks
Graham

Hi kreggly

Thanks for your help, I have now connected and everything seems to be working as expected.

I have just one question: Why do we select Virtual Pin 1 when the connection to the Arduino is to pin 6

Many thanks
Graham

Virtual pins are just that - virtual. They do not have to be mapped to physical pins, though it may make sense to do so to keep track of the physical pins in use. You can change it to virtual pin 6 and it will still work. You will also have to update your widget to use virtual pin 6.

Adam
Thanks for the information, I am new to Arduino/Cayenne just starting the learning curve for both.

Many thanks
Graham

This is the place to be then :slight_smile: Keep using the Cayenne community for help and if you create a project, let us know about it!

Hope to see you around,

-Benny