Shop OBEX P1 Docs P2 Docs Learn Events
Finaly ,Interfacing a K30 CO2 sensor to the Propeller [Video Added] — Parallax Forums

Finaly ,Interfacing a K30 CO2 sensor to the Propeller [Video Added]

Igor_RastIgor_Rast Posts: 357
edited 2012-12-31 05:27 in Propeller 1
I2C_comm_guide_2_1031.pdfHi ,
After some time has passed and i tried different methods to measure the co2 level in air , today I received a new kind of sensor
its the k30 co2 sensor , in the range of 1-10.000 ppm , and uses a ndir sensor .

Before i was doing some testing with the taguchi mg-811 but this sensor proven to be not so accurate and needs to be callibrated.

anyway . I thouth it would be intrested for others wanting to connect a pretty good co2 sensor to there project.
and a good way to get some help to get it connected without too much trouble

it communicates tru I2C ,. have to find out how and what still to get the communications going ,.

anybody have any experiance with this sensor ??? hoping me and other reading can learn allot

ill be posting the working code , when I get there :P
2012-12-27 12.10.46.jpg
2012-12-27 12.10.52.jpg
2012-12-27 13.11.32.jpg



vvvvvvvvvvv444.jpg

looking for a simple object to accomplish just this first step so it seems
1024 x 1365 - 105K
1024 x 1365 - 153K
1024 x 1365 - 122K
779 x 374 - 53K

