This code has been developed and tested on a Raspberry Pi 3 Model B+ running NOOBS. Available from the Raspberry Pi shop:
https://www.raspberrypi.org/products/raspberry-pi-3-model-b-plus/
Whilst not completely necessary, I wholeheartedly recommend explicitly disabling IPv6 on the Raspberry Pi by adding these lines to /etc/sysctl.conf
:
sysctl.conf.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
net.ipv6.conf.eth0.disable_ipv6 = 1
net.ipv6.conf.[interface].disable_ipv6 = 1
This should make network connections significantly quicker to initialise on some networks (most notably, the London Futurice office). Once that's done, reboot:
sudo reboot
Before we install anything, let's confirm the APT is up to date:
sudo apt-get update -y
This project is designed to run on Python 3.5.x
or 3.6.x
, which comes bundled with the Raspbian and Ubuntu (at time of writing) but isn't the default.
We can use Python 3 with the python3
command:
python3 --version
Other versions might work but finding an ARM-compiled binary for numpy
that works as intended is entirely contingent on piwheels and can be quite a lot of hassle.
sudo apt-get install libcblas-dev libhdf5-dev libhdf5-serial-dev libatlas-base-dev libjasper-dev libqtgui4 libqt4-test xboxdrv joystick python-smbus i2c-tools -y
pip3 install numpy==1.13.3 opencv-python tensorflow picamera adafruit-circuitpython-servokit
sudo apt-get install libhdf5-serial-dev hdf5-tools
sudo apt-get install zlib1g-dev zip libjpeg8-dev libhdf5-dev
pip3 install adafruit-circuitpython-pca9685 adafruit-circuitpython-motor numpy grpcio absl-py py-cpuinfo psutil portpicker grpcio six mock requests gast h5py astor termcolor
pip3 install --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v42 tensorflow-gpu==1.13.1+nv19.3
Whilst initially configuring the Pi, we need to disable ERTM to allow Bluetooth connections from an Xbox Controller:
sudo touch /etc/modprobe.d/bluetooth.conf
sudo bash -c "echo 'options bluetooth disable_ertm=Y' >> /etc/modprobe.d/bluetooth.conf"
sudo reboot
sudo bluetoothctl
agent on
default-agent
scan on
connect CONTROLLER_MAC_ADDRESS
trust CONTROLLER_MAC_ADDRESS
exit
Once this is done, the controller should attempt to connect to the Pi automatically any time it's turned on until it is manually connected to another device.
If the controller becomes disconnected, we don't need to pair again. We can connect to the controller manually:
sudo bluetoothctl
devices
connect CONTROLLER_MAC_ADDRESS
exit
If this doesn't work, it might be connected to another device. Plugging the controller in to a PC with micro-USB should clear its existing connection.
sudo jstest /dev/input/js0
python3 start.py --help