Tuesday, January 24, 2017

Install Steam Controller on Ubuntu 16.04

I have a Steam controller that I use every now and then and wanted to try it on Ubuntu 16.04. However, the operating system did not recognize the controller automatically, as of 22.01.2017 on a fresh install of Ubuntu 16.04. Luckily, it can be added quickly without any extensive troubleshooting.

Detecting the steam controller in ubuntu
Ubuntu 16.04 detecting the Steam controller for the first time.

Add a Controller

Referring to an earlier post from November 2016 on AskUbuntu.com the solution is quite straightforward and applies to a fresh 16.04 install.

  1. To install the controller we have to add a new device manually with udev,
    sudo gedit /lib/udev/rules.d/99-steam-controller-perms.rules
  2. There is no such file by default, so the above command will create it. Simply copy the following into it,
    # This rule is needed for basic functionality of the controller in Steam and keyboard/mouse emulation
    SUBSYSTEM=="usb", ATTRS{idVendor}=="28de", MODE="0666"

    # This rule is necessary for gamepad emulation; make sure you replace 'GROUP' with a group that the user that runs Steam belongs to
    KERNEL=="uinput", MODE="0660", GROUP="GROUP", OPTIONS+="static_node=uinput"

    # Valve HID devices over USB hidraw
    KERNEL=="hidraw*", ATTRS{idVendor}=="28de", MODE="0666"

    # Valve HID devices over bluetooth hidraw
    KERNEL=="hidraw*", KERNELS=="*28DE:*", MODE="0666"

    # DualShock 4 over USB hidraw
    KERNEL=="hidraw*", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="05c4", MODE="0666"

    # DualShock 4 wireless adapter over USB hidraw
    KERNEL=="hidraw*", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="0ba0", MODE="0666"

    # DualShock 4 Slim over USB hidraw
    KERNEL=="hidraw*", ATTRS{idVendor}=="054c", ATTRS{idProduct}=="09cc", MODE="0666"

    # DualShock 4 over bluetooth hidraw
    KERNEL=="hidraw*", KERNELS=="*054C:05C4*", MODE="0666"

    # DualShock 4 Slim over bluetooth hidraw
    KERNEL=="hidraw*", KERNELS=="*054C:09CC*", MODE="0666"
    Make sure to replace GROUP with the user's group that will run Steam. In most installations your username and group will be username:username, hence your username will suffice. If in doubt, you can check what groups you belong to simply by,
    groups username
  3. Unplug the controller adapter if it was plugged in.
  4. Re-plug the controller adapter. 
That should be it. Enjoy gaming.

Saturday, January 21, 2017

Install Cura 2.x on Ubuntu 16.04

Cura is a slicer software that prepares your 3D drawings for printing. Installing the latest version on Ubuntu 16.04 was not as easy as downloading the .deb file and installing it from the official site at: https://ultimaker.com/en/products/cura-software.

Cura 2.x running under Ubuntu 16.04

Install from repository

Firstly, since Cura depends on python 3.x, let's get the dependencies first,
sudo apt-get install python3 python3-dev python3-sip
Then add the following repository,
sudo add-apt-repository ppa:thopiekar/cura
Finally, update packages list and install cura.
sudo apt-get update && sudo apt-get install cura
After this you should be able to run cura either with the command cura from the terminal or from searching through dash.
Launch Cura from Ubuntu dash,

Saturday, January 7, 2017

Send email with PHP and crontab on reboot in Ubuntu

Even with the best VPS services reboots can happen: maintenance, hardware upgrade, kernel upgrade. Most of the time users are warned in advance so that they can prepare for the service outage. However, it can happen that there is a reboot and you did not know about it or simply forgot. 

I just added a small php script to my server to send me an email if it was rebooted. This way I can log in ASAP and restart services that do not start automatically.

Send email via PHP

This assumes that you have php installed on your Ubuntu instance.

A simple php program to send emails can look like this:

$to = "email@address.com";
$subject = "Reboot";
$txt = '

Hello, your server has been rebooted and services have most likely stopped.
If this reboot was unscheduled please log in to restart services.

Have a nice day!

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

//More headers
$headers = "From: server@server.com" . "\r\n" .
"CC: ";


It is kind of self-explanatory, but just to explain quickly: 

to: email address of the recipient
subject: subject of the email
text: main body of the email until the final semicolon (;). Note that you can also send html-based emails. To do this, simply used the html codes such as,
$text = '<html>
This is a html <br> message!
headers: sets the message header. You can write any email address in the "from" field.
mail($to,$subject,$txt,$headers); : sends the email with the previously defined variables above.

Create and test

  1. You can save the above in a .php file. (I prefer to have a MyScripts directory in my /home, just to keep everything organized.)
  2. Test if the program is working.
    sudo -u www-data php -f rebootMail.php
    This will call php, as the user "www-data", and launch the specified file. If your web server's default user is not www-data, adjust accordingly.

