For the past several months I've been chipping away on a RPi project to build an always-on, graphical information and media center that is elegant enough to display in the home or office. The result, so far, provides weather, time, calendar, alarms, hourly chime and internet radio functions accessed using a touch-screen or keyboard. Here are a couple of screenshots of the current implementation:
The code for this is written in Python 2.7 using Pygame and is available on GitHub. This project has been a great learning experience, covering a variety of disciplines that stretched my skills set. I plan on blogging different aspects of the build and sharing what I've learned. Can't say that I'm a master at any them, but the result meets my satisfaction. I hope you'll find something of interest here as well.
My Pi Corner
All things Raspberry Pi
Saturday, September 13, 2014
Sunday, March 23, 2014
XBox 360 Controller and Python
The Raspberry Pi has spawned a never ending stream of cool tech projects. With its low cost, smartly designed feature set, and strong sharing community, it will continue to satisfy hardcore and nooby geeks alike.
Here's another cool project for the Pi that makes it easy to extend its capabilities by providing wireless remote control. The XBox 360 controller is an excellent input device, having several analog and digital controls. Combine that with the wireless USB adapter and you have a compact and feature-rich control method, perfect for robots or other remote control projects.
Interfacing with the Pi can be done using a driver that is available called xboxdrv at http://pingus.seul.org/~grumbel/xboxdrv/. This driver takes care of reading raw controller input, but doesn't provide a useful interface for scripting. I've created a Python class that makes it easy to read all of XBox controller inputs in real-time. Digital inputs, such as the A, B, X, and Y buttons return 1 when pressed (True) or 0 when not pressed (False). Analog inputs return floating point values between -1.0 and 1.0. Here's a simple example of how to use the class:
Source code, setup instructions and more sample code for my xbox.py module are available on github
Note: xboxdrv will require sudo privileges to access the USB device. There are workarounds to this, which can be found if you Google around.
Interfacing with the Pi can be done using a driver that is available called xboxdrv at http://pingus.seul.org/~grumbel/xboxdrv/. This driver takes care of reading raw controller input, but doesn't provide a useful interface for scripting. I've created a Python class that makes it easy to read all of XBox controller inputs in real-time. Digital inputs, such as the A, B, X, and Y buttons return 1 when pressed (True) or 0 when not pressed (False). Analog inputs return floating point values between -1.0 and 1.0. Here's a simple example of how to use the class:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xbox | |
joy = xbox.Joystick() #Initialize joystick | |
if joy.A(): #Test state of the A button (1=pressed, 0=not pressed) | |
print 'A button pressed' | |
x_axis = joy.leftX() #X-axis of the left stick (values -1.0 to 1.0) | |
(x,y) = joy.leftStick() #Returns tuple containing left X and Y axes (values -1.0 to 1.0) | |
trigger = joy.rightTrigger() #Right trigger position (values 0 to 1.0) | |
joy.close() #Cleanup before exit |
Source code, setup instructions and more sample code for my xbox.py module are available on github
Note: xboxdrv will require sudo privileges to access the USB device. There are workarounds to this, which can be found if you Google around.
Subscribe to:
Posts (Atom)