Chipkit WF32 and SCD30 Sensor not working

Hello,

Have had a little experience with programming, but very little to adding/modifying libraries. The WF32 tries to talk to the SCD30, but seems a bit off and not sure how to fix. The sketch is the Example2_SetOptions with the pin add statements that is called out for the WF32 in the reference guide. I also changed the altitude to mine. The compiler is MPIDE 0150. I receive the error in the RS232 console: Air sensor not detected. Please check wiring. The BME280 that is the last in the chain and works and also the I2C device detect program see the address of both. I have also included a couple of pictures from my scope. The second part (Middle, End) looks to be the data part of the conversation, but a couple of the pulses are very short? I am stumped and any insight/direction would be most appreciated.

Code:

/*

Reading CO2, humidity and temperature from the SCD30

By: Nathan Seidle

SparkFun Electronics

Date: May 22nd, 2018

License: MIT. See license file for more information but you can

basically do whatever you want with this code.

Feel like supporting open source hardware?

Buy a board from SparkFun! https://www.sparkfun.com/products/15112

This example prints the current CO2 level, relative humidity, and temperature in C.

Hardware Connections:

Attach RedBoard to computer using a USB cable.

Connect SCD30 to RedBoard using Qwiic cable.

Open Serial Monitor at 115200 baud.

Note: All settings (interval, altitude, etc) are saved to non-volatile memory and are

loaded by the SCD30 at power on. There’s no damage in sending that at each power on.

Note: 100kHz I2C is fine, but according to the datasheet 400kHz I2C is not supported by the SCD30

*/

#include <Wire.h>

#include <DTWI.h> //added so it would compile

#include “SparkFun_SCD30_Arduino_Library.h” //Click here to get the library: http://librarymanager/All#SparkFun_SCD30

SCD30 airSensor;

void setup()

{

// added for WF32

pinMode(62, OUTPUT);

pinMode(63, OUTPUT);

digitalWrite(62, HIGH);

digitalWrite(63, HIGH);

Serial.begin(115200);

Serial.println(“SCD30 Example”);

Wire.begin();

if (airSensor.begin() == false)

{

Serial.println(“Air sensor not detected. Please check wiring. Freezing…”);

while (1)

;

}

Serial.print(“SCD30) Present”);

airSensor.setMeasurementInterval(16); //Change number of seconds between measurements: 2 to 1800 (30 minutes), stored in non-volatile memory of SCD30

//While the setting is recorded, it is not immediately available to be read.

delay(200);

int interval = airSensor.getMeasurementInterval();

Serial.print("Measurement Interval: ");

Serial.println(interval);

//My desk is ~30m above sealevel

airSensor.setAltitudeCompensation(30); //Set altitude of the sensor in m, stored in non-volatile memory of SCD30

//Read altitude compensation value

unsigned int altitude = airSensor.getAltitudeCompensation();

Serial.print("Current altitude: ");

Serial.print(altitude);

Serial.println(“m”);

//Pressure in Boulder, CO is 24.65inHg or 834.74mBar

airSensor.setAmbientPressure(835); //Current ambient pressure in mBar: 700 to 1200, will overwrite altitude compensation

airSensor.setTemperatureOffset(5); //Optionally we can set temperature offset to 5°C, stored in non-volatile memory of SCD30

//Read temperature offset

float offset = airSensor.getTemperatureOffset();

Serial.print("Current temp offset: ");

Serial.print(offset, 2);

Serial.println(“C”);

}

void loop()

{

if (airSensor.dataAvailable())

{

Serial.print(“co2(ppm):”);

Serial.print(airSensor.getCO2());

Serial.print(" temp(C):");

Serial.print(airSensor.getTemperature(), 1);

Serial.print(" humidity(%):");

Serial.print(airSensor.getHumidity(), 1);

Serial.println();

}

else

Serial.print(“.”);

delay(1000);

}

My best,

Gorden

Hello,

Do I need to do additional “things” to get any help? Just looking for some direction/idea as I have spent some time, read hours on my own trying to make this work. I noticed that the sparkfun BME280 has a MAX32 version of the library and have tried to copy that format and create my own library, have been able to get it to compile and a wave form is displayed, but same result. I also have read that the clock stretching needs to happen during the ACK (which is never seen) and do not see where in the libraries that is is called?

I never worked on the WF32 nor studied it, hence I left this topic for what it was.

Maybe SOME help. Indeed the SCD30 is using clock stretching. This should be handled by the i2C / Wire library but I had difficulties with that on an ESP32 which does not support that. Hence I took the Wire library from an ESP8266 and made it work on ESP32. I have posted my version of the SCD30 (with additional functions) on https://github.com/paulvha/scd30.

Maybe you can use the Softwire (with some changes) on the WF32.

Hello,

Thank You for the suggestion, will give it a try. I do have a question? Do you know what action/response cause the clock stretching action to occur from the master? Will help me understand the handshakes and also how the data is sent and ACK’ed. When running my I2C device detection program (which picks up the CO2 detector and also my 4 other devices) is the clocked being stretched during the ACK?

My best,

Gorden

HI Gorden,

Clock stretching is not initiated by the master (Controller). The slave (peripheral) will cause this and the master needs to detect it. Normally a peripheral is performing a clock stretch when it needs more time to respond to a request from the controller. It puts the controller on hold/pause by keeping SCL LOW while it generates the answer to send. Once the answer is ready the peripheral will release the SCL line and the controller can now request the answer/data.

When doing an I2C scanner, nothing else than an ACK on the address is expected. There is no request for data hence there is often no clock stretch needed.

Final point: Clock stretch can happen at any moment, but often it is only at ACK.

Hello Paul,

Thank you for the response, quite informative. Used your program and still the same, however did enable the debugs with a value of two and constantly get ack not seen messages. This would seem to indicate that my processor is not clock stretching, however if you look at the top picture titled middle as in the second picture out of three of the conversation the clock looks to have been stretched, is my understanding incorrect? I am also wondering if slowing down the clock speed might help as this processor clock speed is 80Mhz, I am guessing here as I can’t scope it as it decided to call it quits after all these years :frowning: . Would you know the commands to set the clock speed to 50K instead of 100K?

My best,

Gorden

hi Gorden,

Too bad… 2 answers.

In the driver begin(). make sure to include _i2cPort->setClockStretchLimit(200000); to enable a longer clock stretch in the SoftWire.

to change the speed after begin() in the sketch do Wire.setSpeed(50000); for 50K