Roo_027
Posts: 32
Joined: Wed Jan 10, 2018 10:10 am

Pynput - RC Car and Motors

Sat Jan 20, 2018 6:52 pm

Good evening everyone

I have finished building the body for my RC Car and have attached the 2 motors, battery pack, the raspberry pi, motor board and ultrasonic distance detector.

About 10 days or so ago I requested help with which GPIO pin numbers to assign to the motor terminals - the code for that I have adjusted and the wheels turn fine when I write predetermined seconds for them to turn.

Now I would like to be able to control the movement of the car from my PC keyboard through the WiFi at home - I understand you can do this using Putty which I have installed and will look at later. Right now I would like to know if I can use the Python module "Pynput" to tell the vehicle to move in all directions based on "WASD" keys.

I have tried downloading and installing "Pynput" but when I started writing the code in Python:

from pynput import Key, Controller

I got the following error:

"from pynput import Key, Controller
ImportError: No module named pynput"

I tried downloading/installing the module using the terminal but it is not working. I tried:

"sudo pip install python-pynput"
"sudo apt-get install python-pynput"

Neither of these works. Has anyone used this module in the past for such a project? I know pygame also has the ability to read what key the person has pressed but I am not sure that makes sense to use here.

Thank you in advance!

pcmanbob
Posts: 3674
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Pynput - RC Car and Motors

Sat Jan 20, 2018 9:20 pm

You look to have installed python-pynput for python 2, are you running you program using python3 by any chance.
Please only ask questions in the forum I will not answer questions sent to me directly via PM
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

Roo_027
Posts: 32
Joined: Wed Jan 10, 2018 10:10 am

Re: Pynput - RC Car and Motors

Sun Jan 21, 2018 8:59 am

Hi there

Yes I am using Python 2.

pcmanbob
Posts: 3674
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Pynput - RC Car and Motors

Sun Jan 21, 2018 11:58 am

Looking at the these docs for pynput I think you have you import line wrong.

https://pythonhosted.org/pynput/keyboard.html

from pynput.keyboard import Key, Controller

from pynput.keyboard import Key, Listener

are 2 of the options.

you will have to read the docs to decide which you need to use.
Please only ask questions in the forum I will not answer questions sent to me directly via PM
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

Roo_027
Posts: 32
Joined: Wed Jan 10, 2018 10:10 am

Re: Pynput - RC Car and Motors

Sat Jan 27, 2018 1:42 pm

Thank you for the reply.

I will go through the docs and work out how to do the "WASD" configuration.

Return to “Automation, sensing and robotics”

Who is online

Users browsing this forum: No registered users and 6 guests