Comments

  • BeanBean Posts: 8,129
    edited 2012-12-27 06:31
    I have worked with that sensor recently.
    I found it easiest to use the serial interface rather than the I2C interface.

    Here is the code I used:
    ' Setup Propeller Chip for 80 MHz operation from XTAL
    ' P0 = Serial data from K30
    ' P1 = Serial data to K30
    '
    CON
      _clkmode        =  xtal1+ pll16x
      _xinfreq        = 5_000_000
    
    
    OBJ
      K30:  "Parallax Serial Terminal" ' To communicate with K30
      term: "Parallax Serial Terminal" ' to communicate with PC
      
    CON
        
    VAR
      LONG value
          
    PUB start
      term.start(9600)
      K30.StartRxTx(1, 0, 0, 9600)  ' For PC communication
    
    '  Calibrate  ' UnComment this and run when the CO2 level is at 400ppm
    
      repeat
        waitcnt(cnt + clkfreq) ' Wait one second
    
        ' Clear receive buffer
        repeat while K30.RxCount > 0
          K30.CharIn
     
       ' Send request for Co2 measurement
        K30.char($FE)
        K30.char($04)
        K30.char($00)
        K30.char($03)
        K30.char($00)
        K30.char($01)
        K30.char($D5)
        K30.char($C5)
      
        waitcnt(cnt + clkfreq) ' Wait one second
    
        ' Recieve packet
        if K30.charIn == 254
          if K30.charIn == 4
            if K30.charIn == 2
              value := K30.charIn * 256
              value += K30.charIn
    
              term.dec(value)
              term.str(string(" ppM     ", 13))
    
        
    PUB Calibrate
      waitcnt(cnt + clkfreq)
      repeat while K30.RxCount > 0
        K30.CharIn
    
      K30.Char($FE)
      K30.Char($06)
      K30.Char($00)
      K30.Char($00)
      K30.Char($00)
      K30.Char($00)
      K30.Char($9D)
      K30.Char($C5)
    
      waitcnt(cnt + clkfreq)
    
      repeat while K30.RxCount > 0
        term.hex(K30.CharIn, 2)
      term.char(13)
    
    
      K30.Char($FE)
      K30.Char($06)
      K30.Char($00)
      K30.Char($01)
      K30.Char($7C)
      K30.Char($06)
      K30.Char($6C)
      K30.Char($C7)
    
      waitcnt(cnt + clkfreq)
    
      repeat while K30.RxCount > 0
        term.hex(K30.CharIn, 2)
      term.char(13)
    
      waitcnt(cnt + clkfreq*5)
    
      K30.Char($FE)
      K30.Char($03)
      K30.Char($00)
      K30.Char($00)
      K30.Char($00)
      K30.Char($01)
      K30.Char($90)
      K30.Char($05)
    
      waitcnt(cnt + clkfreq)
    
      repeat while K30.RxCount > 0
        term.hex(K30.CharIn, 2)
      term.char(13)
    
      term.str(string(13, "Calibration Completed...", 13))
    
    

    I hope this helps,
    Bean
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-12-27 06:39
    Thanks allot for the piece of code , im going to try it out right away

    the serial interface rather than the i2c , do you mean the uart connections ???
    and are there pull up requierd like with the i2c bus ?

    K30.char($FE) stop ??
    K30.char($04)
    K30.char($00)
    K30.char($03)
    K30.char($00)
    K30.char($01)
    K30.char($D5) adres ?
    K30.char($C5) start ??

    did you use a different adres from the factory default one
  • BeanBean Posts: 8,129
    edited 2012-12-27 06:54
    No pullup. But I did put 1K in series with both just in case I connected them backwards.

    I'm not at work today, but I think they are the UART connections (RxD and TxD I think).

    I'm pretty sure I just used the factory default address.

    My sensor was WAY off before I did the calibration.

    Good luck.
    Bean
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-12-27 07:38
    am using the code you supplied but the sensor doesnt seem to be responding at all .

    care to explaine where the folowing values come from , cause I cant realy relate them from the datasheet that I got

    ok found it discribed in the mobus protocol sheet of it , but still cant seem to get any usefull data out of it

    where is the start and stop bit ?
    dont I need to wake the sensor up before ?
    ' Send request for Co2 measurement
        K30.char($FE)
        K30.char($04)
        K30.char($00)
        K30.char($03)
        K30.char($00)
        K30.char($01)
        K30.char($D5)
        K30.char($C5)
    

    another question , I have the sensor powerd tru g0 and g+ feeding it 6 volts .
    the prop and everything else runs off 3.3v. and like i see the sensor core also runs at 3.3 volts.
    is is possible to connect it to 3,3 volt ( mayme the DVCC) to let it work on 3.3 volt . saving me to have to use the 6 volt regulator and some caps exclusivly for the sensor
    thnx
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-12-28 15:00
    @ Bean

    I have got it working,

    Turned out , I was using 2 power supplies ,
    1 for the propeller , 3.3 volts,
    and a different one for the 6 volts that I feed the sensor with , But I forgot to connect both grounds to each other ,

    now its working fine , My sensor looks to be pretty accurate without doing the calibration ,

    So thanks allot for the example. Ill be further incorporating the sensor into my project
  • Erik FriesenErik Friesen Posts: 1,071
    edited 2012-12-29 06:27
    One note on these self calibrating sensors, indoor calibrations are not to be trusted in my opinion. I have access to calibration gasses, and find that my indoors run around at least 1500ppm all the time, and at times higher than 3000 with a house full of people. Self calibration in this type of environment would be showing 400ppm when in reality it would be more than triple. My suggestion is to calibrate manually outdoors, every six months, and it would be much more accurate than self calibration in my opinion. The NDIR sensors I have in hand don't drift more than 10% that I can see.
  • BeanBean Posts: 8,129
    edited 2012-12-29 07:13
    Igor_Rast wrote: »
    @ Bean

    I have got it working,

    Turned out , I was using 2 power supplies ,
    1 for the propeller , 3.3 volts,
    and a different one for the 6 volts that I feed the sensor with , But I forgot to connect both grounds to each other ,

    now its working fine , My sensor looks to be pretty accurate without doing the calibration ,

    So thanks allot for the example. Ill be further incorporating the sensor into my project

    You are welcome, I'm glad you got it working. Let us know how your project works out.

    Bean
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-12-29 07:52
    @Erik

    That,s exactly what I had in mind about how the calibration inside a room will effect the reading . In fact I im trying not to have to callibrate it at all.
    I have a second co2 sensor ( picture ) that I use *** a reference to the reading that im getting from the k-30 sensor. and till now the reading does look pretty solid and accurate.
    2012-12-29 16.40.25.jpg

    the 2 different sensor have a difference of about max 100 ppm at times , no difference at all . iff i leave the room and let the window open. to get the cleanes air posible I
    end up reading about 430 ppm on both sensors .
    So if you ask me , The sensor precalibrated that they claim it to be from factory , is pretty accurate . and doesnt need to be recalibrated to be used the first time ,

    about the calibration after 6 months , is this really necessary ? Do you have experience to see the reading drift off in 6 moths time . I was hoping the auto ABC feature would allow me to never have to calibrate at all. Or is it that because in your case the sensor enviroment is usualy around 1500 ppm. meaning the sensor ABC function wil drift the 400 ppm mark towards the 1500 ppm . leading to the reading beeing off. ?

    @Bean .
    Your welcome ,
    I was thinking about doing a small Video demo of the sensor attached at the prop .
    Ill be posting it later on I think . have to figure out how still :p
    1024 x 768 - 66K
  • Erik FriesenErik Friesen Posts: 1,071
    edited 2012-12-29 08:18
    Well, there is no getting around some calibration, unless long term drift is within specs. I don't have a good idea what long term is, I suspect it is within 10% though. What I am saying, is that unless you know your air is clean, it is better to turn of the self calibration feature. IMO.
  • Igor_RastIgor_Rast Posts: 357
    edited 2012-12-31 05:27
    @ Bean . I gave it my best shot trying to make a small demo , Hope you like it .

    left the room for a half hour to let the readings of both sensor stabilaze, that worked out pretty nice .
    and excuse my bad english :smile:
    tips are always welcome
  • Hi Guys I wanted to buy the k30 co2 sensor for my college project, I need a little bit help do I need to buy the pump ie extra accessories along with it or it just work without the pump also. And gives proper reading. Guys help me out Plz
    Waiting for your reply
  • hi ,
    Yes the K-30 module is all you need, no need for the pump
    connect it via the Rx TX lines and you can read out the CO2 value

    ICEC
Sign In or Register to comment.