Raspberry Pi Zero W: Enable/disable Wireless Connections (WiFi/Bluetooth) Easily

For some projects it can be useful to easily enable or disable the wireless connections such as WiFi or Bluetooth on a Raspberry Pi Zero W. Whenever power is supposed to be saved and the wireless connections are not required, why not simply turn them off?
And turn them on again once they come in useful again? Without the need to use a display and a keyboard?

The rfkill command can be used to ’softblock‘ the wireless connections:

rfkill block wifi
rfkill block bluetooth

rfkill list              # displays the state of the modules

But this does not turn the hardware of the WiFi and the Bluetooth module off. They will still draw a little power in the background although the connections are cut.

Idea

An idea to disable the wireless hardware on the Raspberry Pi Zero W is to block the drivers during boot of the operating system. This can be achieved by blacklisting in the file /etc/modprobe.d/raspi-blacklist.conf :

# WiFi
blacklist brcmfmac
blacklist brcmutil
# Bluetooth
blacklist btbcm
blacklist hci_uart

The file /etc/modprobe.d/raspi-blacklist.conf can be exchanged on the push of a button.

Hardware

To connect a pushbutton to the Pi follow the instructions in this blog entry.

Software

Sudo copy the files raspi-blacklist.conf_Wireless and raspi-blacklist.conf_noWireless into /etc/modprobe.d .

To launch the button control script controlWirelessConnections.py automatically after boot add this to /etc/rc.local just before the line ‚exit 0‘:

sudo python /home/pi/controlWirelessConnections.py&

That’s it basically.

Basic Observations

I observed the CPU temperature when wireless connections were turned on and off. The CPU temperature was approx. 2.5 degrees Celsius lower when the wireless connections were turned off.

The power consumption was approx. 0.2 W lower without wireless connections. On the long term this may help improve the lifetime of battery powered projects.

This procedure might work on a Raspberry Pi 3 too. However, I have not tested this.

Advertisements

bluetooth sunrise alarm clock + iRise smartphone app

idea

This time I had the idea of creating a sunrise alarm clock. I know they are available for buying, but still I wanted to create my very own version.

My idea was to use an Arduino microcontroller and some RGB LEDs. The sunrise alarm clock should work without a display. A smartphone app should be used to connect via bluetooth to the alarm clock. The smartphone app should be able to set the time, the alarm, steer the LEDs, etc. .

make it happen

With an example I figured out how to create a ’normal‘ Arduino alarm clock using an RTC. This example was easily adapted to steer the RGB LEDs and to integrate the HC-06 bluetooth controller.

principal scheme of hardware setup + working mode

IMG_20151128_114853_principalscheme

I left out the on/off switch and the battery in the basic scheme. It is obvious.

It is definitely recommended to change the name and the PIN of the bluetooth module as described in the bluetooth cookbook.

Switching the alarm on at the time desired was easy. But how to turn the alarm (light) off again? Using the smartphone might be tricky in the morning. I was also thinking of a proximity or a light sensor but this could be error-prone. The next best thing I thought of was a capacitative touch sensor instead of a switch. In the end I realized three possibilities to turn the alarm off:

  • using a simple capacitative touch sensor
  • using the iRise app to send the off command
  • an automatic timeout

The bluetooth controller is connceted to the Arduino as a serial device. A simple Serial.read() does the trick and reads the characters sent via bluetooth. Sending data back is possible using the Serial.write() function.
Before creating a dedicated smartphone app the bluetooth connection can be tested with a bluetooth terminal app from the play store.

protocol

I invented some codes for communication via bluetooth to steer the basic functionality of the alarm clock such as

  • setting the actual time: i12:34z
  • setting the alarm time: s07:30z
  • stopping the alarm: tz
  • turning the RGB LEDs on: c0..9z
  • sending back the current time of the clock: bz

The character ‚z‘ marks the end of a command.

Since I do not want to give anyone the possibility to launch „Denial-of-Sleep“-attacks I will not publish the codes I really use. 🙂

libraries

To avoid a long and confusing Arduino program it is possible to create C++ libraries. For the alarm clock functionality and driving the RGB LEDs I created two simple Arduino libraries.

hardware

In the end I transferred the project to a clone of an Arduino Pro Mini. This small plate has all the required connections and has a minimal size for a reasonable prize.

iRise smartphone app

The smartphone app ‚iRise‘ is pretty straightforward. I decided to go for plain Material design. On http://www.androidhive.info/2015/04/android-getting-started-with-material-design/ I found a good example to start with.
Numerous examples explain how to find and pair a bluetooth device. E.g. http://www.tutorialspoint.com/android/android_bluetooth.htm or http://examples.javacodegeeks.com/android/core/bluetooth/bluetoothadapter/android-bluetooth-example/ explain everything.

rainbow and mood light

The bluetooth sunrise alarm clock can do some more: it also serves as a mood light. Several single colors can be selected in the app. Alternatively a rainbow color change or blueish night mode can be switched on.

The bluetooth state is displayed on another fragment of the app.

extending iRise

Another idea for extension is to capture smartphone notifications such as calendar reminders or incoming messages. Such notifications could trigger the sunrise alarm clock to blink in a dedicated color. This could be solved using a service and a user activated listener as well as the smartphone to be near the alarm clock for a working bluetooth connection.

Another possible extension is to measure the battery voltage to estimate the remaining battery time.

components used

Clone of Arduino Pro Mini 
Lilypad RGB LEDs
RTC – real time clock module
HC-06 bluetooth module
capacitative touch sensor
rechargeable 3.7 V battery
slide switch
buzzer
cables
FTDI cable
for development and testing: Arduino Uno
a box for the clock

For simplicity I used the Lilypad RGB LEDs. They bring the required resistance along. But any other RGB LED or even a RGB LED strip (5V!) will do as well.

software development

Arduino IDE from https://www.arduino.cc/en/Main/Software
Android Studio from http://developer.android.com/sdk/index.html

good to know

Whenever the Arduino sketch is transferred to the board the bluetooth adapter may not be running because it is using the serial connections. Simply remove the power of the HC-06 before the software upload starts and put it back afterwards if required. A reversible connection between the VCC input of the bluetooth module and the power source is a good solution for software updates.

During development it might help a lot to attach an LDC display the the Arduino to display the current settings of the alarm clock.

some pictures and a screenshot

 

source code examples

sunriseclock.ino

AlarmClock

RGBLED

BluetoothUtils.java

construction of a box

This was not simple. One of the first ideas was to construct a paper box. But this is not a durable solution. So the box will be -under construction- for a while! Maybe it will be a wooden box with an acrylic glas top in the end.

references

https://github.com/pAIgn10/AlarmClock

http://arduino-hannover.de/2013/07/20/bluetooth-kochbuch-fur-arduino/

http://lilypadarduino.org/?page_id=548

https://www.arduino.cc/