|
Forum Index : Microcontroller and PC projects : CO2 sensing
| Author | Message | ||||
| karlelch Senior Member Joined: 30/10/2014 Location: GermanyPosts: 274 |
Another German video ;-) https://youtu.be/FfbP-4b5n9o |
||||
| karlelch Senior Member Joined: 30/10/2014 Location: GermanyPosts: 274 |
Here is the code to read out the CO2 sensor, if someone is interested. The sensor is the SCD41, available as breakout from Pimoroni Const I2C_ADDR = 98 Print "Initialize I2C ..." SetPin GP0, GP1, I2C I2C Open 100, 500 Print "Initialize sensor and start measuring ..." I2C Write I2C_ADDR, 0, 2, &H36, &H46 : Pause 50 I2C Write I2C_ADDR, 0, 2, &H21, &HB1 : Pause 2 Function isDataAvailable() Local Integer buf(2) = (0,0,0) I2C Write I2C_ADDR, 0, 2, &HE4, &HB8 : Pause 2 I2C Read I2C_ADDR, 0, 3, buf() isDataAvailable = ((buf(0) << 8) Or buf(1) And &HFFF) > 0 End Function Sub getData CO2, Tmp, Hum Local Integer val, buf(8) = (0,0,0,0,0,0,0,0,0) I2C Write I2C_ADDR, 0, 2, &HEC, &H05 : Pause 1 I2C Read I2C_ADDR, 0, 9, buf() CO2 = (buf(0) << 8) Or buf(1) val = (buf(3) << 8) Or buf(4) Tmp = (((21875 *val) >> 13) -45000) /1000 val = (buf(6) << 8) Or buf(7) Hum = ((12500 *val) >> 13) /1000 End Sub Dim integer i Dim float CO2, T, H For i=1 To 10 Print "Waiting for data ..." Do : Pause 100 : Loop Until isDataAvailable() getData CO2, T, H Print "CO2 = " +Str$(CO2,5,0) +" ppm" Print " T = " +Str$(T,-3,1) +Chr$(186) +"C" Print " H = " +Str$(H,5,0) +"%" Pause 1000 Next i Print "Stop measuring ..." I2C Write I2C_ADDR, 0, 2, &H3F, &H86 : Pause 600 |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |