Peripheral commands and variables enable access to general purpose IOs (GPIOs), analog functions such as analog-digital converters (ADCs) and PWMs (Pulse Width Modulators). In the case of the ACKme Wahoo evaluation board, peripherals include the tri-color LED, the speaker, user buttons and the thermistor ADC.
Note that peripheral is used here in sense of an input or output device attached to the TruConnect device. This is not to be confused with a Bluetooth peripheral.
GPIO commands allow control of the function and direction of the GPIOs.
- get gp u - List GPIO usage, direction and initialization.
- gfu - Configure GPIO function
- gdi - Set GPIO direction, for a GPIO functioning as
- gdis - Set
stdiofunction and direction for multiple GPIOs
- gge - Get GPIO value, for a GPIO functioning as
- gges - Get multiple values for GPIOs functioning as
- gse - Set GPIO value, for a GPIO functioning as
- gses - Set multiple values for GPIOs functioning as
Typically, particular GPIOs are hard-wired to components such as LEDs, the speaker, and buttons. Other GPIOs are configurable for input and output.
GPIOs can be used for special system functions, including (but not limited to):
- enabling a speaker for the beep command
- assigning a LED as a BLE connection indicator
- selecting between serial bus modes: COMMAND or STREAM
- pulse width modulator function
- blink on BLE activity
- general standard IO function
GPIO Functions and Pins
The table below shows functions, defaults and pins for the Bobcat GPIOs.
In the following examples, the Wahoo evaluation board is used to demonstrate GPIO functions. The table also shows defaults, connections and header pins for the AMS001-E01.2 Wahoo.
|Bobcat AMS001, AMS002||Wahoo AMS001-E01.2|
for future use as i2c_sda, spi_mosi
|4||Reserved||Do not connect||H1-1|
for future use as i2c_scl, spi_clk
|5||Reserved||Do not connect||H1-2|
|GPIO6||none, factory||11||none, factory||Button 1, factory reset||H1-7|
|GPIO7||Reserved||12||Reserved||Do not connect||H1-8|
|GPIO9||none||14||mode_sel||Button 2, bus mode, wake||H2-6|
|GPIO10||none||ADC||PWM||15||status_led||Blue tri-color LED||H2-5|
|GPIO11||none||ADC||PWM||16||none||Green tri-color LED||H2-4|
|GPIO14||none||ADC||PWM||20||stream_gpio||Red tri-color LED||H2-1|
Viewing GPIO Usage
To see the current GPIO usage, read the GPIO usage variable. The default Wahoo GPIO usage is:
> get gp u ! # Description # 0 i2c_sda # 1 i2c_scl # 2 user_tx # 3 none # 4 none # 5 user_rx # 6 none,factory # 7 reserved # 8 none # 9 mode_sel # 10 status_led # 11 none # 12 none # 13 speaker # 14 stream_gpio
user_cts functions automatically override any other function configured on GPIO2 & GPIO3 when UART flow control is enabled using the ua f variable. The UART flow control functions cannot be set manually using the gfu command.
Setting GPIO Function
Use the GPIO function command to set a single GPIO to a specific function.
After using gfu, it may be necessary to save then reboot depending on the alternate function (some functions are only configured at boot up).
Use gdis command to set
stdio function and direction for multiple GPIOs. See Setting and Getting Multiple STDIO GPIO Values below.
Available functions are listed in the gfu command documentation.
The gfu command fails if the GPIO is already configured for an alternate function. Disable the alternate function first by using
gfu <GPIO#> none.
For example, to disable the beep command and allow the Wahoo speaker GPIO to operate as
> gfu 13 none Success > gfu 13 stdio Success
After these commands,
get gp u lists GPIO 13 as stdio and the beep command fails:
> get gp u ! # Description ... # 13 stdio,hiz ... beep 100 Command failed
To use the Wahoo red LED to indicate when stream mode is on:
> gfu 14 none Success > gfu 14 stream_gpio Success > save Success > reboot
Press Button 2 to toggle between command mode and stream mode. The Wahoo red LED comes on for stream mode. The Wahoo green LED may also be on or blinking, as it defaults to the
Setting and Getting a Single STDIO GPIO Value
To set and get the value of a single GPIO, use the gse and gge commands.
Note that to set a GPIO, the GPIO must have
stdio function and the output direction. To get the value, the GPIO must have
stdio function. See Setting GPIO Function.
> gdi 12 olo Success > gge 12 0 > gse 12 1 Success > gge 12 1
Setting and Getting Multiple STDIO GPIO Values
To set and get multiple
stdio GPIO values, use the gses and gges commands.
For example, for the Wahoo evaluation board, set GPIO 6 (Button 1) and GPIO 8 (Button 2) as
stdio pull-down inputs, and GPIO 10 (green LED), GPIO 11 (blue LED) and GPIO 14 (red LED) as
> gdis 666666166133663 Success
With no buttons pressed, get the values of the
> gges XXXXXX0XX000XX0
Now turn the red LED on:
> gses XXXXXXXXXX00XX1 Success
Press both buttons and get the values of the
> gges XXXXXX1XX100XX1
To read the value from an ADC, use the adc command. For example, to read the Wahoo thermistor ADC value:
> adc 12 1655
The value reported is in mV.
The ADC mV reading accuracy currently available is +/-10%. A future version of TruConnect will provide a calibration facility to improve accuracy to +/-3%.
To determine temperature from the Wahoo thermistor ADC, see Wahoo Thermistor Temperature vs ADC Value table.
The ADC value can be read regardless of the GPIO function setting.
The pwm command provides control of the frequency and duty cycle of a pulse width modulator output. PWMs are associated with specific GPIOs. The lowest possible frequency is about 128Hz, and the highest is 65536Hz.
The GPIO must be set to the
pwm function. See gfu.
PWMs can be used for controlling the user LED and the speaker.
The level of a LED can be controlled via a GPIO, with either the
The example below uses the Wahoo tri-color user LED. This contains a red, green and blue LED, which can be combined to form a wide range of colors:
|Wahoo GPIO||LED Color|
These same GPIOs are associated with the Wahoo system indicator LEDs, if fitted.
The LEDs can be turned on or off individually by configuring them as output GPIOs, then setting the GPIO level.
Note: GPIO 10 (green LED) defaults to the
status_led function on Wahoo. It must be de-assigned to
none before it can be used for another purpose.
To setup the tri-color LEDs:
Now you can turn on separate red, green and blue leds by setting GPIO values with the gse command. For example:
To set the Wahoo tri-colour LED to a color combining the three LEDs, issue three pwm commands, one for each LED GPIO.
First set each of the LED GPIOs to
pwm function with the gfu command:
gfu 10 none gfu 11 none gfu 14 none gfu 10 pwm gfu 11 pwm gfu 14 pwm
The ratio of
high_count arguments determines the duty cycle of the PWM, as described in the pwm command documentation.
The duty cycle impacts the brightness of the LED, lower duty cycles make the LED brighter.
The lowest available PWM frequency, about 128Hz, may be used without any detectable flashing of the LED.
For example, to set the named color 'RebeccaPurple':
pwm 14 614 409 pwm 10 818 205 pwm 11 409 614
The Color PWM Table shows the pwm commands for a sample color range.
A speaker connected to a GPIO can be controlled with the PWM command or using the beep command.
The Wahoo speaker tone is controlled via GPIO 13 and a PWM. The pwm command documentation describes how to set the frequency and duty cycle of the PWM.
To set the
pwm function on GPIO 13:
gfu 13 none gfu 13 pwm
To play a middle C (C4), the command is:
pwm 13 250 250
To turn the note off:
pwm 13 stop
See the Musical Note PWM Table for pwm commands to play a range of notes on the speaker.
The beep command plays a tone of specified length through a speaker. To use this command, the GPIO wired to the speaker must be set to
speaker function with the gfu command. See Setting GPIO Function above.
The following example shows how to set up the Wahoo speaker on GPIO 13 to allow the beep command, assuming GPIO 13 is currently set to another function:
> gfu 13 none Success > gfu 13 speaker Success > save Success > reboot [COMMAND MODE] > beep 100 Success