I'm just about to start with the pi universe.
This is my first post. I hope i am asking in a accepted way.
I do have 15 years experience on linux, but not a lot in scripting/programming.
I am not at all savvy in electrical engineering.
I have a Pi Zero WH Rev. 1.1 and connected a RPi Motor Driver Board on top through the 40pin header.
I do power it through a 12V Power Adapter from an old QNAP TS209 that goes into VIN and GND on the Motor Driver Board. The Motor Driver Board powers the piz zero (through the header) and two 12V DC motors. AFAIK the motor board can do that ( Onboard 5V regulator, provides power to Raspberry Pi
There is a IR receiver on the motor board too, although i do not know which one exactly (TSOP etc.).
I have installed Raspian Lite Buster from July (this might be a source of the problem, as I do not know how the development state is for IR, Pi Zero etc. on Debian Buster)
I want to use my IR Remote to control the motors with python (but IMPORTANT:without LIRC) and i have succeeded to do so using the waveshare's example code for that HAT board.
But it seems as if only about 10% of all key-presses (scancodes) are captured by the python code. The rest is ignored. Often i can't stop the motors after one of several key-presses has started the motor(s).
If run my pre-configured ir-keytable -t I do receive a scancode for all key-presses using different remotes (NEC with Terratec Cinergy, RC-5 with Hauppauge remote, NEC with a Yamaha HiFi remote).
But when i am running the motor.py code it only captures NEC type scancodes and only about 10% of the key-presses are executed through the code.
This is the ir remote python script ( motor.py) from Waveshare demo code files i am using
What I find strange is that they already take away some parts of the scancode and only using the last bits. But I think this is not the source of the problems i am facing.
How can i test/modify the script in order to fix this?
Code: Select all
import RPi.GPIO as GPIO import time PIN = 18 PWMA1 = 6 PWMA2 = 13 PWMB1 = 20 PWMB2 = 21 D1 = 12 D2 = 26 PWM = 50 GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(PIN,GPIO.IN,GPIO.PUD_UP) GPIO.setup(PWMA1,GPIO.OUT) GPIO.setup(PWMA2,GPIO.OUT) GPIO.setup(PWMB1,GPIO.OUT) GPIO.setup(PWMB2,GPIO.OUT) GPIO.setup(D1,GPIO.OUT) GPIO.setup(D2,GPIO.OUT) p1 = GPIO.PWM(D1,500) p2 = GPIO.PWM(D2,500) p1.start(50) p2.start(50) def set_motor(A1,A2,B1,B2): GPIO.output(PWMA1,A1) GPIO.output(PWMA2,A2) GPIO.output(PWMB1,B1) GPIO.output(PWMB2,B2) def forward(): GPIO.output(PWMA1,1) GPIO.output(PWMA2,0) GPIO.output(PWMB1,1) GPIO.output(PWMB2,0) def stop(): set_motor(0,0,0,0) def reverse(): set_motor(0,1,0,1) def left(): set_motor(1,0,0,0) def right(): set_motor(0,0,1,0) def getkey(): if GPIO.input(PIN) == 0: count = 0 while GPIO.input(PIN) == 0 and count < 200: #9ms count += 1 time.sleep(0.00006) count = 0 while GPIO.input(PIN) == 1 and count < 80: #4.5ms count += 1 time.sleep(0.00006) idx = 0 cnt = 0 data = [0,0,0,0] for i in range(0,32): count = 0 while GPIO.input(PIN) == 0 and count < 15: #0.56ms count += 1 time.sleep(0.00006) count = 0 while GPIO.input(PIN) == 1 and count < 40: #0: 0.56ms count += 1 #1: 1.69ms time.sleep(0.00006) if count > 8: data[idx] |= 1<<cnt if cnt == 7: cnt = 0 idx += 1 else: cnt += 1 if data+data == 0xFF and data+data == 0xFF: #check return data print('IRM Test Start ...') stop() try: while True: key = getkey() if(key != None): print("Get the key: 0x%02x" %key) if key == 0x18: forward() print("forward") if key == 0x08: left() print("left") if key == 0x1c: stop() print("stop") if key == 0x5a: right() print("right") if key == 0x52: reverse() print("reverse") if key == 0x15: if(PWM + 10 < 101): PWM = PWM + 10 p1.ChangeDutyCycle(PWM) p2.ChangeDutyCycle(PWM) print(PWM) if key == 0x07: if(PWM - 10 > -1): PWM = PWM - 10 p1.ChangeDutyCycle(PWM) p2.ChangeDutyCycle(PWM) print(PWM) except KeyboardInterrupt: GPIO.cleanup();
Important side information: I have manually recompiled WebIOPi (otherwise buster issues again) and can control all python functions as used in the IR script without any delay or problems. With WebIOPi it just works.