Skip to content

Instantly share code, notes, and snippets.

@tomoinn
Last active October 7, 2018 20:28
Show Gist options
  • Save tomoinn/0c4396f1e508c1bf01d82f58aced8f8c to your computer and use it in GitHub Desktop.
Save tomoinn/0c4396f1e508c1bf01d82f58aced8f8c to your computer and use it in GitHub Desktop.
Notes on setting up my Raspberry Pi for PiWars, no further explanation but might be helpful!
Install 4.15.9 according to https://www.raspberrypi.org/documentation/linux/kernel/building.md
SSH to pi, then...
sudo apt-get install git bc libdbus-1-dev libglib2.0-dev libudev-dev libical-dev libreadline-dev -y
wget www.kernel.org/pub/linux/bluetooth/bluez-5.49.tar.xz
tar -xvf ./bluez-5.49.tar.xz
cd bluez-5.49/
wget https://gist.github.com/pelwell/c8230c48ea24698527cd/archive/3b07a1eb296862da889609a84f8e10b299b7442d.zip
unzip 3b07a1eb296862da889609a84f8e10b299b7442d.zip
git apply -v c8230c48ea24698527cd-3b07a1eb296862da889609a84f8e10b299b7442d/*
./configure --prefix=/usr --mandir=/usr/share/man --sysconfdir=/etc --localstatedir=/var --enable-experimental \\
--with-systemdsystemunitdir=/lib/systemd/system --with-systemduserunitdir=/usr/lib/systemd --enable-sixaxis \\
--enable-library
make -j4
sudo systemctl stop bluetooth
sudo make install
sudo nano /etc/systemd/system/bluetooth.target.wants/bluetooth.service
---
[Unit]
Description=Bluetooth service
Documentation=man:bluetoothd(8)
ConditionPathIsDirectory=/sys/class/bluetooth
[Service]
Type=dbus
BusName=org.bluez
ExecStart=/usr/libexec/bluetooth/bluetoothd --experimental
NotifyAccess=main
#WatchdogSec=10
#Restart=on-failure
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
LimitNPROC=1
ProtectHome=true
ProtectSystem=full
[Install]
WantedBy=bluetooth.target
Alias=dbus-org.bluez.service
---
sudo nano /etc/dbus-1/system.d/bluetooth.conf
---
<!-- This configuration file specifies the required security policies
for Bluetooth core daemon to work. -->
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<!-- ../system.conf have denied everything, so we just punch some holes -->
<policy user="root">
<allow own="org.bluez"/>
<allow send_destination="org.bluez"/>
<allow send_interface="org.bluez.Agent1"/>
<allow send_interface="org.bluez.MediaEndpoint1"/>
<allow send_interface="org.bluez.MediaPlayer1"/>
<allow send_interface="org.bluez.Profile1"/>
<allow send_interface="org.bluez.GattCharacteristic1"/>
<allow send_interface="org.bluez.GattDescriptor1"/>
<allow send_interface="org.bluez.LEAdvertisement1"/>
<allow send_interface="org.freedesktop.DBus.ObjectManager"/>
<allow send_interface="org.freedesktop.DBus.Properties"/>
</policy>
<policy user="pi">
<allow own="org.bluez"/>
<allow send_destination="org.bluez"/>
<allow send_interface="org.bluez.Agent1"/>
<allow send_interface="org.bluez.MediaEndpoint1"/>
<allow send_interface="org.bluez.MediaPlayer1"/>
<allow send_interface="org.bluez.Profile1"/>
<allow send_interface="org.bluez.GattCharacteristic1"/>
<allow send_interface="org.bluez.GattDescriptor1"/>
<allow send_interface="org.bluez.LEAdvertisement1"/>
<allow send_interface="org.freedesktop.DBus.ObjectManager"/>
<allow send_interface="org.freedesktop.DBus.Properties"/>
</policy>
<policy at_console="true">
<allow send_destination="org.bluez"/>
</policy>
<!-- allow users of lp group (printing subsystem) to
communicate with bluetoothd -->
<policy group="lp">
<allow send_destination="org.bluez"/>
</policy>
<policy context="default">
<deny send_destination="org.bluez"/>
</policy>
</busconfig>
---
sudo nano 90-led-permissions.rules
---
SUBSYSTEM=="leds", ACTION=="add", RUN+="/bin/chgrp -R leds /sys%p", RUN+="/bin/chmod -R g=u /sys%p"
SUBSYSTEM=="leds", ACTION=="change", ENV{TRIGGER}!="none", RUN+="/bin/chgrp -R leds /sys%p", RUN+="/bin/chmod -R g=u /sys%p"
---
sudo groupadd leds
sudo usermod -a -G leds pi
sudo nano /etc/modprobe.d/bluetooth.conf
---
options bluetooth disable_ertm=Y
---
sync
sudo reboot
pi@pi3b:~ $ uname -a
Linux pi3b 4.15.9-v7+ #1 SMP Wed Mar 14 18:59:34 GMT 2018 armv7l GNU/Linux
pi@pi3b:~ $ bluetoothctl -v
bluetoothctl: 5.49
XB1 controller:
pi@pi3b:~ $ bluetoothctl
Agent registered
[bluetooth]# default-agent
Default agent request successful
[bluetooth]# scan on
Discovery started
(put XB1S controller into pairing mode with Home+Share held down on power-on)
[CHG] Controller B8:27:EB:D4:32:CB Discovering: yes
[CHG] Device 5C:BA:37:1D:92:07 RSSI: -53
[bluetooth]# connect 5C:BA:37:1D:92:07
Attempting to connect to 5C:BA:37:1D:92:07
[CHG] Device 5C:BA:37:1D:92:07 Connected: yes
[CHG] Device 5C:BA:37:1D:92:07 Modalias: usb:v045Ep02E0d0903
[CHG] Device 5C:BA:37:1D:92:07 Modalias: usb:v045Ep02FDd0903
[CHG] Device 5C:BA:37:1D:92:07 UUIDs: 00001124-0000-1000-8000-00805f9b34fb
[CHG] Device 5C:BA:37:1D:92:07 UUIDs: 00001200-0000-1000-8000-00805f9b34fb
[CHG] Device 5C:BA:37:1D:92:07 ServicesResolved: yes
[CHG] Device 5C:BA:37:1D:92:07 Paired: yes
Connection successful
[Xbox Wireless Controller]# trust 5C:BA:37:1D:92:07
[CHG] Device 5C:BA:37:1D:92:07 Trusted: yes
Changing 5C:BA:37:1D:92:07 trust succeeded
[Xbox Wireless Controller]#
PS3 controller:
pi@pi3b:~ $ bluetoothctl
Agent registered
[bluetooth]# default-agent
Default agent request successful
Plug in PS3 controller over USB
[NEW] Device 00:21:4F:16:32:69 Sony PLAYSTATION(R)3 Controller
Authorize service
[blue1m[agent] Authorize service 00001124-0000-1000-8000-00805f9b34fb (yes/no): yes
Remove controller / press PS button
[CHG] Device 00:21:4F:16:32:69 Trusted: yes
[CHG] Device 00:21:4F:16:32:69 UUIDs: 00001124-0000-1000-8000-00805f9b34fb
[CHG] Device 00:21:4F:16:32:69 Class: 0x00000508
[CHG] Device 00:21:4F:16:32:69 Icon: input-gaming
[CHG] Device 00:21:4F:16:32:69 Connected: yes
Numpy + OpenBLAS + OpenCV
cd ~
git clone git@github.com:xianyi/OpenBLAS.git --depth=1 --branch=armv7
cd OpenBLAS
make FC=gfortran -j4
sudo make PREFIX=/opt/OpenBLAS install
sudo sh -c "echo '/opt/OpenBLAS/lib' > /etc/ld.so.conf.d/openblas.conf"
sudo ldconfig
cd ~
git clone git@github.com:numpy/numpy.git --depth=1
cd numpy
cp site.cfg.example site.cfg
nano site.cfg
---
[openblas]
libraries = openblas
library_dirs = /opt/OpenBLAS/lib
include_dirs = /opt/OpenBLAS/include
runtime_library_dirs = /opt/OpenBLAS/lib
---
pip install cython
python setup.py build --fcompiler=gnu95 -j 4
python setup.py bdist_wheel
pip install .
cd ~
git clone git@github.com:opencv/opencv.git --depth=1
git clone git@github.com:opencv/opencv_contrib.git --depth=1
cd opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D ENABLE_NEON=ON \
-D ENABLE_VFPV3=ON \
-D BUILD_TESTS=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D BUILD_EXAMPLES=OFF ..
SensHat installation without debian package:
(from within virtual environment, tested with Python 3.7b3)
sudo apt-get install libqt4-dev
cd ~
git clone git@github.com:RPi-Distro/RTIMULib.git
cd RTIMULib/Linux
mkdir build
cd build
cmake ..
make -j4
sudo make install
sudo ldconfig
cd ../python
python setup.py install
cd ~
git clone git@github.com:RPi-Distro/python-sense-hat.git
cd python-sense-hat
python setup.py install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment