Using an Arduino with Python LESSON 17: Controlling Paddle Position with a JoyStick

preview_player
Показать описание
In this video we show how to use a Joystick with Arduino, pass the data to python, and then use the data to control the paddle position in our 3D pong Game. We are using the joystick in your Elegoo Super Starter Kit. If you do not have your kit yet, you can pick it up at the link below (affiliate link):

With this kit, we will will both be working on the same hardware which will make your life and my life easier.

You guys can help me out over at Patreon, and that will help me keep my gear updated, and help me keep this quality content coming:

#Python
#Tutorial
#Arduino

Рекомендации по теме
Комментарии
Автор

I am legend again. Thanks to Paul's patient explanations I can usually do the homework in an hour or so, my stupid mistakes not withstanding. When the maths gets difficult, draw a graph!

steveholt
Автор

I AM LEGEND! There are many possible ways to vary the difficulty of this game. Paul has given me much greater insight into how games are developed. Thanks for all your work on these lessons Paul!

cbrombaugh
Автор

Thanks Paul! I enjoyed the presentation. I can see so many ways in which I can use the line equation beyond this lesson. You have used
it in previous sessions and it is becoming second nature.

edSabio
Автор

The lessons are a great deal of fun with the added benefit of making a game I enjoyed many years ago. God Bless you and your family. #RESISTTHEMETAVERSE CHARGE!!!

opalprestonshirley
Автор

Hi Paul, thanks again, another informative and great lesson.

alfredcalleja
Автор

Hey Big Thanks My Legend for your Mercy!

jerrysankara
Автор

First to comment, Paul is the Engineering himself, 🥰🥰

kekekeernest
Автор

Hello guys. I have some code issues. Sometimes it works, sometimes it doesn't. I also tried to copy the code directly from toptechboy to avoid typos, but without progress. I also tried with two different USB cables on two different computers, with the same negative result. In some cases the Python code works, in others I get one of these errors. It is random. I also added a few lines of print to the code to print the various phases of the dataPacket to find the error. These errors are: Print index out of range or: String cannot be converted to floating.


print('data is: ', dataPacket)
dataPacket=str(dataPacket, 'utf-8')
print('data string: ', dataPacket)
dataPacket.strip('\r\n')
print('data strip: ', dataPacket)
splitPacket=dataPacket.split(', ')
print('split: ', splitPacket)

output in case index out of range error:
data is: b'6, 1\r\n'
data string: 6, 1
data strip. 6, 1

split. ['6', '1\r\n']

There is one value missing


output in case could not convert string to float error:
data is: b'486, 1\r520, 486, 1\r\n'
520, 486, 1ng: 486, 1

520, 486, 1p. 486, 1

split. ['486', '1\r520', '486', '1\r\n']
ValueError: could not convert string to float: '1\r520'

Output in Arduino IDE serial monitor is always all right





Do you have any suggestions? Thank you

UPDATE:
Okay guys, I think I've solved it. It was really a HW problem, sometimes Arduino sent a bad read (incomplete) and therefore the program crashed. I solved this with the IF statement, which checks a number of elements in the array and skips this loop in case of an incomplete array.



example in pseudocode:


if len(splitPacket)==3:
GO
else:
print("reading error")

jansimurda
Автор

I liked this video and make comment on it.

Thank you paul for this gteat content.

anwarzebkhan
Автор

Great stuff as usual! How about adding" Gravity" to the y axis and bouncing the ball?

taurus
Автор

I took a different approach where I used if statements to control joystick. If x < 508 move left...if x>512 move right etc... I just had a 'speed' variable to control how fast paddle moves. This worked well but I couldn't get the paddle to stop when you hit a wall. I tried....

briangraham
Автор



heres a paddle X position that stops before the edge of the paddle and the wall.

RyBred
Автор

Paul I am not sure if you know this, but is Indian JEE math sufficient for good math practice for engineering...? I’ve heard american college math becomes simple that way...

sunilkulkarni
Автор

Hi is it we can run the machine learning code on aurdino witj pyfirmata

Minutes_Of_Code
Автор

It was fun. Got it to work and stay inside the box:

MakeItCodeItPrintIt