Omkars Tech Blog
Published

Monday December 18, 2017

←Home

Raspberry Pi Zero WiFi Car

Raspberry pi car platform

This project in its current form is a raspberry pi zero based wifi car platform. Although this platform can be expanded into futher projects involving autonomus operation, image recognition this platform currently can be used as a simple keyboard operated car connected over WiFi.

Parts

  • Raspberry Pi Zero
  • 4 Motor Chasis like this LINK
  • Motor Driver LINK
  • 2x18650 cells with holder
  • Assorted mounting headers
  • Wifi dongle (not Req in case of Rpi0 W)

Assembling the chasis. Although i did not end up using these two motor drivers Pelican Almost Done Pelican

2 x 18650 cells with battery holder installed

Pelican


Once you login to your Rpi0 via SSH clone the below code and run it in the terminal

GitHub Link

#!/usr/bin/python3
import curses 
from curses import wrapper
from gpiozero import LED
from time import sleep


motor1F = LED(23) # pin 16 on rpi0
motor2F = LED(24) # pin 18
motor1R = LED(27) # pin 13
motor2R = LED(17) # pin 11

def Forward():
    motor1F.on()
    motor2R.on()
    sleep(0.1)
    motor1F.off()
    motor2R.off()
    sleep(0)

def Back():
    motor2F.on()
    motor1R.on()
    sleep(0.1)
    motor2F.off()
    motor1R.off()
    sleep(0)

def Clockwise():
    motor1F.on()
    motor1R.on()
    sleep(0.1)
    motor1F.off()
    motor1R.off()
    sleep(0)

def Anticlockwise():
    motor2F.on()
    motor2R.on()
    sleep(0.1)
    motor2F.off()
    motor2R.off()
    sleep(0)    


screen = curses.initscr()

curses.noecho()
curses.cbreak()

screen.keypad(True)

screen.addstr("Hello World!!!")
screen.addstr("PRESS THE ARROW KEYS TO MOVE THE CAR")
while True:
    c = screen.getch()
    if c == curses.KEY_LEFT:
        screen.addstr(5,10, 'left key pressed')
        Anticlockwise()
        screen.refresh()
    elif c == curses.KEY_RIGHT:
        screen.addstr(5,50, 'right key pressed')
        Clockwise()
        screen.refresh()
    elif c == curses.KEY_UP:
        screen.addstr(2,30,'UP key pressed')
        Forward()
        screen.refresh()
    elif c == curses.KEY_DOWN:
        screen.addstr(9,30,'Down key pressed')
        Back()
        screen.refresh()


curses.nobreak()
screen.keypad(False) # Enable keypad Mode
curses.echo()
curses.endwin()
Go Top