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:
In the Cayenne Dashboard add a new Custom Widget, and select Slider.
Select a virtual pin number.
Set min value to 0 and max value of 1.
Set LED_VIRTUAL_PIN to the pin number you selected.
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]
Set LED_DIGITAL_PIN to the PWM pin number you selected.
Set the token variable to match the Arduino token from the Dashboard.
Compile and upload this sketch.
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>
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
}
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();
}
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.