I’ll preface this by stating that I am receiving accurate readings from my sensors and am able to control my servos using the slider from both the Web and iOS app.
-
Device & model you are using:
Arduino Uno via USB Serial -
What dashboard are you using?
Web and iOS -
Please describe the bug / issue as detailed as possible.
I’ve configured my triggers to power on set some servos when a thermistor sensor reaches a certain point, then change them back again when it cools down. I’ve tried setting up the triggers from both the web and iOS app. The web doesn’t let me choose a temperature unit but the iOS app does so that was the first issue, however, I am yet to be able to get my triggers to work what-so-ever. I’ve attached some screenshots/code below. Any help is greatly appreciated.
#include <CayenneTemperature.h>
#include <CayenneSerial.h>
#include <Servo.h>
// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "xxxxxxxxx";
// Virtual Pin of the Thermistor widget.
#define VIRTUAL_PIN V1
#define SERVO_VIRTUAL_PIN V2
#define SERVO_1_DIGITAL_PIN 9
#define SERVO_2_DIGITAL_PIN 10
// Analog pin the thermistor is connected to.
const int thermistorPin = 0;
// Resistance of the resistor. Currently set to 10k but this can be set to the measured resistance of your
// resistor for greater accuracy.
const float resistance = 10000;
Thermistor thermistor(thermistorPin, resistance);
Servo s1;
Servo s2;
int lastPosition = 0;
void setup() {
Cayenne.begin(token);
s1.attach(SERVO_1_DIGITAL_PIN);
s2.attach(SERVO_2_DIGITAL_PIN);
}
void loop() {
Cayenne.run();
}
// This function is called when the Cayenne widget requests data for the Virtual Pin.
CAYENNE_OUT(VIRTUAL_PIN) {
Cayenne.celsiusWrite(VIRTUAL_PIN, thermistor.getCelsius());
}
CAYENNE_IN(SERVO_VIRTUAL_PIN)
{
// get value sent from dashboard
double currentValue = getValue.asDouble();
int position = (int) currentValue;
// actually move the servo to the specified position
s1.write(position);
s2.write(position);
if (position > lastPosition) {
for (int i = lastPosition; i <= position; i += 1) {
s1.write(i);
s2.write(i);
delay(30);
}
} else if (position < lastPosition) {
for (int i = lastPosition; i >= position; i -= 1) {
s1.write(i);
s2.write(i);
delay(30);
}
}
//update last position
lastPosition = position;
}