Hello!
Im running an Uno via USB Serial connection on Win10. I have managed to figure out all that Serial.begin and CAYENNE_PRINT stuff that interferes with communication after a sketch is uploaded. I am trying to just add a relay actuator. I can manage to upload the sketch, reestablish communication to the dashboard, and now see the intended widget on the dash.
When i toggle the switch, NOTHING! The icon shows the state change, and no result on the physical relay. I have it pointing to the correct digital pin in the sketch, and the virtual channel i have selected is V1. When i upload the sketch, the relay flickers indicating that it is pointed to the correct pin.
Here is my code, any help would be greatly appreciated!!
/*
Cayenne Relay Switch Example
This sketch sample file shows how to set up a Relay Switch with Cayenne.
The CayenneMQTT 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 Relay Switch widget.
- Select a virtual channel number for the widget.
- Set the VIRTUAL_CHANNEL value below to the virtual channel you selected.
- Connect your relay switch to a digital pin.
- Set the ACTUATOR_PIN value below to the digital pin number you selected.
- Set the Cayenne authentication info to match the authentication info from the Dashboard.
- Compile and upload this sketch.
- Once the Arduino connects to the Dashboard you can use the widget button to turn the relay switch on and off.
*/
//#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneMQTTSerial.h>
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = âXXXXXXXXXXXXXXXXXXXXXXXXXXXPreformatted text
â;
char password = âXXXXXXXXXXXXXXXXXXXâ;
char clientID = âXXXXXXXXXXXXXXâ;
#define VIRTUAL_CHANNEL V1
#define ACTUATOR_PIN 12 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.
void setup()
{
//Serial.begin(9600);
pinMode(ACTUATOR_PIN, OUTPUT);
Cayenne.begin(username, password, clientID);
}
void loop()
{
Cayenne.loop();
}
// This function is called when data is sent from Cayenne.
CAYENNE_IN(VIRTUAL_CHANNEL)
{
// Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
if (getValue.asInt() == 0) {
digitalWrite(ACTUATOR_PIN, HIGH);
}
else {
digitalWrite(ACTUATOR_PIN, LOW);
}
}