Sensair CO2 Sensor - Raspberry Pi Forums


hello

i'm using following code read co2 senseair s8 sensor serial port of pi3:

code: select all

import serial import time #rpi pin connections: #pin 6 gnd #pin 4 5v #pin 8 txd: uart data s8 #pin 10 rxd: uart data s8 ser = serial.serial("/dev/ttyama0",baudrate =9600,timeout = .5) print " an-137: raspberry pi3 k-30 via uart\n" ser.flushinput() time.sleep(1) in range(1,21): # print 20 readings sensor         ser.flushinput()         ser.write("0xfe,0x44,0x00,0x08,0x02,0x9f,0x25")         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)
unfortunately i'm getting error regarding ord() function.

error states ord(resp[3]) string index out of range: image

quetion if i'm reading data 7 character of string using ser.read(7) how can index 3 out of range.

when i'm not indexing sensor , trying print data as:

code: select all

print(resp)
i'm getting: b' '

please how proceed this!

so "resp = ser.read(7)" timing out before receives 7 bytes. add line "print len(resp)" after read can see how many bytes have been read. u may need increase time out


raspberrypi



Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'