Skip to main content Link Menu Expand (external link) Document Search Copy Copied

[gpio]

The GPIO section provides support for up to 5 inputs using GPIO16 to GPIO21 which can be used to control a BooleanGauge. These are the pins that are broken out on the SDC I/O Hat.

Example:

[gpio]
gpio0=19            ; this defaults to pulldown
gpio1=20.pu         ; this is a pullup
gpio2=21.pd         ; pulldown - same as if not specified.

This example enables GPIO19, GPIO20 and GPIO21. These GPIO’s will be set up by the application to detect a change in the edge of the pin (either high or low), and when this happens the value in the associated gauge attribute will change to 1 when the pin is high and 0 when the pin is low. SDC enables the internal pullup or pulldown on the pin as specified, which changes the default state when the pin is open circuit.

gpio<x> entries must start at 0. There is no checking to ensure that the GPIO number you specify on the right of the equals is a valid one. See the Raspberry Pi header pinout for valid values. If you are using the SDC I/O Hat then there is a subset of GPIO’s available on the breakout pin header. Additional pins can be accesed via the solder joints on the top of the 40 pin connector but beware that some of them may already be in use for Canbus or Serial.

If you are using a [buttons] entry, then you should not also specify a GPIO entry for the same pin. GPIO’s used by [buttons] are associated with actions, and although there is nothing to stop you doing so, using the GPIO pin used by a button as an attribute doesn’t really serve a useful purpose. GPIO entries are really for reading values of switches etc.

You must be careful to electrically isolate anything you are using as an input, such as an indicator switch, from the Pi as these will use voltages that will destroy the inputs on your Pi. Opto-isolators are a common method of doing this.

The following gauge example uses a GPIO as its reference.

<gauge>
    <name>gpio20</name>
    <type>BooleanGauge</type>
    <x>50</x>
    <y>650</y>
    <radius>40</radius>
    <bitvalue>1</bitvalue>
    <attribute>gpio20</attribute>
    <colours>red</colours>
    <onbitmap>redon.bmp</onbitmap>
    <offbitmap>redoff.bmp</offbitmap>
    <flashfrequency>500</flashfrequency>
    <visible>1</visible>
</gauge>

This particular example has a non-zero flash frequency defined but this is not absolutely necessary. As you can see it is attached to gpio20. One thing that is important is that the ‘bitvalue’ must be set to 1, as the underlying value will toggle between 0 and 1 when the GPIO changes state.

Although it is possible to attach a GPIO to a ValueGauge there isn’t really much point in doing so as it can only have a value of either 1 or 0.

As with all inputs on the Raspberry Pi, you must be careful if you connect an input which switches between a voltage and ground rather than open circuit and ground. The Pi’s inputs are only safe up to 3.3 volts.

If you are using a rotary encoder with the SDC I/O hat then some of the pins available for GPIO will likely be used for the rotary encoder. You cannot use a pin twice obviously, so be careful which inputs you have configured across these two functions. Similarly, for your ground you must make sure all grounds are connected to each other to avoid ground offsets.