Open hapklaar opened 4 years ago
Have you tried i2c-scanner to verify the connections and the address... try that first. I can help you more tomorrow if it doesn’t work out 👍
Search for the i2c scanner if you don’t have it....
/Niclas
30 aug. 2020 kl. 14:19 skrev hapklaar notifications@github.com:
Hi,
Thanks for your work on this! I'm playing a bit with this sensor and am trying to get your examples to work, unfortunately haven't been able to get any output by using the i2c bus. UART works fine though. I'm new to i2c, so still learning :)
I'm thinking it's probably not working due to me not having any external pullup resistors on SCL and SDA. Was hoping the internal pullup function of wire.h would enable me to work without them. How did you connect the sensor to your board? Did you also connect VDDIO per the instructions in TDE7318.pdf (page 6)?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.
It could be due to settings of the sensor... have you tried the readInfo sketch? Are you reading continuously or just single requests?
i2c scanner finds the sensor and shows its at 0x68. Was also able to query the sensor over i2c successfully with another sketch only using wire.h. (see found code below). Unfortunately got the same waiting response with the readInfo sketch
#include <Wire.h>
char FIND_ADDRESS = 'F';
char READ_CO2 = 'R';
byte address = 0x68;
//byte address = 104; //slave address
void setup() {
// put your setup code here, to run once:
Wire.begin();
Wire.setClock(10000);
Serial.begin(115200);
Serial.println("Type F to find all devices on I2C bus and type R to read CO2 from S-11");
}
void sendDataAndReadToAddress(byte reg, byte address, int bufferSize, int readCount) {
Wire.beginTransmission(address);
for (int k = 0; k < bufferSize; k++) {
Wire.write(reg);
}
Wire.endTransmission(false);
delay(24);
Wire.requestFrom(address, readCount);
delay(12);
int nBytes = Wire.available();
byte buff[nBytes];
int i = 0;
while (Wire.peek() != -1) {
buff[i] = Wire.read();
Serial.print(buff[i],HEX);
Serial.print(" ");
i++;
}
//Serial.write(buff, nBytes);
Serial.print('\n');
int co2 = (buff[0] << 8) | buff[1];
Serial.print("CO2 Concentration: ");
Serial.print(co2);
Serial.print("\n");
}
void getAllAddress() {
//Serial.println("Looking for addresses");
byte error, address;
for (address = 1; address < 128; address++) {
Wire.beginTransmission(address);
error = Wire.endTransmission();
delay(5);
if (error == 0) {
Serial.print(address, HEX);
Serial.print(" ");
}
}
}
void loop() {
// put your main code here, to run repeatedly:
while (Serial.available() == 0) { }
//Delay 10ms to ensure we get the whole message
delay(15);
int serialBufferSize = Serial.available();
byte buff[serialBufferSize];
int i = 0;
while (Serial.peek() != -1 && i < serialBufferSize) {
buff[i] = (byte)Serial.read();
i++;
}
char command = (char)buff[0];
if (command == FIND_ADDRESS) {
getAllAddress();
} else if (command == READ_CO2) {
//The LSB nibble of the second byte contains the number of data bytes being read
//Add 2 for the Command byte and Checksum
int bufferSize = 1;
int readCount = 2;
sendDataAndReadToAddress(0x06, address, bufferSize, readCount);
} else {
Serial.println("Invalid Command... Type F to find all devices on I2C bus and type R to read CO2 from S-11");
}
}
Try to remove the following lines:
while(sunrise.readErrorStatus() >> 7){
Serial.println("Waiting for first measurement to arrive...");
delay(1000);
I added it to avoid initial false readings...
The message I'm getting is "Waiting for sunrise response from address 0x68"
Not sure what removing that section of code would do as it's not happening in that loop?
Sorry, I didn’t read your error message careful enough. You get stuck during init so the i2c bus is not up. What pins are you using for SCL and SDA?
GPIO 22 (SCL) and GPIO 21 (SDA)?
GPIO 22 (SCL) and GPIO 21 (SDA)?
Yes indeed. GPIO21 and 22, which works with the sketch I posted. Which makes me guess the i2c bus is connected correctly to the sensor.
Yes...hmmm, strange. I use it in all my CO2 sensors without issue... I’ll check tomorrow so the latest code is pushed to my repo. Can’t think of anything else.
Great, thanks for taking the time!
In the mean time I broke the USB connector of the pcb, so got some soldering to do...
No problem!
PS just to be sure, have you tied up the sensor according to this diagram as well?
Only thing I left out is nRDY
If you plan to use it in continuous mode then this wiring is correct!
Mine are wired so they can use both single and continuous measurements, but you don’t necessarily have to do that if you plan to only use continuous mode...
The ones I used as prototypes are wired as above. You can see the traces...
That's so cool! I like your pcb design, easy for mounting the sensor in an enclosure and limiting the number of wires needed to connect it especially.
I'm currently trying to use it for continuous usage, but also very interested in on demand reading in a battery powered unit. This sensor is great in that it doesn't require warmup time, so could be very useful for that.
Do you also use 10k pullup resistors, or are you using a lower value?
It is not that sensitive. I have successfully used from 4-10k... Yes, I have tested a lot of CO2 sensors and this one is in a league of its own. I wired up five and placed next to each other and they only differ 5-10 ppm after a few weeks in operation.
I used the sketch "continous.ino" as is in the library and it worked just fine here..?
Curious... I'm sure I've also tried the continuous sketch and got that error. I will try again once I have my ESP32 board back up with the usb port attached ;)
Ok was able to test again, and got 2 different results with continuous v1.0.0. When I power on the ESP32 by connecting the USB, I get this:
After I press the reset button, I get this:
Strange right?
In both cases the bus is down but for some reason you got past the first bus check in initialization in your first example..? Did you get “i2c ready!” in the beginning?
1 sep. 2020 kl. 18:49 skrev hapklaar notifications@github.com:
Ok was able to test again, and got 2 different results with continuous v1.0.0. When I power on the ESP32 by connecting the USB, I get this:
After I press the reset button, I get this:
Strange right?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.
I can't see as I need to restart serial monitor for it to capture anything in that situation. I'm too late to see if that is the case.
By the way, when I disconnect SDA and SCL I get a different error:
Waiting for first measurement to arrive... Failed to write to sensor!
I'm going to test some different boards. They are 8266's, I guess that is no problem?
Probably not the board since your other sketch works. You probably need some minor tweaks to run on 8266, data pins for example...
1 sep. 2020 kl. 19:05 skrev hapklaar notifications@github.com:
I can't see as I need to restart serial monitor for it to capture anything in that situation. I'm too late to see if that is the case.
By the way, when I disconnect SDA and SCL I get a different error:
Waiting for first measurement to arrive... Failed to write to sensor!
I'm going to test some different boards. They are 8266's, I guess that is no problem?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.
The other sketch is now also giving strange values. Must be something wrong with the board, wiring/breadboard or sensor.
How does you library determine SDA and SCL? Is it hardcoded or does it use wire.h designations?
Looking at all the compile errors, it looks like it's not gonna be easy enough for me. ;)
Do you have a spare module or only one? Do you have an oscilloscope to check signals?
1 sep. 2020 kl. 19:14 skrev hapklaar notifications@github.com:
The other sketch is now also giving strange values. Must be something wrong with the board, wiring/breadboard or sensor.
How does you library determine SDA and SCL? Is it hardcoded or does it use wire.h designations?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.
I don't have a spare ESP32 unfortunately, got a some Wemos D1 mini's, but they are 8266.
I do have a scope, but not very proficient with it yet.
Just put one probe on scl and one on sda and the crocodiles on ground. Start the scope an push “auto”. Set trigger level to 1.5V and trigger on rising edge. You should see a 400kHz square wave on scl and you should see the data packages on sda. You don’t have to dig any deeper than that. If you see “nice” signals going from 0V to 3.3 then you are all good. You can then see if you can see both the request package and the response package. If there are no packages att all then esp is faulty. If you see the request package but no response then the CO2 module is faulty... I’m sure you can do it! What kind of scope is it? If the signals are disturbed there could be a wiring issue or pull-up/pull-down problem... give it a try😀
That sounds interesting and doable even for me 😀
I have a DSO138 and also have an old Tektronix 2215. Will give it a go when I have some more time, I hope later this week!
Hi,
Thanks for your work on this! I'm playing a bit with this sensor and am trying to get your examples to work, unfortunately haven't been able to get any output by using the i2c bus. UART works fine though. I'm new to i2c, so still learning :)
I'm thinking it's probably not working due to me not having any external pullup resistors on SCL and SDA. Was hoping the internal pullup function of wire.h would enable me to work without them. How did you connect the sensor to your board? Did you also connect VDDIO per the instructions in TDE7318.pdf (page 6)?
PS Got the device to show up on i2c bus with the proposed 10k pullup resistors, but its not able to communicate it seems. Output of serial is: Waiting for sunrise response from address 0x68