9/15/2023 0 Comments Arduino bluetooth motor![]() ![]() init () print 'Xbox Controller Connected' # Create the client socket Import bluetooth import serial import pygame import time import math # init controller It would be really cool to come back and finish this properly but for now my demo was done. Rather than modify my Arduino program to read analog data over serial and really use the controller I simply mapped joystick values to W A S D in python before sending it over bluetooth. Now I will admit at this point I had pretty much proved my point and I needed to get back to more important work so the final result was a bit of a cop out. It turns out this really wasn’t too hard I used pygame to read from the joystick and the rest is pretty much history. getch () getch = _Getch ()Īfter I got the connection stuff working and out of the way it was pretty simple to write an Arduino program to accept my input and respond accordingly.īut I wasn’t done just yet! I wanted to take my demo further and use an XBox 360 controller instead of the keyboard. TCSADRAIN, old_settings ) return ch class _GetchWindows : def _init_ ( self ): import msvcrt def _call_ ( self ): import msvcrt return msvcrt. impl () class _GetchUnix : def _init_ ( self ): import tty, sys def _call_ ( self ): import sys, tty, termios fd = sys. impl = _GetchUnix () def _call_ ( self ): return self. impl = _GetchWindows () except ImportError : self. Does not echo to the screen.""" def _init_ ( self ): try : self. Here is the python code, it’s pretty simple:Ĭlass _Getch : """Gets a single character from standard input. Of course I chose the familiar control scheme of W S A D`. I borrowed a getch() class from stack overflow to facilitate only grabbing one key press at a time and then sent it to the robot. It took me a bit to get set up to send data between the two but it wasn’t too tough. I googled around for a bluetooth library and decided on pybluez with python. ![]() ![]() I had a program from previous years in the course that did just this but it was in the form of a windows binary and I a) couldn’t be bothered to boot into windows and b) wanted to do it myself anyways. I hooked up the bluetooth shield and started looking into how to send commands from my computer. I’d been playing with the robots for a while so I knew all the basic features now it was time to go above and beyond. Now I could have ran any number of basic demonstrations that would have taken no time at all but of course I chose to take the opportunity to do something cool (well at least I think it is cool…).īeing the teaching assistant for ELEC 299, a second year course which uses mobile robots, I had access to some pretty cool hardware. This is the night where we try and entice the first years (Queen’s is a general first year) to choose ECE for their discipline for second and hopefully subsequent years. Earlier this week I was asked to put together a robotics demo for the Electrical and Computer Engineering first year discipline night. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |