Peripherals

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 Zentri 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 ZentriOS BLE device. This is not to be confused with a Bluetooth peripheral.

GPIOs

GPIO commands allow control of the function and direction of the GPIOs.

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):

GPIO Functions and Pins

In the following examples, the Zentri Wahoo evaluation board is used to demonstrate GPIO functions.

For details of peripherals on specific platforms and evaluation boards, see:

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

Note: The user_rts and 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 stdio:

> 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 status_led function.

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.

For example:

> 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 stdio outputs.

> gdis 666666166133663
Success

With no buttons pressed, get the values of the stdio GPIOs:

> gges
XXXXXX0XX000XX0

Now turn the red LED on:

> gses XXXXXXXXXX00XX1
Success

Press both buttons and get the values of the stdio GPIOs:

> gges
XXXXXX1XX100XX1

ADCs

For these features, you need the ZENTRI-ANALOG product.

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 ZentriOS BLE 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.

PWMs

For these features, you need the ZENTRI-ANALOG product.

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.

LEDs

The level of a LED can be controlled via a GPIO, with either the stdio or pwm function.

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 GPIOLED Color
14Red
10Green
11Blue

These same GPIOs are associated with the Wahoo system indicator LEDs, if fitted.

GPIO control

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:

ZentriOS BLE commandsComments

gfu 10 none
gfu 11 none
gfu 14 none
gfu 10 stdio
gfu 11 stdio
gfu 14 stdio
gdi 10 olo
gdi 11 olo
gdi 14 olo

Free up GPIO 10
Free up GPIO 11
Free up GPIO 14
Assign GPIO 10 to stdio function
Assign GPIO 11 to stdio function
Assign GPIO 14 to stdio function
Set red, green and blue GPIOs to output,
initial level low

Now you can turn on separate red, green and blue leds by setting GPIO values with the gse command. For example:

ZentriOS BLE commandsComments

gse 10 0
gse 11 0
gse 14 1

Turn green off
Turn blue off
Turn red on

PWM control

For this feature, you need the ZENTRI-ANALOG product.

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 low_count and 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.

Speaker

For this feature, you need the ZENTRI-ANALOG product.

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

I2C

For these features, you need the ZENTRI-I2CM (I2C Master) product.

Commands

Variables

SPI

For these features, you need the ZENTRI-SPIM (SPI Master) product.

Commands

Variables