diff --git a/code/piplayer2.py b/code/piplayer2.py index 9fc233c..edcc3f9 100644 --- a/code/piplayer2.py +++ b/code/piplayer2.py @@ -75,7 +75,7 @@ try: logging.debug('Photo sensor active, activating light and camera') subprocess.call(["mocp", "-l", SOUND_SCANNING]) - # turn LED onGPIO.wait_for_edge(23, GPIO.FALLING) + # turn LED on GPIO.output(27, GPIO.HIGH) # scan QR code diff --git a/code/test/qrtest.py b/code/test/qrtest.py new file mode 100644 index 0000000..f5aa4c6 --- /dev/null +++ b/code/test/qrtest.py @@ -0,0 +1,51 @@ +import RPi.GPIO as GPIO +import time +import subprocess +import select # see http://stackoverflow.com/a/10759061/3761783 + +QR_SCANNER_TIMEOUT = 3 + + +# photo sensor on PIN 17 +GPIO.setmode(GPIO.BCM) +GPIO.setup(17, GPIO.IN) + +# LED on PIN 27 +GPIO.setup(27, GPIO.OUT) +GPIO.output(27, GPIO.LOW) + +try: + print('Start QR scan test') + + while True: + time.sleep(0.25) + if (GPIO.input(17) == GPIO.LOW): + #print('LOW') + GPIO.output(27, GPIO.LOW) + else: + print('Sensor active') + GPIO.output(27, GPIO.HIGH) + zbarcam = subprocess.Popen(['zbarcam', '--quiet', '--nodisplay', '--raw', '-Sdisable', '-Sqrcode.enable', '--prescale=320x240', '/dev/video0'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + poll_obj = select.poll() + poll_obj.register(zbarcam.stdout, select.POLLIN) + + # wait for scan result (or timeout) + start_time = time.time() + poll_result = False + while ((time.time() - start_time) < QR_SCANNER_TIMEOUT and (not poll_result)): + poll_result = poll_obj.poll(100) + + if (poll_result): + qr_code = zbarcam.stdout.readline().rstrip() + qr_code = qr_code.decode("utf-8") # python3 + print("QR Code: {}".format(qr_code)) + else: + print('Timeout on zbarcam') + + zbarcam.terminate() + GPIO.output(27, GPIO.LOW) + + +except KeyboardInterrupt: + print('bye') + GPIO.cleanup() diff --git a/installation.txt b/installation.txt index 8b1c616..6d784a2 100644 --- a/installation.txt +++ b/installation.txt @@ -61,6 +61,11 @@ python3 lighton.py sudo fswebcam -r 320x240 -d /dev/video0 -v ~/test.jpg python3 lightoff.py +# QR-Test +python3 lighton.py +zbarcam --quiet --nodisplay --raw -Sdisable -Sqrcode.enable --prescale=320x240 /dev/video0 +python3 lightoff.py + # enable lirc in /boot/config.txt and add parameters sudo nano /boot/config.txt