Disabling Bluetooth on Raspberry Pi

This post shows steps to 1) disable on-board Bluetooth and 2) disable Bluetooth completely. I tested the steps with Raspbian Stretch (November 2017 version).

Update (Jul 9, 2019): Tested with Raspbian Buster 2019-07-10.

 


Disabling on-board Bluetooth
The steps below shows how to disable on-board Bluetooth and related services. Those steps also disable loading the related kernel modules such as bluetooth, hci_uart, btbcm, etc at boot.

1. Open /boot/config.txt file.

sudo nano /boot/config.txt

2. Add below, save and close the file.

# Disable Bluetooth
dtoverlay=pi3-disable-bt

3. Disable related services.

sudo systemctl disable hciuart.service
sudo systemctl disable bluealsa.service
sudo systemctl disable bluetooth.service

4. Reboot to apply the changes

sudo reboot

Even after disabling on-board Bluetooth and related services, Bluetooth will be available when a Bluetooth adapter (e.g. Plugable Bluetooth Adapter) is plugged in.

 

 


Disable Bluetooth completely
If Bluetooth is not required at all, uninstall Bluetooth stack. It makes Bluetooth unavailable even if external Bluetooth adapter is plugged in.

1. Uninstall BlueZ and related packages.

sudo apt-get purge bluez -y
sudo apt-get autoremove -y

Uninstalling Bluetooth stack also disabling related services, and loading related kernel modules.

 

 

Lightning Bolt (Under-Voltage Warning) on Raspberry Pi

If a lightning bolt image appears in the top-right corner of the screen, it means Raspberry Pi is not getting enough voltage (4.65V according to this forum post). To prevent it from showing up, there are two options.

 

1) Replace Power Supply and/or Cable (Recommended)
In most cases, it’s due to the power supply and/or cable. Replacing those with better one such as CanaKit 5V 2.5A Power Supply or HomeSpot 5V 2.4A Power Supply will most likely fix the problem. I like HomeSpot because it has ON/OFF switch, which is very convenient to power up Raspberry Pi.

 

2) Disable Under-voltage Warning (Not Recommended)
Under-voltage may cause SD card corruption and/or other problems. Disabling the warning won’t make it any better. But if you understand the risk, it can be disabled by the steps below. I tested it with Raspbian Stretch (November 2017 version).

Open /boot/config.txt file.

sudo nano /boot/config.txt

Add below, save and close the file.

# Disable under-voltage warning
avoid_warnings=1

Reboot to apply the change.

sudo reboot

 

 

Silent boot on Raspbian Stretch in Console Mode


Update (May 22, 2019):
Step 5 has been updated to adopt the latest version of Raspbian (2019-04-08).


The purpose of the steps here is to remove Rainbow image, Raspberry Pi Logo, login messages, etc. from Raspberry Pi boot up process when it’s in console autologin mode. For silent boot in desktop mode, please see this post. After following the steps, the first thing you see will be a shell prompt like below.

pi@raspberrypi:~ $

I tested it with Raspberry Pi 3 running Raspbian Stretch with Desktop (2019-04-08).

 

Assumptions

– Console Autologin
If it’s not yet in Console Autologin mode, launch raspi-config.

sudo raspi-config

Then, navigate to “Boot Options” > “Desktop / CLI” and select “Console Autologin“.

– Password change if SSH enabled
If SSH is enabled, change the login password to avoid the warning message below.

SSH is enabled and the default password for the 'pi' user has not been changed. 
This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.

 

Steps

1. Disable “Welcome to PIXEL” splash
Disable plymouth-start service.

sudo systemctl mask plymouth-start.service

 

2. Remove Rainbow Screen
2-1. Open “/boot/config.txt”.

sudo nano /boot/config.txt

2-2. Add below at the end of the file.

# Disable rainbow image at boot
disable_splash=1

 

3. Remove Raspberry Pi logo and blinking cursor
3-1. Open “/boot/cmdline.txt”.

sudo nano /boot/cmdline.txt

3-2. Add below at the end of the line.

logo.nologo vt.global_cursor_default=0

‘logo.nologo’ and ‘vt.global_cursor_default=0’ remove Raspberry Pi logo (image of four raspberries in the top left corner) and blinking cursor, respectively.

 

