[Request] k30 Series CO2 meter library


#1

Is anyone able to convert this lib, or is it able to be converted at all? It uses SoftwareSerial, I would imagine that has already been ported to the Spark? I am willing to donate some $$ if it is a lot of work, I want to be able to use my sensor on my Spark!

http://www.co2meters.com/Documentation/AppNotes/AN126-K3x-sensor-arduino-uart.zip

Thanks,

Joe


#2

@jboswell, this does not look too difficult. I’ll give it a try


#3

@jboswell, SoftwareSerial is not necessary on the Core (and won’t work either) since there are two extra serial ports you can use (Serial1, 2). Porting the code looks quite easy once you get past the SoftwareSerial stuff. I’ll have it for you in the morning. :smile:


#4

Not one but two distinguished gentlemen! Please let me know if I can reimburse one or both of you fine fellows!

J


#5

@jboswell, I posted the ported library as a gist here. The library is written to work with Arduino and Spark though Spark does not use SoftwareSerial. When compiling for the Spark, you cannot specifiy the RX and TX lines used since I specified the Spark’s hardware serial port Serial1 to be used. You can change that to Serial2 by editing line 28 of KSeries.cpp.

The K30_basic.ino example in the original code did not even use the library! So I modified it to create a KSeries object and call its measurement methods. It is untested but should work.

Keep me posted on your results! :smile:


#6

I will try it asap! Thank you!


#7

@jboswell, if everything works then all I ask is that you make a generous donation to a local food bank or soup kitchen :blush:


#8

Ok, finally got to testing!

I had to get up to speed a bit and tried a lot of different things. Here’s the rundown:

Weirdness.

Basically I started out swapping it over to Serial2 just so I could output to Serial1 while it was on the bench. Initially it worked but gave incorrect values (2050 exactly) so at first I assumed maybe the sensor was bad.

Then I decided to move it back to all defaults and check to see if things would be better or worse or the same (to confirm sensor deadness). At that point when I uploaded it to the core it just kept flashing red immediately after the firmware updated (single blink followed by, I think, 9 or 10 very quick blinks). So I messed around on that route for like 2 or 3 hours, to no avail, pretty much dead core if I tried to use Serial1…

Or so I thought. Towards the end of the night I decided to try a few last things, one thing it turns out that I was doing wrong was isolating the ground from the power that runs the sensor (even though I thought I read their datasheet and it was supposed to be able to use 3.3v it only seems to light up on 5v). Fixed that issue and magic happened, I started getting readings that changed when I blew on the sensor! Yay!

At that point I called it a night.

Walk in today to have a look at it, everything is still running great (really good sign) but I realized that I am using Serial1 (explicitly) but the sensor itself is actually plugged into the Serial2 pins D0 and D1!!! What. the. hell?

So at this point, I am confused, but still happy. It works, and I don’t know WHY it works, but it totally does and it’s weird. I haven’t even enabled Serial2 in the firmware which is even weirder. The only change to the code seems to be that instead of:

Serial.begin(9600);

In the ino, I explicitly use:

Serial1.begin(9600);

That is the difference between dead core and alive core with working sensor. Very, very much weird. That being said, it is usable, so I am making that donation now! Thank you so much!


#9

Small update.

I was looking at older code apparently… It uses Serial2 when serial 2 is all properly defined and it’s changed (like you mentioned) in the .cpp file as well as in the ino.

Other than Serial2 though, I couldn’t get this thing to work, so really as long as you use Serial2 this thing is fine and pretty damn stable.

J