Note: If you have a web server running, you can run the above php program from your web browser. Simply copy the rebootMail.php into your /var/www (or wherever your web server's / is) and visit serveraddress.com/rebootMail.php. If you have done everything correctly, you should receive an email. Although, in this case the php program can be executed by anyone visiting it's web address.

Auto-launch program on reboot 

This can be done either via crontab or using /etc/rc.local. Let's do it via crontab.
  1. To edit existing cron scheduled tasks (no sudo needed),
    crontab -e
  2. In a new line at the end of the file add,
    @reboot /usr/bin/php /path/to/rebootMail.php
  3. Save changes and exit the nano editor,
    Ctrl + O
    Ctrl + X
Done. If all done correctly, you should now receive an email on every reboot. To make sure everything is well configured, you should reboot your server manually once and confirm that it works.

Note: If your php is not installed in /usr/bin, adjust the path accordingly.

Sunday, September 11, 2016

Change Banana Pi M3 CPU Frequency

This is a short script for changing the CPU clock rate of the Banana Pi M3 in the allowable steps between 480 MHz to 1.8 GHz.


Since the Banana Pi M3 heats quite a bit at 1.8 GHz (even with heat sinks), lowering the CPU frequency can bring these temperatures down. The clock rate can be tuned between 480 MHz and 1.8 GHz by default, possibly up to 2 GHz when the CPU voltages are adjusted and unlocked. 

Note: This script only adjusts the speed up to 1.8 GHz.


  1. Download the script from Pastebin [Direct Download
  2. Copy it over to your Banana Pi M3
    scp BananaPiM3_FrequencyChanger.sh user@bananapi:/home/remoteuser/
  3. Make it executable
    chmod +x BananaPiM3_FrequencyChanger.sh
  4. Run it with

Optional:  Add an alias in your .bash_aliases to call it faster!
echo "alias frequency='./BananaPiM3_FrequencyChanger.sh'" >> .bash_aliases
Apply the changes with,
source .bashrc
From now on you can call the script with
Screenshot of the script in action.
Screenshot of the script, setting my board's frequency to 1 GHz.

Wednesday, August 31, 2016

Large Heat Sink on Banana Pi M3

So while I was playing with the idea of running BOINC - on my otherwise mostly idle - octa-core Banana Pi M3, I remembered that the previously added tiny heat sink will probably not do much good. The CPU is still easily heating to 65-67 degrees Celsius even with a CPU clock rate set to 1GHz and under moderate load.
Small heat sink installed on my Banana Pi M3
Small heat sink installed on my Banana Pi M3


I started looking around in my "random parts box" and found a roughly 5*5 cm aluminium heat sink, with a slight plateau on the bottom, in the centre line where something used to be attached. Unfortunately, there isn't any mounting opportunity on the board and everything is tightly packed. The CPU and the RAM are the same height, but some parts directly next to them are slightly higher and this puts a limit on how large the heat sink can be. I measured and a roughly 3.5*2.5 cm heat sink should give enough clearance from nearby parts. I had to cut my heat sink into pieces, but it worked.
Heat sink cut into 3 parts. 1 scrap and 2 useful sides.
Heat sink cut into 3 parts. Bottom one is scrap, left and right are the right size.


I cleaned and polished the cut edges a bit and made sure it fits on the board. I put a grain of thermal paste on both the CPU and RAM and aligned the part carefully. It fits just right and the paste also gives a bit of mechanical stability, although not much. It is not visible on the pictures, but to hold the heat sink in place I have used 2 pea-sized balls of glue on the side of the heat sink close to the GPIO pins. Ideally I would have used a glue gun, but since I do not have one, I used the 2 component Pattex glue paste.

As you can see below, the heat sink has an odd-shape with one "arm" extending over the eMMC storage (to the right), whereas contact is only made on the left side with the CPU and RAM. I realize it is an oddly shaped heat sink, but the shape allowed me to use a surface area as large as possible.

Large heat sink mounted on the Banana Pi M3.

Large heat sink mounted on the Banana Pi M3. Side view.

 It is an odd shape, yes, but it is the added thermal mass and the surface area that matters.


  • I have been running BOINC on 6 cores at 100% load, using a clock frequency of 1GHz for about 45 minutes and the temperature seems to have maxed out at 62-63 degrees Celsius. Ambient temperature of 27 degrees Celsius.
  • The heat sink seems to sit tightly, despite the agreeably dodgy mounting. I wish I could have added some screws, but there simply isn't enough space.
  • The possible drawback is that since the heat sink covers both the RAM and CPU, it is quite likely that it is in fact heating the RAM. I am not sure if this is the case - or to what degree as the RAM was usually hot as well, just checking by touching - nevertheless, I'll keep an eye on this.
I will do a bunch of testing to see what temperatures I get at different CPU speeds and number of cores used. Stay tuned.

Running BOINC on Banana Pi M3

So I have my Banana Pi M3 sitting on my shelf, pretty much only serving as a low-power file server with samba shares. 8 cores, doing nothing 99% of the time. So I though, why not run BOINC on it and contribute to science projects a bit?


  • Banana Pi M3 (clocked down to 1GHz)
  • Seagate 2 TB HDD
  • Debian Jessie, as shown below.
lsb_release -a
No LSB modules are available.
Distributor ID:    Debian
Description:    Debian GNU/Linux 8.5 (jessie)
Release:    8.5
Codename:    jessie
uname -a
Linux bananapi 3.4.39-BPI-M3-Kernel #22 SMP PREEMPT Wed Mar 16 12:07:48 CST 2016 armv7l GNU/Linux


Installation is pretty straightforward and worked for me out of the box on the above mentioned installation.
  1. sudo apt-get update && sudo apt-get upgrade
  2. sudo apt-get install boinc-client


Now I don't have a screen attached to my Banana Pi M3, so I didn't download the boinc manager. There is the text interface tool, called boinctui, however I made the experience that it doesn't allow to connect to BAM! account manager. Hence I would rather connect from another machine on my local network with the boinc manager.
Furthermore, I would strongly recommend using an account manager (https://boincstats.com) and making a new "Work Preference" setting especially for the Banana Pi / other ARM devices. I have assigned 6 CPU cores total and a maximum usage of 100%. Also, the CPU clock rate of my device is throttled down to 1GHz to avoid overheating. (Yes, 8 cores heat quite a bit) Like this I am getting up to 63 degrees Celsius, thanks to my new over-sized heat sink!

To allow a remote boinc manager to connect I am running the client with the following command:

boinc --daemon --dir /path/to/BOINC/directory --no_gpus --allow_remote_gui_rpc 

As you can see I have a --dir option in there, which specifies the BOINC default directory. I have specified this on my 2 TB HDD so that there is plenty of space and not the 8 GB eMMC is used. It is running smoothly.
Running BOINC on my Banana Pi M3, currently 6 cores at 1 GHz.
Running BOINC on my Banana Pi M3, currently 6 cores at 1 GHz.

Connect remotely

On your remote machine launch Boinc manager and go to File/Select Computer. In the popup window enter the IP address of the Banana Pi and the password. The latter is stored in the default BOINC directory under /Boinc/directory/gui_rpc_auth.cfg.  You can edit this simply with 
sudo nano /Boinc/directory/gui_rpc_auth.cfg
Select computer to control with Boinc manager
Select computer to control with Boinc manager.
After this you can easily add an account manager and synchronize with the projects and settings as per configured at https://boincstats.com. This way you can remotely adjust the settings as needed later on.


HDD spin up/down timeout

By default you may have noticed that an attached hard drive is on continuously, it doesn't enter sleep/stand-by mode. To avoid this, I have added the following to my /etc/rc.local
sudo hdparm -S 25 /dev/sdb
This tells the drive to spin down if there was no activity in the last 25*5 seconds. Now if you have done the same, the smart thing to do (I guess) would be to limit  how often the boinc client can access the drive. I don't want it to have access every 60 seconds and spin up the drive for 5 seconds to write something and then wait 60 seconds again. This would be wasteful in terms of drive lifetime. Hence I would recommend setting the "Write to disk at most" parameter in the client settings to reasonably value. I am testing 1000 seconds for the moment.
This can be configured in your BAM! account at https://boincstats.com/en/bam/workPreferences/.

CPU clock settings

At the maximum of 2 GHz the 8 cores produce quite a bit of heat and therefore would continuously throttle back the whole device. Therefore I would recommend setting the maximum frequency a bit lower. The relevant system directory is /sys/devices/system/cpu/cpu0/cpufreq.
To see the available frequencies
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies

I have made the following script that sets up my CPU clockrate on every boot. From this you can easily deduct how to set what.

#Sets the CPU's core frequency

echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo 1000000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq
echo 480000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq
echo 25 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold
echo 10 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor
You can save this script, make it executable with
sudo chmod +x script.sh
And then call it from e.g. /etc/rc.local to run at system boot.

You can experiment a bit to see what is best.


Check out my post to see how I have resolved this issue.
Large Heat Sink on the Banana Pi M3.

Sunday, May 1, 2016

Cannot set password for user with adduser

Recently with my Banana Pi M3 I was having multiple issues while installing. One of them was an error message when trying to set up a new user. See the error message below.

Current password:
New password:
New password (again):
passwd: Authentication token manipulation error
passwd: password unchanged


When adding a new user with
sudo adduser $user
The system does not accept a password and produces the above message.


I have found that removing the (non existing ?) password from the user is the only way to solve the problem quickly. It is a weird thing, I have no clue what is causing this.
While logged in as any user with root privileges (sudo), delete the $user password,
sudo passwd -d $user
And set a new password for $user,
sudo passwd $user
It should work now.

Credit goes to Askubuntu.com. Thanks!