4. Remove login message
Create ‘.hushlogin’ file in home directory.

touch ~/.hushlogin

It removes login message below [1]:

Last login: Tue Nov 21 14:51:56 2017
Linux raspberrypi 4.9.41-v7+ #1023 SMP Tue Aug 8 16:00:15 BST 2017 armv7l
 
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
 
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

 

5. Remove autologin message by modify autologin service
5-1. Open “getty@tty1.service.d/autologin.conf”.

sudo nano /etc/systemd/system/getty@tty1.service.d/autologin.conf

5-2. Replace the line below:

ExecStart=-/sbin/agetty --autologin pi --noclear %I xterm-256color

with:

ExecStart=-/sbin/agetty --skip-login --noclear --noissue --login-options "-f pi" %I $TERM

It removes autologin message below:

Raspbian GNU/Linux 9 raspberrypi tty1
raspberrypi login: pi (automatic login)

 

6. Verify
Reboot the board and see if it works properly.

sudo reboot

 

Bonus 1: Removing Lightning Bolt Icon
In case a lightning bolt icon is shown in the right-top corner of the screen, see this post.

 

Bonus 2: Removing Bash Prompt
If you want to remove even the bash prompt (e.g. “pi@raspberrypi:~ $”), open .bashrc file.

nano ~/.bashrc

Then add the line below at the bottom of the file.

PS1=""

 

 

References
[1] Remove GNU licence and ‘no warranty’ thing when logging into ssh
[2] Silence and Appliance-ify your RetroPie Installation

 

Setting Up Raspberry Pi Web Kiosk


This post shows steps to setup a web kiosk using Raspberry Pi. The goal is to load a web page using a browser in full-screen kiosk mode directly after boot up.

I tested it with Raspberry Pi 3 B+ running Raspbian Stretch (November 2017 version) with Raspberry Pi official 7″ display. I used Chromium as browser. Also, Internet connection is required since the kiosk access a web site on the Internet.

 

Steps
1. install software
Install unclutter which hides mouse cursor.

sudo apt-get update
sudo apt-get install unclutter -y

 

2. Screen setting
2-1. Create .xinitrc in home directory.

nano ~/.xinitrc

2-2. Copy below lines, save and close the file.

#!/bin/sh

# disable blank screen
xset s off
xset -dpms
xset s noblank

# hide mouse cursor when it's not moving
unclutter -idle 0.1 &

# launch browser
exec chromium-browser --window-size=800,480 --incognito --kiosk --window-position=0,0 https://www.wunderground.com/fullscreenweather

Line 4-6 disables blank screen. [1]
Line 9 enables the mouse pointer only when it’s moving.
The browser loads full-screen weather [2] which is great for kiosk example. (Line 12)
‘incognito’ option disables session restore prompt on Chrome browser. [3] (Line 12)

 

3. Setting for launching browser when login
3-1. Open .bashrc.

nano ~/.bashrc

3-2. Add below lines at the end of the file.

if [ -z "${SSH_TTY}" ]; then
    startx > /dev/null 2>&1
fi

 

At this point, full-screen weather (specified at line 12 in step 2-2) will be shown after boot up. Check it by rebooting the board.
Below steps are to remove unnecessary stuff for kiosk, such as Rainbow image, Raspberry logo, Desktop GUI, login messages, etc

 

4. Disable Desktop Environment (PIXEL/LXDE)
Since desktop environment is not required for kiosk, let’s disable it.

4-1. Launch raspi-config.

sudo raspi-config

4-2. Navigate to “Boot Options” > “Desktop / CLI“, then select “Console Autologin“.

 

5. Disable “Welcome to PIXEL” splash
Disable plymouth-start service.

sudo systemctl mask plymouth-start.service

 

6. Remove Rainbow Screen
6-1. Open “/boot/config.txt”.

sudo nano /boot/config.txt

6-2. Add below at the end of the file.

# Disable rainbow image at boot
disable_splash=1

 

7. Remove Raspberry Pi logo and blinking cursor
7-1. Open “/boot/cmdline.txt”.

sudo nano /boot/cmdline.txt

7-2. Add below at the end of the line.

logo.nologo vt.global_cursor_default=0

‘logo.nologo’ and ‘vt.global_cursor_default=0’ remove Raspberry Pi logo and blinking cursor, respectively.

 

