How to assemble?


#1

In my project i have a lot of captor.
How to assemble him ?

Example : (Thermometer + Lamp

#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneMQTTEthernet.h>

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = “//”;
char password[] = “//”;
char clientID[] = “//”;

#define SENSOR_PIN 0
#define VIRTUAL_CHANNEL 3
#define VIRTUAL_CHANNEL 2
#define ACTUATOR_PIN 2 // 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 at intervals to send sensor data to Cayenne. //Lamp
CAYENNE_OUT(VIRTUAL_CHANNEL)
{
Cayenne.virtualWrite(VIRTUAL_CHANNEL, analogRead(SENSOR_PIN));
}

// This function is called when data is sent from Cayenne. //Thermometer
CAYENNE_IN(VIRTUAL_CHANNEL)
{
int value = getValue.asInt();
CAYENNE_LOG(“Channel %d, pin %d, value %d”, VIRTUAL_CHANNEL, ACTUATOR_PIN, value);
// Write the value received to the digital pin.
digitalWrite(ACTUATOR_PIN, value);
}

I try like this but it does’nt work.


#2

change this :

to

#define VIRTUAL_CHANNEL_0 3

#define VIRTUAL_CHANNEL_1 2

in your entire code


#3

Thanks you man ! ^^


#4

:frowning:

Whats is the problem…?


#5

just remove that line CAYENNE_LOG


#6

I’m triying


Mhh… :confused:


#7

made changes to your code.

 #define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneMQTTEthernet.h>

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";

#define SENSOR_PIN 0
#define VIRTUAL_CHANNEL_1 3
#define VIRTUAL_CHANNEL_2 2
#define ACTUATOR_PIN 2 // 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 at intervals to send sensor data to Cayenne. //Lamp
CAYENNE_OUT(VIRTUAL_CHANNEL_1)
{
Cayenne.virtualWrite(VIRTUAL_CHANNEL_1, analogRead(SENSOR_PIN));
}

// This function is called when data is sent from Cayenne. //Thermometer
CAYENNE_IN(VIRTUAL_CHANNEL_2)
{
int value = getValue.asInt();
digitalWrite(ACTUATOR_PIN, value);
}

#8

Thx I’m triying

EDIT : Its work ! Thx ^^

I took the same example to add a actuator but i have a conflict whit my lamp.
When i turn on my new actuator (A fan), my lamp turn on and my fan don’t on.
When i turn on my lamp, my lamp on correctly.


#9

can you post the code.


#10
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneMQTTEthernet.h>

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "//";
char password[] = "//";
char clientID[] = "//";

#define VIRTUAL_CHANNEL_4 4
#define ACTUATOR_PIN 4 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.

#define VIRTUAL_CHANNEL_1 3
#define SENSOR_PIN 3

#define VIRTUAL_CHANNEL_2 2
#define ACTUATOR_PIN 2 // 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 at intervals to send sensor data to Cayenne. //Thermo
CAYENNE_OUT(VIRTUAL_CHANNEL_1)
{
Cayenne.virtualWrite(VIRTUAL_CHANNEL_1, analogRead(SENSOR_PIN));
}

// This function is called when data is sent from Cayenne. //Lampe
CAYENNE_IN(VIRTUAL_CHANNEL_2)
{
int value = getValue.asInt();
digitalWrite(ACTUATOR_PIN, value);
}
// This function is called when data is sent from Cayenne. //Ventilateur
CAYENNE_IN(VIRTUAL_CHANNEL_4)
{
  int value = getValue.asInt();
  digitalWrite(ACTUATOR_PIN, value);
}

#11

give this a try

#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneMQTTEthernet.h>

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "//";
char password[] = "//";
char clientID[] = "//";

#define VIRTUAL_CHANNEL_4 4
#define ACTUATOR_PIN_1 4 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.

#define VIRTUAL_CHANNEL_1 3
#define SENSOR_PIN 3

#define VIRTUAL_CHANNEL_2 2
#define ACTUATOR_PIN_2 2 // Do not use digital pins 0 or 1 since those conflict with the use of Serial.


void setup()
{
Serial.begin(9600);
pinMode(ACTUATOR_PIN_1, OUTPUT);
pinMode(ACTUATOR_PIN_2, OUTPUT);
Cayenne.begin(username, password, clientID);
}

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

// This function is called at intervals to send sensor data to Cayenne. //Thermo
CAYENNE_OUT(VIRTUAL_CHANNEL_1)
{
Cayenne.virtualWrite(VIRTUAL_CHANNEL_1, analogRead(SENSOR_PIN));
}

// This function is called when data is sent from Cayenne. //Lampe
CAYENNE_IN(VIRTUAL_CHANNEL_2)
{
int value= getValue.asInt();
digitalWrite(ACTUATOR_PIN_1, value);
}
// This function is called when data is sent from Cayenne. //Ventilateur
CAYENNE_IN(VIRTUAL_CHANNEL_4)
{
  int value_1 = getValue.asInt();
  digitalWrite(ACTUATOR_PIN_2, value_1);
}

#12

Thx :yum:
Good bye ^^


#13

but i hope you are not just copying and pasting the code. try to understand and learn from the mistake you have made till now. anyways best of luck with your project.


#14

Don’t worry, I studied and understood