Does not work when i type pinMode


#1

Hi guys i have 2 project on Cayenne and right now i have a issue. Can you talk about Cayenne.begin and Cayenne.loop parameters? I tried to official cayenne code about thermometer and lux values and its work very good but when i start to write a own code on void setup its not working i am just using pinMode command why it is not sending data?


#2

Hi ozbayalperen1

Could you post your code


#3

I cant share my all code because i can’t find to all part but i can share my code’s part and error. When i type this its work:

#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>

const int trigPin = 6;
const int echoPin = 7;

int duration;
int distance;

int sayi = 0;

char ssid[] = "";
char wifiPassword[] = "";

char username[] = "";
char password[] = "";
char clientID[] = "";

unsigned long lastMillis = 0;

void setup() {

	Serial.begin(9600);
	Cayenne.begin(username, password, clientID, ssid, wifiPassword);


}

void loop() {
  	Cayenne.loop();
   if (millis() - lastMillis > 10000) {
    lastMillis = millis();
   Cayenne.virtualWrite(0, lastMillis);

    Cayenne.virtualWrite(3, 13, TYPE_PROXIMITY, UNIT_CENTIMETER);
	}
}



CAYENNE_IN_DEFAULT()
{
	CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());
}

But if i type to pinmode command its not working like this:

#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>

const int trigPin = 6;
const int echoPin = 7;

int duration;
int distance;

int sayi = 0;

char ssid[] = "";
char wifiPassword[] = "";

char username[] = "";
char password[] = "";
char clientID[] = "";

unsigned long lastMillis = 0;

void setup() {
  pinMode(trigPin,OUTPUT);
  pinMode(ECHOPin,INPUT);
	Serial.begin(9600);
	Cayenne.begin(username, password, clientID, ssid, wifiPassword);


}

void loop() {
  	Cayenne.loop();
   if (millis() - lastMillis > 10000) {
    lastMillis = millis();
   Cayenne.virtualWrite(0, lastMillis);

    Cayenne.virtualWrite(3, 13, TYPE_PROXIMITY, UNIT_CENTIMETER);
	}
}



CAYENNE_IN_DEFAULT()
{
	CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());
}

#4

@ozbayalperen1 the problem is the pins which you have selected for trigger and echo. on esp8266 there are no GPIO 6 and 7. so changing them to 4 and 5 works.


#5

I am using nodeMcu bruh.


#6

@shramiksalgaonkar is correct. D6 and D7 is not GPIO 6 and GPIO 7. See below:


#7

I am using this one: https://goo.gl/vE8rKi


#8

No matter which variation you use, ESP8266 devices simply don’t have GPIO 6 or 7. D6 != GPIO6 and D7 != GPIO 7

Actually, the pinout was on the page you linked. D6 is GPIO 12 and D7 is GPIO 13. Replace the 6 and 7 with 12 and 13 and I think you will find it works.


#9

@ozbayalperen1 for once replace your 6 and 7 pin to other pin like 12 and 13 . Give it a try and see if it works and then reply.


#10

Thank you guys it is working :smiley: