0 Replies Latest reply on Jul 20, 2015 1:40 PM by userc_6124

    How to control GPIOs and LEDs

      Controlling GPIOs and LEDs

      This example provides information demonstrating how to use WiConnect, a serial API that sits on top of WICED to use GPIOs to control LEDs on ACKme evaluation boards.

      In WiConnect, a GPIO may have two functions: a standard IO function or an alternate function (such as a system indicator, status GPIO or control GPIO). When a GPIO is configured with an alternate 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 alternate function. If a GPIO is not being used for an alternate 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.

      Note: The full article and others can be found here: ACKme | How to control GPIOs and LEDs

      GPIO Usage

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

       

      WiConnect Session (AMW004-E03 Rev 1)

      > get gpio.usage

      ! # Description

      #10 - Standard I/O

      #11 - Standard I/O

      #13 - UART1 RX

      #14 - UART1 TX

      #17 - SPI CLK

      #18 - SPI MOSI

      #19 - SPI MISO

      #21 - system.indicator.network

      #22 - system.indicator.wlan

       

      LED Control

      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 WiConnect command sequence shown in the table below.

      Note! Don't forget to adjust the GPIO numbers to suit your specific board!

      WiConnect Commands (for AMW004-E03 Rev1)Command Description

      set system.indicator.gpio wlan -1

      set system.indicator.gpio network -1

      save

      reboot

       

      set gpio.alias 21 LED1

      set gpio.alias 22 LED2

       

      gpio_dir LED1 out

      gpio_dir LED2 out

       

      gpio_set LED1 1

      gpio_set LED2 1

       

      gpio_set LED1 0

      gpio_set LED2 0

      <- Disable the wlan system indicator

      <- Disable the network system indicator

      <- Save

      <- Reboot since system indicator functions are setup after a reset

       

      <- Setup a friendly alias for the LED on GPIO 21

      <- Setup a friendly alias for the LED on GPIO 22

       

      <- Set the GPIO direction to output

      <- Set the GPIO direction to output


      <- Turn on LED 1

      <- Turn on LED 2


      <- Turn off LED 1

      <- Turn off LED 2

       

      To re-instate the system indicators, either factory reset the module, or use the following commands.

       

      WiConnect CommandsCommand Description

      gpio_dir LED1 none

      gpio_dir LED2 none


      set system.indicator.gpio wlan LED1

      set system.indicator.gpio network LED2

      save

      reboot

      <- Free up the GPIO aliased to LED1

      <- Free up the GPIO aliased to LED2

       

      <- Set the wlan system indicator GPIO to LED1

      <- Set the wlan system indicator GPIO to LED2

      <- Save

      <- Reboot since system indicator functions are setup after a reset

       

      GPIO Initialization

      To simplify GPIO setup (on boot up), WiConnect provides the option to automatically configure GPIOs with a GPIO configuration script set using the gpio.config_file variable. Alternately, GPIOs may be individually configured for initialization after reset using the gpio.init variable. Don't forget to save & reboot to make sure recent GPIO initialization changes take effect.

       

      Sensors.com

       

       

       

      WICED Studio Wi-Fi/Combo ForumsZentriWICED Studio Wi-Fi/Combo