Raspberry Pi: static IP address

  • Raspberry Pi 3 model B

To set Raspberry Pi static IP address, e.g

  • Modify /etc/network/interfaces
#iface eth0 inet dhcp
iface eth0 inet static
  • Add to /etc/dhcpcd.conf
interface eth0
static ip_address=
static routers=
static domain_name_servers=


Raspberry Pi: slow mouse cursor

  • Raspberry Pi 3 model B

If changing mouse cursor speed in Raspberry Pi Preferences does not work for you try this:

$ sudo nano /boot/cmdline.txt
# Add the bold text at the end of the line:
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles usbhid.mousepoll=0

Taken from Mouse pointer speed.


Raspberry Pi: Dart Hello BC2835

  • Ubuntu 16.04 LTS
  • arm-linux-gnueabihf (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
  • Dart SDK, master 511963d71509de50ac577ac22f3bac8d33c17e34
  • Raspberry Pi 3 model B
Install ARM toolchain

See Raspberry Pi: C++ cross-compiling

Build and install Dart SDK for ARM

See Dart: build Dart SDK for x86 and ARM

Optionally, copy dart-api.h to /usr/local/include:

$ cd dart-sdk/sdk/out
$ find . -name dart_sdk.h
$ cp ./ReleaseXARM/dart-sdk/include/dart_api.h /usr/local/include
Build and install libbcm2835.so

See Raspberry Pi: cross-compile bcm2835 library

Build  missing Dart SDK ARM libraries
# libunsafe_extension.git
$ git clone https://github.com/mezoni/unsafe_extension.git
$ cd unsafe_extension/lib/src/
$ arm-linux-gnueabihf-gcc -shared -fPIC -I/home/username/tools/sdk-dart/sdk/out/ReleaseXARM/dart-sdk/include unsafe_extension.cc -o libunsafe_extension.cc
$ scp libunsafe_extension.so pi@192.168.0.xxx:~
# libffi6_extension.so
$ git clone https://github.com/mezoni/libffi6_extension.git
$ cd libffi6_extension/lib/src/
$ arm-linux-gnueabihf-gcc -shared -fPIC -I/home/username/tools/sdk-dart/sdk/out/ReleaseXARM/dart-sdk/include ffi6_extension.cc -o libffi6_extension.so
$ scp libffi6_extension.so pi@192.168.0.xxx:~
Install the libraries on Raspberry Pi
# On Raspberry Pi
$ sudo mv libbcm2835.so /usr/lib
$ sudo mv libunsafe_extension.so /usr/lib
$ sudo mv libffi6_extension.so /usr/lib
$ sudo ldconfig
Dart Hello BCM2835 project
# On Raspberry Pi
$ git clone https://github.com/yolkhovyy/dart-hello-bcm2835.git
$ cd dart-hello-bcm2835
$ pub get
Resolving dependencies... (1.6s)
Got dependencies!
$ dart bin/main.dart
Hello bcm2835!
Unhandled exception:
Bad state: File not found: bcm2835.lib.h
#0      Declarations.Declarations (package:binary_declarations/src/binary_declarations/declarations.dart:25:7)
#1      _Declarations.declare (package:binary_types/src/declarations.dart:37:28)
#2      BinaryTypeHelper.declare (package:binary_types/src/type_helper.dart:143:24)
#3      Bcm2835Lib.Bcm2835Lib (package:bcm2835_bindings/src/bcm2835_bindings/bcm2835.lib.dart:17:14)
#4      loadBcm2835Library (package:bcm2835_bindings/src/bcm2835_bindings/bcm2835_lib_loader.dart:23:14)
#5      main (file:///home/pi/projects/spikes/bcm2835/dart/bin/main.dart:13:27)
#6      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:263)
#7      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:151)

TODO: figure out why bcm2835.lib.h is missing.

Update: bcm2835_bindings is not maintained anymore – dead end?

Raspberry Pi: cross-compile bcm2835 library

  • Ubuntu 16.04 LTS
  • arm-linux-gnueabihf (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
  • Raspberry Pi 3 Model B

The bcm2835 library “provides access to GPIO and other IO functions on the Broadcom BCM 2835 chip, as used in the RaspberryPi, allowing access to the GPIO pins on the 26 pin IDE plug on the RPi board so you can control and interface with various external devices”.

Install ARM toolchhain

See Raspberry Pi: C++ cross-compiling.

Download and cross-compile bcm2835
Static library

Note, that:

  • In the example below version 1.52 of the library is used – replace with the latest version.
  • The toolchain prefix arm-linux-gnueabihf- should be replaced by your toolchain prefix. See more on toolchains and cross-compiling in Raspberry Pi: C++ cross-compiling blog.
  • The library and its header will be installed in /usr/local/lib and /usr/local/include.
$ wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.52.tar.gz
$ tar zxvf bcm2835-1.52.tar.gz
$ cd bcm2835-1.52
$ ./configure -host=arm -prefix=/usr/local CC=arm-linux-gnueabihf-gcc ar=arm-linux-gnueabihf-ar
$ make
# Skip the check (test) - it will fail in Ubuntu
# sudo make check
$ sudo make install
 /bin/mkdir -p '/usr/local/lib'
 /usr/bin/install -c -m 644  libbcm2835.a '/usr/local/lib'
 ( cd '/usr/local/lib' && ranlib libbcm2835.a )
 /bin/mkdir -p '/usr/local/include'
 /usr/bin/install -c -m 644 bcm2835.h '/usr/local/include'

To change installation directories to, e.g. /usr/local/include/rpi and /usr/local/lib/rpi, use the -includedir and -libdir option instead of -prefix:

$ ./configure -host=arm CC=arm-linux-gnueabihf-gcc ar=arm-linux-gnueabihf-ar -includedir=/usr/local/include/rpi -libdir=/usr/local/lib/rpi
$ sudo make install
 /bin/mkdir -p '/usr/local/lib'
 /usr/bin/install -c -m 644  libbcm2835.a '/usr/local/lib/rpi'
 ( cd '/usr/local/lib' && ranlib libbcm2835.a )
 /bin/mkdir -p '/usr/local/include'
 /usr/bin/install -c -m 644 bcm2835.h '/usr/local/include/rpi'
Shared library

Quick solution without involving autotools:

$ cd bcm2835-1.52/src
$ arm-linux-gnueabihf-gcc -shared -fPIC bcm2835.c -o libbcm2835.so

Copy the shared library to the /lib on your Raspberry Pi.

Raspberry Pi: serial terminal setup

  • Ubuntu 16.04 LTS
  • Raspberry Pi 3 Model B
Serial terminal setup
Serial cable

We need a FTDI USB-cable, e.g. such one.

Connect the cable to Raspberry Pi GPIO connector.

Disclaimer: I’ll take no responsibility for the correctness of the wiring information below and potential damage of your hardware. Please re-check the wiring.

  • RxD (green wire) – pin 10
  • TxD (white wire) – pin 8
  • Ground (black wire) – pin 6
  • Power (red wire) – pin 4, connect only if you want to power your Raspberry Pi via the serial cable, otherwise – leave unconnected


One of the options is the Screen Shell Session Manager  as described on Intel’s Set up a serial terminal page:

$ sudo apt-get install screen
$ sudo screen /dev/ttyUSB0 115200

Other option is Putty, install and configure as shown below:

$ sudo apt-get install putty


Raspberry Pi: compile and run Magenta

  • Ubuntu 16.04 LTS
  • arm-linux-gnueabihf (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
  • Magenta master branch, commit 0ad390c4d67102ede5ad8aeaa0f51d1f6401ab6c
  • Raspberry Pi 3 Model B

Magenta is a kernel developed by Google and used in Google’s coming soon brand new Fuchsia OS. Magenta is based on Little Kernel.

Download Magenta source code

Magenta source code can be downloaded as part of Fuchsia OS (see Fuchsia OS Getting Started) or separately (see Magenta Getting Started)

Build Magenta
# In Fuchsia repositories it's in the magenta folder
$ cd fuchsia/magenta
# Or, standalone Magenta repository
$ cd magenta
$ make magenta-rpi3-arm64
Prepare bootable SD card

To run Magenta on Raspberry Pi we need a single-partition bootable SD card with Master Boot Record (MBR) and FAT32 file system. Not all cards come in that state. See how to make one on Intel’s Make a bootable micro SD card page:

  • Run Unity Dash (desktop search utility).
  • Enter the command: disks.
  • Select the Disks app.
  • Insert the micro SD card into your computer.
  • In the left sidebar, select the micro SD card.
  • If you see multiple partitions, select a partition and click the icon to delete the partition.
  • Click the + icon to create a new partition.
  • From the Type drop-down list, select Compatible with all systems and devices (FAT). In the Name field, type magenta to make it easier to identify in the steps below.
Copy Magenta files to the SD card

See complete story on Github:

$ cd magenta
$ cp ./build-magenta-rpi3-arm64/magenta.bin /media/username/magenta/kernel8.img
$ cp ./kernel/target/rpi3/config.txt /media/username/magenta/config.txt
$ cp ./kernel/target/rpi3/cmdline.txt /media/username/magenta/
$ cp ./kernel/target/rpi3/bcm2710-rpi-3-b.dtb /media/username/magenta/
$ cp ./build-magenta-rpi3-arm64/bootcode.bin /media/username/magenta/
$ cp bootcode.bin /media/username/magenta/
$ cp start.elf /media/username/magenta/
$ ls -a /media/username/magenta/ | sort
  • Note that the ./build-magenta-rpi3-arm64/magenta.bin file is renamed to kernel8.img – this is how it is referred to in config.txt:
$ cat /media/username/config.txt
# Tells the Pi's bootloader which file contains the kernel.

The bootcode.bin and start.elf files are not part of the Magenta build process described above and can be found here and here.

Serial terminal setup

See the Raspberry Pi: serial terminal setup.

Run Magenta

Start screen/putty terminal and power up your Raspberry Pi:

...[00002.007] 01473.01497> LAN9514 - attempting to bind 
[00002.007] 01473.01497> lan9514 returned 3 endpoints 
[00002.021] 01473.02308> Initializing LAN9514... 
[00002.030] 01473.02308> LAN9514 MAC Address b8:27:eb:20:0a:4c 
[00002.045] 01473.02308> LAN9514 Initialized! bmcr=3000  bsr=7809 
[00002.052] 01041.01044> devcoord: drv='ethernet' bindable to dev='smsc-lan9514' 
[00002.062] 01227.01307> netifc: ? /dev/class/ethernet/000 
[00002.073] 01227.01307> netifc: create 128 eth buffers 
[00002.078] 01227.01307> macaddr: b8:27:eb:20:0a:4c 
[00002.078] 01227.01307> ip6addr: fe80::ba27:eb4d:fe20:a4c 
[00002.078] 01227.01307> snmaddr: ff02::1:ff20:a4c 
[00002.079] 01227.01307> netsvc: nodename='carol-grope-cozy-squat' 
[00002.079] 01227.01307> netsvc: start 
[00003.491] 01473.02308> lan9514: Link is up - 782d 
magenta$ ls -l 
d  7        0 . 
d  7        0 .. 
d  9        0 dev 
d  7        0 boot 
d  2        0 tmp 
d  2        0 data 
d  2        0 volume 
d  2        0 svc 

Raspberry Pi: turn on, off, blink the Green ACT LED

  • Ubuntu 16.04 LTS
  • Raspberry Pi 3 Model B
Turn on, off, blink the Green ACT LED
# We need root permissions
$ sudo -i
# Turn On
$ echo none > /sys/class/leds/led0/trigger
$ echo 1 > /sys/class/leds/led0/brightness
# Turn Off, echo none to trigger is not required
$ echo 0 > /sys/class/leds/led0/brightness
# Blink
$ echo timer > /sys/class/leds/led0/trigger


Raspberry Pi: key-based authentication

  • Ubuntu 16.04 LTS
  • Raspberry Pi 3 Model B

Key-based authentication is a nice alternative to username/password-based login. Below is a basic process describing how to generate an RSA key pair and install public key on Raspberry Pi.

For more info see How to configure ssh key-based authentication on a linux server.

Create RSA key pair
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa):        
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
The key fingerprint is:

The key will be created in the ~/.ssh folder by default.

Upload public key to Raspberry Pi
$ cat ~/.ssh/id_rsa.pub | ssh pi@192.168.0.xxx "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

Alternatively, use ssh-copy-id:

$ ssh-copy-id pi@192.168.0.xxx
Key-based authentication

Start ssh session as usually, password will not be required:

$ ssh pi@192.168.0.xxx