Raspberry pi Zero で オフィス環境の可視化 その2
K30 CO2 Sensor SENSEAIR
UART でつなぎます。
$ pip install pyserial $ sudo systemctl stop serial-getty@ttyAMA0.service
コーディング
前回の使い回し。
#!/usr/bin/env python # -*- coding: utf-8 -*- import serial import time ser = serial.Serial("/dev/ttyAMA0") #print "Serial Connected!" ser.flushInput() #time.sleep(0.5) while True: ser.write("\xFE\x44\x00\x08\x02\x9F\x25") time.sleep(0.01) resp = ser.read(7) high = ord(resp[3]) low = ord(resp[4]) co2 = (high*256) + low if co2 > 1: print(str(co2)) time.sleep(5)
音絡み
sudo apt-get install python-alsaaudio
cat /proc/asound/modules
/etc/modprobe.d/alsa-base.conf で、 options snd-usb-audio index=0にしてあげる。