DragonBoard im not able to switch on and off a LED

I want switch on a LED and i decided to use libsoc.

I installed the libsoc in this way…

git clone https://github.com/jackmitch/libsoc.git libsoc.git
cd libsoc.git
autoreconf -i
./configure --enable-board=dragonboard410c
make
make install

and after i compiled the following code:

/************************************************************/
/*                             */
/* Written with libsoc C library              */
/*                             */
/*                             */
/* You can do interrupt programming with this library    */
/*                             */
/************************************************************/

#include <stdio.h>
#include <stdlib.h>

#include "libsoc_gpio.h"
#include "libsoc_debug.h"
#include "libsoc_board.h"

unsigned int GPIO_LED;
unsigned int GPIO_BUTTON;

int last_touch;
int led_state = 0;
int running = 1;
int c=0;
/* This bit of code below makes this example work on all */ 
/* 96Boards, Though you could just call this in main */
__attribute__((constructor)) static void _init()
{
  board_config *config = libsoc_board_init();
  GPIO_BUTTON = libsoc_board_gpio_id(config, "GPIO-A");
  GPIO_LED = libsoc_board_gpio_id(config, "GPIO-C");
 libsoc_board_free(config);
}
/* End of 96Boards special code */

int main()
{
  gpio *gpio_led,*gpio_button;
  int touch;
 
  libsoc_set_debug(0);
  gpio_led = libsoc_gpio_request(GPIO_LED,LS_SHARED);
  gpio_button = libsoc_gpio_request(GPIO_BUTTON,LS_SHARED);
 
  if((gpio_led == NULL) || (gpio_button == NULL))
  {
    return(-1);
  }
  libsoc_gpio_set_direction(gpio_led,OUTPUT);
  libsoc_gpio_set_direction(gpio_button,INPUT);
 
  if((libsoc_gpio_get_direction(gpio_led) != OUTPUT)
  || (libsoc_gpio_get_direction(gpio_button) != INPUT)) 
  {
    return(-1);
  }
  while(running)
  {
     usleep(100000);
     libsoc_gpio_set_level(gpio_led,1);
     usleep(100000);
     libsoc_gpio_set_level(gpio_led,0);

  }

  if(gpio_led || gpio_button)
  {
    printf("apply gpio resource fail!\n");
    libsoc_gpio_free(gpio_led);
    libsoc_gpio_free(gpio_button);
  }
  return EXIT_SUCCESS;
}

the led is connected in this way and viceversa

i noted this:

l ogin as: linaro
linaro@192.168.1.102’s password:

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Tue Mar 21 13:17:47 2017 from 192.168.1.101
-bash: export: `[board]': not a valid identifier
-bash: export: `[GPIO]': not a valid identifier
-bash: export: `GPIO-A=36': not a valid identifier
-bash: export: `GPIO-B=12': not a valid identifier
-bash: export: `GPIO-C=13': not a valid identifier
-bash: export: `GPIO-D=69': not a valid identifier
-bash: export: `GPIO-E=115': not a valid identifier
-bash: export: `GPIO-F=507': not a valid identifier
-bash: export: `GPIO-G=24': not a valid identifier
-bash: export: `GPIO-H=25': not a valid identifier
-bash: export: `GPIO-I=35': not a valid identifier
-bash: export: `GPIO-J=34': not a valid identifier
-bash: export: `GPIO-K=28': not a valid identifier
-bash: export: `GPIO-L=33': not a valid identifier
-bash: export: `GPIO-23=36': not a valid identifier
-bash: export: `GPIO-24=12': not a valid identifier
-bash: export: `GPIO-25=13': not a valid identifier
-bash: export: `GPIO-26=69': not a valid identifier
-bash: export: `GPIO-27=115': not a valid identifier
-bash: export: `GPIO-28=507': not a valid identifier
-bash: export: `GPIO-29=24': not a valid identifier
-bash: export: `GPIO-30=25': not a valid identifier
-bash: export: `GPIO-31=35': not a valid identifier
-bash: export: `GPIO-32=34': not a valid identifier
-bash: export: `GPIO-33=28': not a valid identifier
-bash: export: `GPIO-34=33': not a valid identifier

Hi Vincenzo,

Just for testing, have you tried to toggle the LED from shell?

http://www.96boards.org/documentation/ConsumerEdition/CE-Extras/GPIO/Examples/GPIO_Examples/Example_1.md/
https://www.element14.com/community/people/Workshopshed/blog/2016/05/15/dragonboard-401c-gpio

Also, in the example, the code uses GPIO_C for LED, and I noticed that you have connected the LED on GPIO_L? Just to be safe, can you check if the connections are right?

Best Regards,
Rajan.

@vincenzo

Hello! Glad to see you found your way to the libsoc library.

I have several observations here:

  1. You are using a piece of sample code that requires both a button and an LED. You will not activate GPIO_C(PIN_25) unless you have an input into GPIO_A(PIN_23) [1]

  2. You do not have your LED plugged into GPIO_C(PIN_25) as shown in the code you are compiling. [2]

  3. The low-speed expansion header has an output of 1.8V. This means you are most likely not reaching the voltage requirement to breach the Yellow LED voltage threshold. Please note this is dependent on wavelength, however, even the high end for yellow will be 590nm and 2.2V. [3]

Most red LED will also be very dim, or will not work either. High end of wavelength for red led is 660nm which will allow for 1.8V to break threshold and show light.


To over come these obstacles I would suggest acquiring an appropriate mezzanine board (or sensor kit w/ mezzanine), using a step up resistors, a transistor, or even building an amplifier to achieve your desired voltage using the 1.8V output of the GPIO. [4]

Check out our Coursera Course [5] - This course shows how to build amplifiers and utilize the expansion connector without the need of mezzanine boards


I would be glad to explain this in more detail in OpenHours. If you are able to join, I host a live open forum every Thursday.

www.96Boards.org/OpenHours

Please stop by and bring your questions.

[1]https://github.com/96boards/documentation/blob/master/ConsumerEdition/CE-Extras/GPIO/README.md
[2]https://github.com/96boards/documentation/blob/master/ConsumerEdition/CE-Extras/GPIO/LSExpansionHeader/README.md
[3]http://www.oksolar.com/led/led_color_chart.htm
[4]http://www.96boards.org/products/mezzanine/
[5]https://www.coursera.org/learn/internet-of-things-dragonboard
[5]https://www.coursera.org/learn/internet-of-things-sensing-actuation
[5]https://www.coursera.org/learn/internet-of-things-communication

@vincenzo

I would also suggest installing the libsoc library using the apt-get method.

$ sudo apt-get update
$ sudo apt-get upgrade

$ sudo apt-get install libsoc-dev

the problem was the led with a red led it works! did you connect a DHT11 sensor to the dragon?