Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

hi. i made rc car by using rispberry pi. so it can move while it plug in pi. But i want move it with wireless.

hi. i made rc car by using rispberry pi. so it can move while it plug in pi. But i want move it with wireless. so i conneted into Pi by using putty on laptop. But when i tried to run it, get some error like this

"Traceback (most recent call last): File "robot3.py", line 81, in comman = ti.Tk() File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1813, in __init__ self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) _tkinter.TclError: no display name and no $DISPLAY environment variable"

And here is my code

import RPi.GPIO as gpio import time

import Tkinter as ti

def init(): gpio.setmode(gpio.BOARD) gpio.setup(7, gpio.OUT) gpio.setup(11, gpio.OUT) gpio.setup(13, gpio.OUT) gpio.setup(15, gpio.OUT)

def forward(tf): gpio.output(7, False) gpio.output(11, True) gpio.output(13, True) gpio.output(15, False) time.sleep(tf) gpio.cleanup()

def reverse(tf): gpio.output(7, True) gpio.output(11, False) gpio.output(13, False) gpio.output(15, True) time.sleep(tf) gpio.cleanup()

def turn_left(tf): gpio.output(7, True) gpio.output(11, True) gpio.output(13, True) gpio.output(15, False) time.sleep(tf) gpio.cleanup()

def pivot_right(tf): gpio.output(7, False) gpio.output(11, True) gpio.output(13, False) gpio.output(15, True) time.sleep(tf) gpio.cleanup()

def key_input(event): init() print 'key:', event.char key_press = event.char sleep_time = 0.030

if key_press.lower() == 'w': forward(sleep_time) elif key_press.lower() == 's':

reverse(sleep_time) elif key_press.lower() == 'a': turn_left(sleep_time) elif key_press.lower() == 'd': turn_right(sleep_time) elif key_press.lower() == 'q': pivot_left(sleep_time) elif key_press.lower() == 'e': pivot_right(sleep_time)

comman = ti.Tk() comman.bind('', key_input) comman.mainloop()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Information Modeling And Relational Databases

Authors: Terry Halpin, Tony Morgan

2nd Edition

0123735688, 978-0123735683

More Books

Students also viewed these Databases questions

Question

Define net income and explain its computation.

Answered: 1 week ago