Skip to content

Controlling and mapping gamepads with Python and Raspberry Pi and using MQTT to connect to ESP8266 to Raspberry Pi

Notifications You must be signed in to change notification settings

hritobroto/Gamepad-Control

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Gamepad-Control

  • Basic- All button mapping
  • Version 1.0- Direction and speed control
  • Version 2.0- Exception handling

Connecting to the Raspberry Pi

Updating Raspberry Pi:

apt-get update && apt-get upgrade -y
  • For bluetooth controllers:

    sudo bluetoothctl
    power on
    agent on
    default-agent

    The bluetoothctl will keep the bluetooth device talking to Linux.

    scan on

    This gives a list of the avaiable devices

    pair XX:XX:XX:XX:XX:XX

    This is the format for pairing the device with the device ID.

  • For USB Controllers:
    Just plug in the USB cable


Communication

Turn off/unplug the device and use

ls /dev/input

Then reconnect/plug the device back in and run the command again. This gives the new device that is being added. For eg, Device1
Now to test out out the incoming data from the device:

cat /dev/input/Device1

if this gives an output it means the device is connected and it is communicating with the Raspberry Pi.


Test communication with EVDEV

First, lets install EVDEV

sudo apt-get install python-dev
sudo apt-get install python-pip
sudo pip install evdev

Test communication with INPUTS

First, lets install input

pip install inputs

or

git clone https://github.com/zeth/inputs.git
cd inputs
python setup.py install

or just download inputs.py


Mapping controller:

  • EVDEV
    Parts: ecode type, event code, event value.
  • Inputs
    Parts: event type, event code, event state.

Installing Mosquitto

sudo apt install -y mosquitto mosquitto-clients
mosquitto -v

Installing Flask

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python-pip python-flask
pi@raspberrypi ~ $ sudo pip install flask

Installing Paho-MQTT

sudo pip install paho-mqtt

NB:
  • Highlighted fields are executable terminal commands.
  • Flask as backup if controller fails

About

Controlling and mapping gamepads with Python and Raspberry Pi and using MQTT to connect to ESP8266 to Raspberry Pi

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages