This is my first pi project so im a bit new at this. Im trying to connect a senseair K-30 CO2 sensor to the pi via the UART gpio pins. This is the sensor I am using: https://www.co2meter.com/products/k-30-co2-sensor-module
and I set it up following the app note here: http://www.co2meters.com/Documentation/AppNotes/AN137-K30-sensor-raspberry-pi-uart.pdf
However, the co2 measurements show up as 0ppm even if I breathe on the sensor membrane so my thoughts are that the Tx and Rx pins are not reading anything from the sensor.
What I've done so far:
- Went into raspi-config
and under interfacing options, changed "Would you like a login shell to be accessible over serial?" to "No" and "Would you like the serial port hardware to be enabled" to "Yes"
- Added the line enable_uart=1
to the /boot/config.txt
file.
- Deleted the line console=/dev/ttyS0,115200
in the /boot/cmdline.txt
file.
- Did both systemctl stop serial-getty@ttyS0.service
and systemctl disable serial-getty@ttyS0.service
- I also had to change some permissions in order for me to be able to use ttyS0, I added the user to the groups dialout, tty and uucp.
- I tried checking the pins by making a feedback loop and using minicom or screen to check if they are reading properly but im unsure of how to use either of them so it did not help
Any pointers on how to short the Tx and Rx pins together and use minicom to see if they're working? Are there other permissions I need to change in order to use the serial pins to communicate with the sensor? It stopped giving me the error saying permissions denied but possibly it can read but not write or execute? Im a little confused and any help would be much appreciated!
Here is the code that the sensor uses:
#rpi serial connections
#Python app to run a K-30 Sensor
import serial
import time
ser = serial.Serial("/dev/ttyS0",baudrate =9600,timeout = .5)
print " AN-137: Raspberry Pi3 to K-30 Via UART\n"
ser.flushInput()
time.sleep(1)
for i in range(1,21):
ser.flushInput()
ser.write("\xFE\x44\x00\x08\x02\x9F\x25")
time.sleep(.5)
resp = ser.read(7)
high = ord(resp[3])
low = ord(resp[4])
co2 = (high*256) + low
print "i = ",i, " CO2 = " +str(co2)
time.sleep(.1)
And the output:
AN- 137: Raspberry Pi3 to K-30 via UART
i = 1 CO2 = 0
i = 2 CO2 = 0
i = 3 CO2 = 0
i = 4 CO2 = 0
i = 5 CO2 = 0
i = 6 CO2 = 0
i = 7 CO2 = 0
i = 8 CO2 = 0
i = 9 CO2 = 0
i = 10 CO2 = 0
i = 11 CO2 = 0
i = 12 CO2 = 0
i = 13 CO2 = 0
i = 14 CO2 = 0
i = 15 CO2 = 0
i = 16 CO2 = 0
i = 17 CO2 = 0
i = 18 CO2 = 0
i = 19 CO2 = 0
i = 20 CO2 = 0