Thank you both for responding so quickly!
Well I connected the arduino as shown below:
The arduino’s A4/A5 can be connected just as easily to the 3.3V bus.
I’d run different code on the arduino depending on which sensor I was looking at, but for instance, the code for the sgp30 is
#include <Wire.h>
#include "Adafruit_SGP30.h"
Adafruit_SGP30 sgp;
/* return absolute humidity [mg/m^3] with approximation formula
* @param temperature [°C]
* @param humidity [%RH]
*/
uint32_t getAbsoluteHumidity(float temperature, float humidity) {
// approximation formula from Sensirion SGP30 Driver Integration chapter 3.15
const float absoluteHumidity = 216.7f * ((humidity / 100.0f) * 6.112f * exp((17.62f * temperature) / (243.12f + temperature)) / (273.15f + temperature)); // [g/m^3]
const uint32_t absoluteHumidityScaled = static_cast<uint32_t>(1000.0f * absoluteHumidity); // [mg/m^3]
return absoluteHumidityScaled;
}
void setup() {
Serial.begin(115200);
while (!Serial) { delay(10); } // Wait for serial console to open!
Serial.println("SGP30 test");
if (! sgp.begin()){
Serial.println("Sensor not found :(");
while (1);
}
Serial.print("Found SGP30 serial #");
Serial.print(sgp.serialnumber[0], HEX);
Serial.print(sgp.serialnumber[1], HEX);
Serial.println(sgp.serialnumber[2], HEX);
// If you have a baseline measurement from before you can assign it to start, to 'self-calibrate'
//sgp.setIAQBaseline(0x8E68, 0x8F41); // Will vary for each sensor!
}
int counter = 0;
void loop() {
// If you have a temperature / humidity sensor, you can set the absolute humidity to enable the humditiy compensation for the air quality signals
//float temperature = 22.1; // [°C]
//float humidity = 45.2; // [%RH]
//sgp.setHumidity(getAbsoluteHumidity(temperature, humidity));
if (! sgp.IAQmeasure()) {
Serial.println("Measurement failed");
return;
}
Serial.print("TVOC "); Serial.print(sgp.TVOC); Serial.print(" ppb\t");
Serial.print("eCO2 "); Serial.print(sgp.eCO2); Serial.println(" ppm");
if (! sgp.IAQmeasureRaw()) {
Serial.println("Raw Measurement failed");
return;
}
Serial.print("Raw H2 "); Serial.print(sgp.rawH2); Serial.print(" \t");
Serial.print("Raw Ethanol "); Serial.print(sgp.rawEthanol); Serial.println("");
delay(1000);
counter++;
if (counter == 30) {
counter = 0;
uint16_t TVOC_base, eCO2_base;
if (! sgp.getIAQBaseline(&eCO2_base, &TVOC_base)) {
Serial.println("Failed to get baseline readings");
return;
}
Serial.print("****Baseline values: eCO2: 0x"); Serial.print(eCO2_base, HEX);
Serial.print(" & TVOC: 0x"); Serial.println(TVOC_base, HEX);
}
}
Which works when using the arduino, but the same code on the e-series fails at the sgp.begin() function, returning an error of “Sensor not found :(”. Even when adding a separate Wire.begin() function call in the setup.
What is also strange is that on the e-series i2c scanner, the sgp30 shows up. That i2c scanner code is shown below:
#include "Particle.h"
int led = D7;
int motor = B0;
void setup()
{
pinMode(motor,OUTPUT);
Particle.function("MOTOR_DUTY",mDuty);
pinMode(led,OUTPUT);
digitalWrite(led,HIGH);
delay(500);
digitalWrite(led,LOW);
delay(500);
digitalWrite(led,HIGH);
Particle.function("ILed",I2CT);
Serial.begin(9600);
// while ( digitalRead(led) ) {
// Serial.println("Waiting for keypress ...");
// // it waits until you run the ILed function on the console
// delay(1000);
// }
Wire.begin();
Serial.begin(9600);
delay(1000);
Serial.println("I2C Scanner\n");
Particle.publish("I2C Scanner");
}
char message[100];
char add[10];
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
Particle.publish("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
sprintf(message,"I2C device found at address 0x%x",address);
sprintf(add,"0x%x",address);
Particle.publish(message,add);
nDevices++;
}
else if (error==4)
{
Serial.print("Unknown error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
sprintf(message,"Unknown error at address 0x%x",address);
sprintf(add,"0x%x",address);
Particle.publish(message,add);
}
}
if (nDevices == 0) {
Serial.println("No I2C devices found\n");
Particle.publish("No I2C devices found");
}
else {
Serial.println("done\n");
Particle.publish("done");
}
delay(5000); // wait 5 seconds for next scan
}
int I2CT(String command) {
digitalWrite(led, digitalRead(led)^1 );
return digitalRead(led);
}
int mDuty(String command) {
float duty = (float)atoi(command);
duty = duty * 255.0/100.0;
analogWrite(motor,duty);
return duty;
}
Running this code on the particle outputs the sgp30’s i2c address. But I cant begin communication after that.
Thanks again for your help!