sending double address to i2c sensor

johnlong

Senior Member
Hi
I am thinking of getting the senseair sunrise co2 sensor just reading through the data sheet for the i2c link up
it states to send the i2c address twice can this be accomplished by
HI2CSETUP I2CMASTER, 0x68, I2Cslow, I2Cbyte
hi2cout (0x68)
sun.jpg
hi2cout (0x68)
regards john
 

hippy

Technical Support
Staff member
Do you have a link to a datasheet ?

You might be able to wake it up using a dummy read - HI2CIN 0,(b0) - otherwise you might have to bit-bang the I2C.
 

hippy

Technical Support
Staff member
That 0x68 default DeviceAddress appears to be 7-bit so $D0 (%11010000) as 8-bit . I would try this first, see if it gives reasonable expected results or not -
Code:
Symbol DEVICE_ADDRESS = 0x68 * 2

Symbol FIRM_ADR = 0x38
Symbol TEMP_ADR = 0x08

PowerOnReset:
  HI2cSetup I2CMASTER, DEVICE_ADDRESS, I2CSLOW, I2CBYTE
  Pause 3000
  SerTxd( "Starting", CR, LF )

MainLoop:
  Do

    w1 = 0
    HI2cIn FIRM_ADR, ( b0     )
    HI2cIn FIRM_ADR, ( b3, b2 ) ; w1 = Firmware
    Sertxd( "Firmware    = ", #b3, ".", #b2, CR, LF )
    Pause 1000

    w2 = 0
    HI2cIn TEMP_ADR, ( b0     )
    HI2cIn TEMP_ADR, ( b5, b4 ) ; w2 = Temperature
    b1 = w2 /  100
    b0 = w2 // 100
    If b0 < 10 Then
      Sertxd( "Temperature = ", #b1, ".0", #b0, "C", CR, LF )
    Else
      Sertxd( "Temperature = ", #b1, ".",  #b0, "C", CR, LF )
    End If
    Pause 5000

    SerTxd( CR, LF )
  Loop
 

johnlong

Senior Member
Hi
I am only recieving back
Firmware = 255.255
Temperature = 143.35C (result copied of the serial terminal screen)
Have tried the 0x68 and the 0xD0 8 bit from post #4 the same results
seems alot of wiring for such a small unit
regards john
 

johnlong

Senior Member
Hi Hippy
It now reading the 2 values as you intended not sure
what I did. Rewired and programmed it to try if it would communicate via serial
no joy so rewired it back to 12c and reprogrammed and hey presto

Starting
Firmware = 0.14
Temperature = 18.39C

Firmware = 0.14
Temperature = 18.39C

Firmware = 0.14
Temperature = 18.39C
Copied from the serial terminal
maybe a bad connection on the COMSEL pin on the bread board to GND
regards
 

johnlong

Senior Member
Hi
Have exstended your code to read the CO2 levels and the devices error bits
from the serial terminal
Firmware = 0.14
Temperature = 20.09C
CO2 = 460 ppm
ERROR BITS = 0000000000000000

Firmware = 0.14
Temperature = 20.10C
CO2 = 467 ppm
ERROR BITS = 0000000000000000
#extension of Hippys code
Code:
#Picaxe 28x2
#no_table
#no_data
Symbol DEVICE_ADDRESS = 0x68 * 2
Symbol CO_ADR= 0x10
Symbol FIRM_ADR = 0x38
Symbol TEMP_ADR = 0x08
Symbol ERROR_ADR = 0x00
PowerOnReset:
  HI2cSetup I2CMASTER, DEVICE_ADDRESS, I2CSLOW, I2CBYTE
  Pause 3000
  SerTxd( "Starting", CR, LF )

MainLoop:
  Do

    w1 = 0
    HI2cIn FIRM_ADR, ( b0     )
    HI2cIn FIRM_ADR, ( b3, b2 ) ; w1 = Firmware
    Sertxd( "Firmware    = ", #b3, ".", #b2, CR, LF )
    Pause 1000

    w2 = 0
    HI2cIn TEMP_ADR, ( b0     )
    HI2cIn TEMP_ADR, ( b5, b4 ) ; w2 = Temperature
    b1 = w2 /  100
    b0 = w2 // 100
    If b0 < 10 Then
      Sertxd( "Temperature = ", #b1, ".0", #b0, "C", CR, LF )
    Else
      Sertxd( "Temperature = ", #b1, ".",  #b0, "C", CR, LF )
    End If 
    pause 1000
    w3 = 0
    Hi2cin CO_ADR,(b0)
    Hi2cin CO_ADR,(b7,b6)
    sertxd("CO2 = ", #w3," ppm",cr,lf)
    pause 1000
    Hi2cin ERROR_ADR, (b2)
    Hi2cin ERROR_ADR, (b1,b0)
    sertxd("ERROR BITS = ",#bit15,#bit14,#bit13,#bit12,#bit11,#bit10,#bit9,#bit8,#bit7,#bit6,#bit5,#bit4,#bit3,#bit2,#bit1,#bit0,cr,lf)
    Pause 5000

    SerTxd( CR, LF )
  Loop
This is with the unit running in continious mode next step is to look into wiring it for single read for battery use which will invole toggling the EN pin
and the falling edge of the nRDY pin (do:loop until pinC.6=0 would this do it) or it mentions a 2 second pause before read to save a pin
The data sheet shows it conected to a 1.8v device would both the device and the picaxe at 3.3v cause a problem
or are they just showing an example of the minimum device usable voltage
regards
 

hippy

Technical Support
Staff member
It now reading the 2 values as you intended not sure
what I did.
It could be that some power-on delay needs adding, or one needs to discard some initial readings until it has settled down.

That "Firmware = 255.255" suggests that, if it's not ready it reads $FF, so I would perhaps check to see if you get any $FFFF reading and discard that, perhaps read the Firmware value every time and see if either are $FF before retrying if it is.

Or maybe there was just a loose connection.

The data sheet shows it conected to a 1.8v device would both the device and the picaxe at 3.3v cause a problem
Looking at the PSP4731.pdf datasheet link in your second linked datasheet that says; 3.05V to 5.5V. Table 1, page 3.
 

johnlong

Senior Member
Hi Hippy
My moneys on loose connection
added 2 bread boards together side by side via the lugs as the pins are wider than a single boards pins
its being running since
4pm with out missing a read as I added the measurements taken funtion at 0x0D
thanks for the help baffling me that double send of the device address
regards
 
Top