H.A
Posts: 11
Joined: Thu Dec 17, 2015 8:26 am

GPIO LED

Thu Dec 17, 2015 9:31 am

Hello there, and sorry for poor English.
I'm using rpi2 and FreeBSD 11 for my own bike and i want to run some sensors with my rpi2 board.
I have just two 'ON' gpio pins 35 and 47 in my test, so the question is how can i turn on the other pins.
Unfortunately the pin 31 has no normal behavior ! any attempt to on/off this pin will cause to crash my board.
My script to test :

Code: Select all

for ((i=0;i<31;i++));do gpioctl -f /dev/gpioc0 -t $i ;done
for ((i=32;i<55;i++));do gpioctl -f /dev/gpioc0 -t $i ;done

Code: Select all

[email protected] :: rpi2 :: ~ # gpioctl -l 
pin 00: 0       pin 0<>
pin 01: 0       pin 1<>
pin 02: 1       pin 2<>
pin 03: 1       pin 3<>
pin 04: 1       pin 4<IN>
pin 05: 1       pin 5<IN>
pin 06: 1       pin 6<IN>
pin 07: 1       pin 7<>
pin 08: 1       pin 8<>
pin 09: 0       pin 9<>
pin 10: 0       pin 10<>
pin 11: 0       pin 11<>
pin 12: 0       pin 12<IN>
pin 13: 0       pin 13<IN>
pin 14: 1       pin 14<>
pin 15: 1       pin 15<>
pin 16: 0       pin 16<IN>
pin 17: 0       pin 17<IN>
pin 18: 0       pin 18<IN>
pin 19: 0       pin 19<IN>
pin 20: 0       pin 20<IN>
pin 21: 0       pin 21<IN>
pin 22: 0       pin 22<IN>
pin 23: 0       pin 23<IN>
pin 24: 0       pin 24<IN>
pin 25: 0       pin 25<IN>
pin 26: 0       pin 26<IN>
pin 27: 0       pin 27<IN>
pin 28: 1       pin 28<IN>
pin 29: 1       pin 29<IN>
pin 30: 0       pin 30<IN>
pin 31: 1       pin 31<OUT>
pin 32: 0       pin 32<OUT>
pin 33: 0       pin 33<IN>
pin 34: 1       pin 34<IN>
pin 35: 1       gpioled0<OUT>
pin 36: 1       pin 36<IN>
pin 37: 0       pin 37<IN>
pin 38: 0       pin 38<OUT>
pin 39: 0       pin 39<IN>
pin 40: 0       pin 40<>
pin 41: 0       pin 41<OUT>
pin 42: 1       pin 42<IN>
pin 43: 1       pin 43<IN>
pin 44: 1       pin 44<>
pin 45: 0       pin 45<>
pin 46: 1       pin 46<IN>
pin 47: 0       gpioled1<OUT>
pin 48: 0       pin 48<>
pin 49: 1       pin 49<>
pin 50: 1       pin 50<>
pin 51: 1       pin 51<>
pin 52: 1       pin 52<>
pin 53: 1       pin 53<>

H.A
Posts: 11
Joined: Thu Dec 17, 2015 8:26 am

Re: GPIO LED

Fri Dec 18, 2015 12:48 pm

I found a "C" code to deal with GPIO, the gpio command wil run correctly if i change state of any pin with this code.
The ds18b20 sensor does not work yet, and the question is WHY.

C code to deal with gpio,

Code: Select all

#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");

#include <fcntl.h>
#include <paths.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <sys/gpio.h>

void usage ( void )  {
  fprintf ( stderr, "Usage: pin [0|1]\n" );
  exit(1);
}

int main ( int argc, char **argv )  {

  int pin, val, fd;
  char ctlfile[] = _PATH_DEVGPIOC "0";
  struct gpio_pin gpiopin;
  struct gpio_req gpioreq;

  if ( argc != 3 )  usage();
  sscanf( argv[1], "%d", &pin );
  sscanf( argv[2], "%d", &val );

  if ( (val != 0) && (val != 1) )  {
    fprintf ( stderr, "Invalid pin value: %d\n", val );
    exit(1);
  }

  printf ( "pin .. %d, val .. %d\n", pin, val );

  if ( (fd = open(ctlfile, O_RDONLY)) < 0 )  {
    perror("open");
    exit(1);
  }

  gpiopin.gp_pin = pin;
  gpiopin.gp_flags = GPIO_PIN_OUTPUT;
  if ( ioctl(fd, GPIOSETCONFIG, &gpiopin) < 0 )  {
    perror("ioctl(GPIOSETCONFIG)");
    exit(1);
  }

  gpioreq.gp_pin = pin;
  gpioreq.gp_value = val;
  if ( ioctl(fd, GPIOSET, &gpioreq) < 0 )  {
    perror("ioctl(GPIOSET)");
    exit(1);
  }

  close(fd);
  exit(0);
}

Code: Select all


[email protected] :: rpi2 :: ~ # digitemp_DS9097 -i -s /dev/cuau0
DigiTemp v3.6.0 Copyright 1996-2007 by Brian C. Lane
GNU Public License v2.0 - http://www.digitemp.com
owAcquire: failed to open device: Device busy
Error 23: Failed to acquire a necessary system resource

User avatar
joan
Posts: 14196
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: GPIO LED

Fri Dec 18, 2015 1:50 pm

The only GPIO you ought to change on a Pi2 are GPIO 2-27, 35, 38, and 47.

H.A
Posts: 11
Joined: Thu Dec 17, 2015 8:26 am

Re: GPIO LED

Fri Dec 18, 2015 2:28 pm

Problem is not "what port", is change or not, if i understand correctly.
The gpioctl command in my FBSD does not change any thing until i change it by the "C" code.

User avatar
joan
Posts: 14196
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: GPIO LED

Fri Dec 18, 2015 2:30 pm

H.A wrote:Problem is not "what port", is change or not, if i understand correctly.
The gpioctl command in my FBSD does not change any thing until i change it by the "C" code.
Sorry, I misunderstood the problem. I know nothing about gpioctl.

Return to “FreeBSD”