Can you guys help to check if the code is right?
and the picture is the layout for Arduino
:
#include "DFRobot_OzoneSensor.h"
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define COLLECT_NUMBER 20 // collect number, the collection range is 1-100
#define Ozone_IICAddress OZONE_ADDRESS_3
#define SEALEVELPRESSURE_HPA (1013.25)
/* iic slave Address, The default is ADDRESS_3
ADDRESS_0 0x70 // iic device address
ADDRESS_1 0x71
ADDRESS_2 0x72
ADDRESS_3 0x73
/
DFRobot_OzoneSensor Ozone;
Adafruit_BME280 bme;
void setup() {
Serial.begin(9600);
while (!Ozone.begin(Ozone_IICAddress)) {
Serial.println("I2c device number error !");
delay(1000);
}
Serial.println("I2c connect success !");
/ Set iic mode, active mode or passive mode
MEASURE_MODE_AUTOMATIC // active mode
MEASURE_MODE_PASSIVE // passive mode
*/
Ozone.setModes(MEASURE_MODE_PASSIVE);
if (!Ozone.begin(Ozone_IICAddress)) {
Serial.println("I2c device number error !");
delay(1000);
}
Serial.println("I2c connect success !");
/* Set iic mode, active mode or passive mode
MEASURE_MODE_AUTOMATIC // active mode
MEASURE_MODE_PASSIVE // passive mode
/
}
void loop() {
/ Smooth data collection
COLLECT_NUMBER // The collection range is 1-100
*/
int16_t ozoneConcentration = Ozone.readOzoneData(COLLECT_NUMBER);
Serial.print("Ozone concentration is ");
Serial.print(ozoneConcentration);
Serial.println(" PPB.");
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println("*C");
Serial.print("Pressure = ");
Serial.print(bme.readPressure() / 100.0F);
Serial.println("hPa");
Serial.print("Approx. Altitude = ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println("m");
Serial.print("Humidity = ");
Serial.print(bme.readHumidity());
Serial.println("%");
delay(1000);
}
The first thing that I do when I have trouble with I2C devices is to run an I2C scanner to confirm I2C addresses and communication with the bus.
// I2C scanner by Nick Gammon. Thanks Nick.
#include <Wire.h>
void setup() {
Serial.begin (115200); //***** make sure serial monitor baud matches *****
// Leonardo: wait for serial port to connect
while (!Serial)
{
}
Serial.println ();
Serial.println ("I2C scanner. Scanning ...");
byte count = 0;
Wire.begin();
for (byte i = 1; i < 120; i++)
{
Wire.beginTransmission (i);
if (Wire.endTransmission () == 0)
{
Serial.print ("Found address: ");
Serial.print (i, DEC);
Serial.print (" (0x");
Serial.print (i, HEX);
Serial.println (")");
count++;
delay (1); // maybe unneeded?
} // end of good response
} // end of for loop
Serial.println ("Done.");
Serial.print ("Found ");
Serial.print (count, DEC);
Serial.println (" device(s).");
} // end of setup
void loop() {}
Please post a schematic. Written descriptions are always more ambiguous than a drawing. Hand drawn, photographed and posted is fine. Include all pin names/numbers, components, their part numbers and/or values and power supplies.
Please read the forum guidelines to see how to properly post code and some information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in a code block.
Please go back and fix your original post.
Hi,
Thanks for your reply, I just updated my post.
and I2C is:
I2C Scanner
Scanning...
I2C device found at address 0x60 !
I2C device found at address 0x6A !
I2C device found at address 0x73 !
I2C device found at address 0x7E !
done
Two sensors can run individuality with the code but when I combined together, no data is showing
The (improperly) posted code is incomplete will not compile. Please post a compete, minimal and verifiable code that demonstrates the issue.
This one is for sen0321:
:
#include "DFRobot_OzoneSensor.h"
#define COLLECT_NUMBER 20 // collect number, the collection range is 1-100
#define Ozone_IICAddress OZONE_ADDRESS_3
/* iic slave Address, The default is ADDRESS_3
ADDRESS_0 0x70 // iic device address
ADDRESS_1 0x71
ADDRESS_2 0x72
ADDRESS_3 0x73
/
DFRobot_OzoneSensor Ozone;
void setup() {
Serial.begin(9600);
while (!Ozone.begin(Ozone_IICAddress)) {
Serial.println("I2c device number error !");
delay(1000);
}
Serial.println("I2c connect success !");
/ Set iic mode, active mode or passive mode
MEASURE_MODE_AUTOMATIC // active mode
MEASURE_MODE_PASSIVE // passive mode
/
Ozone.setModes(MEASURE_MODE_PASSIVE);
}
void loop() {
/ Smooth data collection
COLLECT_NUMBER // The collection range is 1-100
*/
int16_t ozoneConcentration = Ozone.readOzoneData(COLLECT_NUMBER);
Serial.print("Ozone concentration is ");
Serial.print(ozoneConcentration);
Serial.println(" PPB.");
delay(1000);
}
They are worked individually
system
Closed
November 15, 2023, 9:08pm
9
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.