How to Make Raspberry pi Robot
How to Make Raspberry pi Robot
In this tutorial, we will learn how to control a tank robot remotely and wirelessly with Raspberry Pi. We will remotely connect to the robot via VNC. This is a great tutorial for beginners to Raspberry Pi. This tutorial will show you how to use the L298N Motor driver, DC motor control, GPIO pins, remote access and wireless motor control with Raspberry Pi. We will control the tank or robot from the computer, keyboard, smartphone and keypad using the curses library.
Get Started with Raspberry Pi (Installing Raspbian)
https://youtu.be/x0Xh21nilUg
How to access the raspberry pi via internet
https://youtu.be/IpKRfwVH1Ko
Product
1 Raspberry pi http://amzn.in/dnl7orF
2 Robot chassis http://amzn.in/ffYwtYO
To install the NCurses library on a Debian based machine you can issue the
apt-get
command below:sudo apt-get install libncurses5-dev libncursesw5-dev
Code :)
import curses import RPi.GPIO as GPIO GPIO.setwarnings(False) #set GPIO numbering mode and define output pins GPIO.setmode(GPIO.BOARD) motor1a = 7 motor1b = 11 motor1e = 22 motor2a = 13 motor2b = 16 motor2e = 15 GPIO.setup(motor1a,GPIO.OUT) GPIO.setup(motor1b,GPIO.OUT) GPIO.setup(motor1e,GPIO.OUT) GPIO.setup(motor2a,GPIO.OUT) GPIO.setup(motor2b,GPIO.OUT) GPIO.setup(motor2e,GPIO.OUT) # Get the curses window, turn off echoing of keyboard to screen, turn on # instant (no waiting) key response, and use special values for cursor keys screen = curses.initscr() curses.noecho() curses.cbreak() curses.halfdelay(3) screen.keypad(True) try: while True: char = screen.getch() if char == ord('q'): break elif char == curses.KEY_UP: GPIO.output(motor1a,GPIO.HIGH) GPIO.output(motor1b,GPIO.LOW) GPIO.output(motor1e,GPIO.HIGH) GPIO.output(motor2a,GPIO.HIGH) GPIO.output(motor2b,GPIO.LOW) GPIO.output(motor2e,GPIO.HIGH) elif char == curses.KEY_DOWN: GPIO.output(motor1a,GPIO.LOW) GPIO.output(motor1b,GPIO.HIGH) GPIO.output(motor1e,GPIO.HIGH) GPIO.output(motor2a,GPIO.LOW) GPIO.output(motor2b,GPIO.HIGH) GPIO.output(motor2e,GPIO.HIGH) elif char == curses.KEY_RIGHT: GPIO.output(motor1a,GPIO.HIGH) GPIO.output(motor1b,GPIO.LOW) GPIO.output(motor1e,GPIO.HIGH) GPIO.output(motor2a,GPIO.LOW) GPIO.output(motor2b,GPIO.HIGH) GPIO.output(motor2e,GPIO.HIGH) elif char == curses.KEY_LEFT: GPIO.output(motor1a,GPIO.LOW) GPIO.output(motor1b,GPIO.HIGH) GPIO.output(motor1e,GPIO.HIGH) GPIO.output(motor2a,GPIO.HIGH) GPIO.output(motor2b,GPIO.LOW) GPIO.output(motor2e,GPIO.HIGH) elif char == 10: GPIO.output(motor1a,GPIO.LOW) GPIO.output(motor1b,GPIO.LOW) GPIO.output(motor1e,GPIO.LOW) GPIO.output(motor2a,GPIO.LOW) GPIO.output(motor2b,GPIO.LOW) GPIO.output(motor2e,GPIO.LOW) finally: #Close down curses properly, inc turn echo back on! curses.nocbreak(); screen.keypad(0); curses.echo() curses.endwin() GPIO.cleanup()
Comments
Post a Comment