Frambuesa Pi Control remoto juguete coche
Hardware:
1. Frambuesa Pi B + o superior
2. (4) 2N3904 NPN (EBC) Q6
3. (8) resistentes a la de 10 K
4. (4) resistentes a la de 1 K
5 (4) llevó la luz (cualquier Color)
¿Cómo hacer?
Ver arriba fotos
Conectar PIN
Frambuesa Pi--Circuito--control remoto de Control
GPIO 17--circuito A--a la izquierda
GPIO 27--circuito B--derecho
GPIO 22--circuito C--hacia adelante
GPIO 23--circuito D--hacia atrás
Prueba simple Python
Esta prueba simple es el control GPIO 4 encendido y apagado, tienes que conectar al Pin adelante en juguete coche remoto antes de ejecutar
$ sudo nano simpletest.py
<pre><p><strong>import</strong> time</p><p><strong>import</strong> RPi.GPIO <strong>as</strong> io</p><p>io.setmode(io.BOARD)</p><p>pir_pin = 7</p><p>io.setup(pir_pin, io.OUT)</p><p><strong>while</strong> True:</p><p> io.output(pir_pin, io.HIGH)</p><p> <strong>print</strong>(<strong>"Forward On"</strong>)</p><p> time.sleep(3)</p><p> io.output(pir_pin, io.LOW)</p><p> <strong>print</strong>(<strong>"Forward OFF"</strong>)</p><p> time.sleep(3)</p>
Script completo
$sudo nano toycarremote.py
<p>import time <br>import RPi.GPIO as gpio </p><p>class ToyCarRemote: def __init__(self, forward_pin=11, backward_pin=13, left_pin=15, right_pin=16, test_pin=7): #gpio.setmode(gpio.BCM) #test_pin = 4 # GPIO 4 #forward_pin = 17 # (GPIO 17) #backward_pin = 27 # GPIO 27 #left_pin = 22 # GPIO 22 #right_pin = 23 # GPIO 24</p><p> self.test_pin=test_pin self.forward_pin=forward_pin self.backward_pin=backward_pin self.left_pin=left_pin self.right_pin=right_pin</p><p> gpio.setmode(gpio.BOARD) test_pin = 7 # GPIO 4 forward_pin = 11 # (GPIO 17) backward_pin = 13 # GPIO 27 left_pin = 15 # GPIO 22 right_pin = 16 # GPIO 23</p><p> gpio.setup(self.test_pin, gpio.OUT) gpio.setup(self.forward_pin, gpio.OUT) gpio.setup(self.backward_pin, gpio.OUT) gpio.setup(self.left_pin, gpio.OUT) gpio.setup(self.right_pin, gpio.OUT)</p><p> gpio.output(self.forward_pin, gpio.LOW) gpio.output(self.backward_pin, gpio.LOW) gpio.output(self.left_pin, gpio.LOW) gpio.output(self.right_pin, gpio.LOW) </p><p> def clearAll(self): gpio.output(self.forward_pin, gpio.LOW) gpio.output(self.backward_pin, gpio.LOW) gpio.output(self.left_pin, gpio.LOW) gpio.output(self.right_pin, gpio.LOW) </p><p> def updown(self, direction, OnOff, tsecond): # direction F:forward , B:Backward if direction in ('F'): gpio.output(self.backward_pin, gpio.LOW) gpio.output(self.forward_pin, OnOff) if direction in ('B'): gpio.output(self.forward_pin, gpio.LOW) gpio.output(self.backward_pin, OnOff) time.sleep(tsecond)</p><p> def leftright(self, direction, OnOff, tsecond): # direction L:left , R:Right if direction in ('L'): gpio.output(self.right_pin, gpio.LOW) gpio.output(self.left_pin, OnOff) if direction in ('R'): gpio.output(self.left_pin, gpio.LOW) gpio.output(self.right_pin, OnOff) time.sleep(tsecond)</p><p>#try: # while True: # gpio.output(test_pin, gpio.HIGH) # #except KeyboardInterrupt: # gpio.cleanup()</p><p>if __name__ == '__main__': tcr = ToyCarRemote() for i in range(20): print('\n', 'Loop : ', i) print 'Forward 2 Second' tcr.updown('F', gpio.HIGH , 0) tcr.leftright('L', gpio.HIGH, 0) time.sleep(2) tcr.clearAll() print 'Stop Forward' tcr.updown('B', gpio.HIGH, 0) time.sleep(2) tcr.clearAll()</p>
Más información: iMediaBank - http://www.imediabank.com