ACKme BLE modules control peripheral devices via GPIOs (General Purpose Input Output devices). GPIO commands and variables enable access to GPIOs, to control and monitor 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.
- GPIO commands and variables:
- Controlling LEDs
- Controlling a speaker
For more on controlling peripherals, see Peripherals.
GPIO Functions and Pins
See Peripherals, GPIO Functions, Defaults and Pins table for the functions and defaults of the Bobcat and Wahoo GPIOs.
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
Speakers and LEDs can be controlled with a PWM (Pulse Width Modulator) output. The pwm command provides control of the frequency and duty cycle of a PWM output. PWMs are associated with specific GPIOs.
To use a GPIO as a PWM, any existing function on the GPIO must be de-assigned, with the command
gfu <GPIO> none. The the GPIO is set to the
pwm function with the command
gfu <GPIO> pwm. Then the pwm command assigns the frequency and duty cycle.
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 provide 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.
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