Skip to content

wangdrew/e-foosball

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 

Repository files navigation

e-foosball

Foosball is fun! Foosball with lights, sound effects, and active score tracking is even better!

Intro

This repository contains Arduino and Python source code to poll goal sensors, drive goal box LED lights for effect, maintain score state, and update LED score indicators.

Why Arduino and Python? The Arduino code drives the hardware - sensors and LEDs. The Python code runs on a Raspberry Pi and primarily plays sound effects but future improvements will bring score persistence, stats, and a foosball web server. Playing audio is too expensive to perform on the Arduino and its 25k usable memory doesn't cut it for most audio playback.

Overview

Materials

Arduino

The Arduino source code is located in a single sketch file - [FoosballArduino.ino] (FoosballArduino/FoosballArduino.ino)

The code runs on an Arduino Uno R3 and can be adapted for any Atmega Arduino board by changing the pinout variables.

The Arduino code polls two infared sensors, one for each goalbox. Upon detecting a trip when the ball goes in the goalbox, the goalbox analog LED strips flash and the digital LED strips increment score. A basic FSM implements this logic.

The Arduino also maintains the score and sends it through serial over USB to the Raspberry Pi for every detected goal.

Raspberry Pi

The Raspberry Pi runs the Debian-based OS Raspbian with Python 2.7 installed. The e-foosball python code is located: GameManager.py

The following python packages must be installed prior to running GameManager.py

sudo apt-get update
sudo apt-get -y install python-serial
sudo apt-get -y install alsa-tools alsa-utils
sudo apt-get -y install python-alsaaudio

You may need to change a library file, see Issues section.

Once installed simply run:

python GameManager.py

The Pi opens a serial connection using PySerial and listens for game events (i.e. new game, goals) generated by the Arduino. Upon receiving a game event, the event is passed to event handlers to perform actions on the event. One event handler, SoundEventHandler plays different sounds depending on the score.

Issues

GameManager uses pydub library for audio playback. Unfortunately pydub's preferred backend pyaudio has known issues running on a Raspberry Pi. I've also experienced these clipping issues and couldn't figure out a way around it. Getting pydub to work properly involves a mega-hack. Edit library file: /usr/local/lib/python2.7/dist-packages/pydub/playback.py and change this line:

subprocess.call([PLAYER, "-nodisp", "-autoexit", f.name])

to:

subprocess.call(["aplay", f.name])

This forces pydub to use linux utility aplay to play audio files which works but a hack is still a hack.

About

arduino and python code to pimp out a foosball table

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages