Change the Pin that Used by Witty Pi

UPDATE ON 2016.08.03:

This tutorial was written for Witty Pi (1st generation), however the approach can be used on Witty Pi 2 as well. Please kindly notice that, in Witty Pi 2’s software, we do not use wiringPi naming anymore, and instead use BCM naming everywhere. So you will see GPIO-4 is pin 4, and GPIO17 is pin 17 when you are editing Witty Pi 2’s script.


 

By default, Witty Pi uses GPIO-4 to detect the switching off signal and GPIO17 to drive the white LED on board. This configuration works in the major of cases. However, if you are using a third-party board that already uses any of these two pins, you may want to change the pin that used by Witty Pi. Fortunately it is not difficult to achieve.

Change Pin for the White LED

If you want to choose a different pin to drive the white LED on Witty Pi, it is quite simple and basically any available pin could be used for this purpose. Just put the yellow jumper on the “Custom” position, and use a dupont wire to connect the remaining jumper pin and the new pin you selected.

WittyPi_Change_LED_Pin

Then you need to modify the “daemon.sh” file, to use the new pin to light up the white LED on board.

For example, if you wish to use GPIO-18 instead of the default GPIO-17 pin to drive the LED, you will modify the “daemon.sh” file as shown below.

The only change is on line 25 and 26, where we modify the pin number from 0 to 1. Since GPIO-18 is pin 1 in wiringPi, while GPIO-17 is pin 0 in wiringPi.

Change Pin for Switching Off Your Pi

By default Witty Pi listens to GPIO-4 (pin 7 in wiringPi). If it drop to low voltage, Witty Pi will start the shutdown procedure. If you want to use a different pin for this purpose, you need to choose a pin that:

  • gets initiated as input pin
  • has default HIGH state

How to find a good alternative pin? The simplest way I found is to run “gpio readall” after starting your Pi. It will print out all pin status in a very clean way:

WittyPi_GPIO_State

Here we choose GPIO-8 to replace GPIO-4. The wiring looks like this:

WittyPi_Change_Pin

The last step is to update the “daemon.sh” script. Here is the modified code:

Only line 21 and 22 are changed, please notice that GPIO-8 is pin 10 in wiringPi, while GPIO-4 is pin 7 in wiringPi.

That’s it, after rebooting your Witty Pi will be functional with the new pins :-D

 

See also