Porting Library: Adafruit CCS811

Hi all!

I’m quite new to this platform and currently trying to port the Adafruit CCS811 library.

I’m currently trying to port the library so that I can use the Sensor for one of my projects however no error occurs in IDE and the Particle Photon crashes as soon as it tries to load.

I have tried to replaced some of the ‘includes’ but that does not help.

Anybody have an idea on how to approach this?

Adding a link to the library sources would be the first step to get people to help out :wink:

Also be a bit more specific about this

How does this crashing look?
Is it a red SOS pattern followed by # red blinks? How many?

If it’s five I’d have a look at this

double Adafruit_CCS811::calculateTemperature()
{
	uint8_t buf[4];
	this->read(CCS811_NTC, buf, 4);

	uint32_t vref = ((uint32_t)buf[0] << 8) | buf[1];
	uint32_t vntc = ((uint32_t)buf[2] << 8) | buf[3];
	
	//from ams ccs811 app note
	uint32_t rntc = vntc * CCS811_REF_RESISTOR / vref;
	
	double ntc_temp;
	ntc_temp = log((double)rntc / CCS811_REF_RESISTOR); // 1
	ntc_temp /= 3380; // 2
	ntc_temp += 1.0 / (25 + 273.15); // 3
	ntc_temp = 1.0 / ntc_temp; // 4
	ntc_temp -= 273.15; // 5
	return ntc_temp - _tempOffset;

}

where DIV/0 exceptions might occure.

Oh whoops forgot a few things was in a rush when I posted.

https://github.com/adafruit/Adafruit_CCS811/archive/master.zip

I think it doesn’t crash it flashes green (which I think means it can’t contact the server)

That’s a completely different story than crashing then :wink:
You need to be more precise when talking to programmers (just like when talking to µCs)

This will probably be the reason for flashing green

  if(!ccs.begin()){
    Serial.println("Failed to start sensor! Please check your wiring.");
    while(1); // <-- not time for cloud maintenance!
  }
  // or
    else{
      Serial.println("ERROR!");
      while(1);
    }

(Assuming you are using the test sample - since you didn’t say either)

Yes that seems to be the problem! Thanks!

@ParticleStudent, have you ever finished this port?
As I was just about to publish the lib I saw that the name was already taken by a private (not published for others) version and hence unavailable for an official publish.
If this was you, are you going to ever publish this port?


Update:
I was able to get ownership of the lib and have published it here
https://build.particle.io/libs/Adafruit_CCS811/1.0.0/tab/Adafruit_CCS811.cpp

3 Likes