Controlling GPIOs and LEDs
This example demonstrates how to use GPIOs with ZentriOS in general, and how to use GPIOs to control LEDs on Zentri evaluation boards. For details of using GPIOs and peripherals, see Peripherals.
When a GPIO is configured with an alternative function, the standard IO function is NOT available and the gpio_dir, gpio_set, and gpio_get commands are disabled for that GPIO.
Before a GPIO can be used to control an LED, it is necessary to first check whether the GPIO is being used for an alternative function.
If a GPIO is not being used for an alternative function, but is already in use as a standard GPIO (for another purpose), the GPIO must first be freed up by setting the direction of the GPIO to
none using the gpio_dir command.
The gpio.usage variable makes it easy to get a list of GPIOs that are already in use. The session in the following table shows the GPIO usage after factory reset for a Mackerel Evaluation Board (schematics: AMW004-E03 Rev 1).
|ZentriOS Session (AMW004-E03 Rev 1)
The following example is based on the first revision of a Mackerel evaluation board which only has two LEDs connected to GPIO 21 & 22. These LEDs are factory configured as system indicators to dynamically indicate the state of the Wi-Fi and network connection (as shown in the table above). To repurpose the GPIOs as standard IOs for use with LEDs, try the ZentriOS command sequence shown in the table below.
Note! Don't forget to adjust the GPIO numbers to suit your specific board!
|ZentriOS Commands (for AMW004-E03 Rev1)
To re-instate the system indicators, either factory reset the module, or use the following commands.
Supporting ZentriOS Editions and Versions