Problems reading sensors CC3200 w BOOSTXL to Cayenne


#1

I connected the CC3200 to Cayenne and set up the dashboard. To test connectivity I put in constant values for the sensors and they showed up on cayenne however when I replaced those values with their assigned variables they just read 0 which is the initialization value they were set at. Any ideas on how to fix this problem would be much appriciated


#2

@Tplenig Welcome to cayenne community. Can you post the code so that we can find the error out.


#3

@shramiksalgaonkar ok thanks so I fixed that problem however it now once I try to add the OPT3001 into the system everything stops working on it. With the BME and TMP it works fine though w/o the OPT active

// Define structures and classes
WiFiServer myServer(80); // Port 80
uint8_t oldCountClients = 0;
uint8_t countClients = 0;

Adafruit_TMP007 tmp007(0x40);
Adafruit_BME280 bme;
BMA222 bma222;
opt3001 opt3001;

boolean state = false;

//initialize variables to store sensor readings
int button1 = 0;
int button2 = 0;
float temp = 0;
float pressure = 0;
float altitude = 0;
float humidity = 0;
float diet = 0;       //Ambient temperature sensor in degrees Celsius
float result = 0;     //variable to store output from light sensor in Lux
float accX = 0;
float accY = 0;
float objt = 0;
float accZ = 0;
float timePast = 0; //variable to store the number of milliseconds since the Microcontroller was powered up

const uint32_t period_ms = 10000;
uint32_t chrono = 0;

void setup()
{
  Serial.begin(9600);
  Cayenne.begin(username, password, clientID, wifi_name, wifi_password);
  Wire.begin();

  delay(500);

//  opt3001.begin();  //This function makes a call to initialize the OPT3001

  if (! tmp007.begin()) {   //Initializes the TMP007 and returns an error which halts the program if the initialization failed
    //Serial.println("Could not find a valid TMP007 sensor.");
    while (1);
  }
  if (! bme.begin()) {      //Initializes the BME280 and returns an error which halts the program if the initialization failed
    //Serial.println("Could not find a valid BME280 sensor.");
    while (1);
  }
//  if (! opt3001.begin()) {      //Initializes the OPT3001 and returns an error which halts the program if the initialization failed
////    Serial.println("Could not find a valid OPT3001 sensor.");
//    while (1);
//  }

  delay(500);


}

// Add loop code
void loop()
{
  
  Cayenne.loop();
  
  Cayenne.virtualWrite(0, chrono);
  
if (millis() > chrono)
    {
        chrono = millis() + period_ms;


      temp = bme.readTemperature();    //Returns temperature in Celsius
//      myClient.print(temp); myClient.print(",");

//      lux = opt3001.readResult();
//      myClient.print(lux); myClient.print(",");

      pressure = bme.readPressure();       //Returns pressure in hectopascals (hPa)
//      myClient.print(pressure); myClient.print(",");

      humidity = bme.readHumidity();       //Returns Humidity in percentage
//      myClient.print(humidity); myClient.print(",");

      // This is the tempurature reading for what is in front of the sensor
      objt = tmp007.readObjTempC();     //Stores output from Object temperature sensor in degrees Celsius;
//      myClient.print(objt); myClient.print(",");

//      // This is the Ambient tempurature of the tempurature sensor
//      diet = tmp007.readDieTempC();     //Stores output from Ambient temperature sensor in degrees Celsius;
//      myClient.print(diet); myClient.print(",");

//      // This is the light sensor which returns light intensity
//      result = opt3001.readResult();    //Stores output from light sensor in Lux;
//      myClient.print(result); myClient.print(",");

      delay(1000);                            //This is used to delay time between taking sensor readings

      Cayenne.luxWrite(1, result);
//      Cayenne.celsiusWrite(2, temp);
      Cayenne.hectoPascalWrite(2, pressure);
      Cayenne.virtualWrite(4, humidity);
      Cayenne.celsiusWrite(5,objt);

      
  }

}

#4

I’m assuming you omitted your include statements, in which case just add them to the top of this code. Let me know if this works and what you are getting in the serial console.

// Define structures and classes
//WiFiServer myServer(80); // Port 80
uint8_t oldCountClients = 0;
uint8_t countClients = 0;

Adafruit_TMP007 tmp007(0x40);
Adafruit_BME280 bme;
BMA222 bma222;
opt3001 opt3001;

boolean state = false;

//initialize variables to store sensor readings
int button1 = 0;
int button2 = 0;
float temp = 0;
float pressure = 0;
float altitude = 0;
float humidity = 0;
float diet = 0;       //Ambient temperature sensor in degrees Celsius
float result = 0;     //variable to store output from light sensor in Lux
float accX = 0;
float accY = 0;
float objt = 0;
float accZ = 0;
float timePast = 0; //variable to store the number of milliseconds since the Microcontroller was powered up

const uint32_t period_ms = 10000;
uint32_t chrono = 0;

void setup()
{
	Serial.begin(9600);
	Cayenne.begin(username, password, clientID, wifi_name, wifi_password);
	Wire.begin();

	delay(500);

	if (! tmp007.begin()) {   //Initializes the TMP007 and returns an error which halts the program if the initialization failed
		Serial.println("Could not find a valid TMP007 sensor.");
		while (1);
	}
	if (! bme.begin()) {      //Initializes the BME280 and returns an error which halts the program if the initialization failed
		Serial.println("Could not find a valid BME280 sensor.");
		while (1);
	}
	if (! opt3001.begin()) {      //Initializes the OPT3001 and returns an error which halts the program if the initialization failed
		Serial.println("Could not find a valid OPT3001 sensor.");
		while (1);
	}

  delay(500);
}

// Add loop code
void loop(){
	Cayenne.loop();

	Cayenne.virtualWrite(0, chrono);

	if (millis() > chrono){
		chrono = millis() + period_ms;
		temp = bme.readTemperature();    //Returns temperature in Celsius
		lux = opt3001.readResult();
		pressure = bme.readPressure();       //Returns pressure in hectopascals (hPa)
		humidity = bme.readHumidity();       //Returns Humidity in percentage
		// This is the tempurature reading for what is in front of the sensor
		objt = tmp007.readObjTempC();     //Stores output from Object temperature sensor in degrees Celsius;
		// This is the Ambient tempurature of the tempurature sensor
		diet = tmp007.readDieTempC();     //Stores output from Ambient temperature sensor in degrees Celsius;
		// This is the light sensor which returns light intensity
		result = opt3001.readResult();    //Stores output from light sensor in Lux;
		
		//Print results in serial console
		Serial.println("chrono: " + chrono);
		Serial.println("temp: " + temp);
		Serial.println("lux: " + lux);
		Serial.println("pressure: " + pressure);
		Serial.println("humidity: " + humidity);
		Serial.println("objt: " + objt);
		Serial.println("diet: " + diet);
		Serial.println("result: " + result);

		delay(1000);                            //This is used to delay time between taking sensor readings

		Cayenne.luxWrite(1, result);
		//      Cayenne.celsiusWrite(2, temp);
		Cayenne.hectoPascalWrite(2, pressure);
		Cayenne.virtualWrite(4, humidity);
		Cayenne.celsiusWrite(5,objt);
	}
}