8. Remove login message
8-1. Create ‘.hushlogin’ file in home directory.

touch ~/.hushlogin

It removes login message below [4]:

Last login: Tue Nov 21 14:51:56 2017
Linux raspberrypi 4.9.41-v7+ #1023 SMP Tue Aug 8 16:00:15 BST 2017 armv7l
 
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
 
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

 

9. Remove autologin message by modify autologin service
9-1. Open the unit file for autologin service.

sudo nano /etc/systemd/system/autologin\@.service

9-2. Modify the line starts with “ExecStart”
From:

ExecStart=-/sbin/agetty --autologin pi --noclear %I $TERM

To:

ExecStart=-/sbin/agetty --skip-login --noclear --noissue --login-options "-f pi" %I $TERM

It removes autologin message below:

Raspbian GNU/Linux 9 raspberrypi tty1
raspberrypi login: pi (automatic login)

 

10. Verify
Now, everything should be ready. Reboot the board and see if it works properly.

sudo reboot

 

In case a lightning bolt icon is shown in the right-top corner of the screen, see this post.

 

 

References
[1] How do I prevent the screen from going blank?
[2] https://www.wunderground.com/fullscreenweather
[3] How to hide chrome warning after crash?
[4] Remove GNU licence and ‘no warranty’ thing when logging into ssh
[5] Setup a Raspberry Pi Kiosk with Chromium
[6] How to build a web kiosk with Raspberry Pi and make the SD read-only

 

 

Adding Power Switch on Raspberry Pi


Below shows how I added a physical power switch to Raspberry Pi. It enables boot up, shutdown, and reboot Raspberry Pi board.

Note: This switch does not actually power-up or power-down, and Raspberry Pi board consumes some mA of current even after shutdown (i.e. halt state). To control actual power, additional circuit such as this is required.

Tested with

 

Prerequisites
– Raspberry Pi board (e.g. Raspberry Pi Zero W, Raspberry Pi 4B) running Raspberry Pi OS
– Normally-Open Switch such as this
Jumper wires

 

Steps
1. Wiring
1-1. Solder jumper wires with the switch.

1-2. Connect the wires with GPIO pin 5 & 6. Please refer this site for Raspberry Pi’s GPIO pinout.
Momentarily shorting pin 5 and 6 makes Raspberry Pi booting up from halt state [1]. Also, pin 5 will be used for detecting shutdown and reboot signals from the switch.

 

2. Test wiring
2-1. First, supply power to Raspberry Pi and boot it up.

2-2. Then, shut it down. After the activity LED (green LED) goes off, Raspberry Pi is in halt state.

sudo shutdown -h now

2-3. Push the switch to test. Raspberry Pi should boot up. If not, check the continuity of the switch with multimeter.

 

3. Script for shutdown and reboot
3-1. Create a python script file of any name or location.

sudo nano /usr/local/bin/power-switch.py

3-2. Write a code to detect shutdown and reboot signal.

import threading, subprocess
import RPi.GPIO as GPIO

if __name__ == '__main__':
    try:
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(5, GPIO.IN)
        GPIO.wait_for_edge(5, GPIO.RISING)
        pin = GPIO.wait_for_edge(5, GPIO.FALLING, timeout=3000)
        if pin is None:
            subprocess.call('sudo shutdown -h now', shell=True)
        else:
            subprocess.call('sudo reboot', shell=True)
    finally:
        GPIO.cleanup()

Pushing and holding the switch more than 3 seconds makes Raspberry Pi shutdown, and pushing the switch less than 3 seconds makes it reboot.

 

4. Enable script at boot
4-1. Open /etc/rc.local.

sudo nano /etc/rc.local

4-2. Add a line above “exit 0” to execute the script at boot.

python /usr/local/bin/power-switch.py &

4-3. Reboot.

sudo reboot

 

5. Verify
5-1. Verify reboot by pushing the switch less than 3 seconds when Raspberry Pi is running.

5-2. Verify shutdown by pushing and hold the switch more than 3 seconds when Raspberry Pi is running.

5-3. Verify booting up by pushing the switch when Raspberry Pi is in halt state.

 

References
[1] Wake from Halt

[2] rpi-gpio Event detection

[3] How to add a power button to your Raspberry Pi