Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion NDIR_RasPi_Python/NDIR.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class Sensor():
cmd_measure = [0xFF,0x01,0x9C,0x00,0x00,0x00,0x00,0x00,0x63]
ppm = 0

IODIR = 0X0A << 3
IOSTATE = 0X0B << 3
IOCONTROL = 0X0E << 3
FCR = 0X02 << 3
LCR = 0X03 << 3
Expand Down Expand Up @@ -46,7 +48,7 @@ def measure(self):
try:
self.write_register(self.FCR, 0x07)
self.send(self.cmd_measure)
time.sleep(0.01)
time.sleep(0.02)
self.parse(self.receive())
return True
except IOError:
Expand Down Expand Up @@ -96,3 +98,15 @@ def receive(self):
break

return buf

def power_on(self):
state = self.read_register(self.IOSTATE)
state |= 1
self.write_register(self.IOSTATE, state)

def power_off(self):
self.write_register(self.IODIR, 0x03)
state = self.read_register(self.IOSTATE)
state &= ~1
self.write_register(self.IOSTATE, state)

12 changes: 10 additions & 2 deletions NDIR_RasPi_Python/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@
if sensor.begin() == False:
print("Adaptor initialization FAILED!")
exit()

while True:
sensor.power_on()
print("Power On")
i = 0
while i < 50:
if i == 25:
sensor.power_off()
print("Power Off")
sensor.ppm = -1
if sensor.measure():
print("CO2 Concentration: " + str(sensor.ppm) + "ppm")
else:
print("Sensor communication ERROR.")

time.sleep(1)
i += 1