please choosego to mobile | Continue to access the PC version
Author: linga51

GPIO library - WiringPi

[Copy link]

2

threads

144

posts

1066

credits

Gold member

Rank: 6Rank: 6

credits
1066
Published in 2016-2-15 18:43:08 | Show all floors
sauberpauli replied at 2016-2-15 17:24
The orginal wiringpi.com uses polling tooo ... not realy interrupts. See source code of wiringpi ...

You are incorrect. As http://wiringpi.com/reference/priority-interrupts-and-threads/ quite well demonstrates, Wiringpi does use interrupts. The sysfs GPIO-interface does allow you to trigger an interrupt on pin-changes and that's what Wiringpi uses. I recommend reading about the sysfs-interface to GPIO, seeing examples like e.g. http://elinux.org/EBC_Exercise_11_gpio_Polling_and_Interrupts and https://www.linux.com/learn/tuto ... -through-linux-gpio and Googling.

2

threads

19

posts

110

credits

Registered member

Rank: 2

credits
110
Published in 2016-2-16 17:33:18 | Show all floors
I am trying to use the OrangePI for domotica and have connected a 433Mhz receiver to it. With opensource software there is an RFSniffer to receive signals from 433mhz devices. This opensource software is based on wiringPI. But in the altered version for orangePi the following part is in the code (wiringpi.c)

  1. if (sysFds [bcmGpioPin] == -1)
  2.   {
  3.     sprintf (fName, "/sys/class/gpio/gpio%d/value", bcmGpioPin) ;
  4.     if ((sysFds [bcmGpioPin] = open (fName, O_RDWR)) < 0)
  5.       return wiringPiFailure (WPI_FATAL, "wiringPiISR: unable to open %s: %s\n", fName, strerror (errno)) ;
  6.   }
Copy code


Here you can see that it uses the gpio directory instead of gpio_sw,  does anybody know if we alter this it will work on the gpio_sw sysfs? Or does anybody has a solution on orangepi to work with the 433mhz receiver on gpio?

12

threads

30

posts

150

credits

Registered member

Rank: 2

credits
150
Published in 2016-2-16 18:35:20 | Show all floors
@WereCatf  
I was looking into hardware pwm and thought I could use the sunxi_pwm module,
I had a look the H3 manual, and I think only PA5 is usable (serial boot connector)
I had no luck executing the sunxi_pwm module (filesystem with PWM0 is not created).
The fex file does not set the port correctly to pwm nor the pwm register.
I think it should be possible though! I attached a LED to PA5 and modified dataregister
(p 317 H3 manual  011 PWM0)
However it would not boot with the LED attached ...

@sauberpauli
I had a look at wiringOP
https://github.com/zhaolei/WiringOP/blob/h3/wiringPi/wiringPi.c
Here I found
#define SUNXI_PWM_BASE (0x01c20e00)
in the H3 manual P.188 they state it should be 0x01C21400?
furthermore they refer to channel1
(SUNXI_PWM_CH1_EN)
whereas in the manual they refer to channel 0




0

threads

5

posts

70

credits

Registered member

Rank: 2

credits
70
Published in 2016-2-16 21:11:30 | Show all floors
Edited by Impressive at 2016-2-16 21:15
phreon replied at 2015-12-23 03:19
I downloaded the wiringpi from the link in jacer post above. Credict goes to Zhaolei or sauberpauli. ...

So, I downloaded the wiringpi from the link: https://github.com/zhaolei/WiringOP

I have OrangePi2, it's work!
I connect LED+transistor between physical pin 7 and physical pin 11(ground)

Then I can switch on/off the LED with this C code:
  1. #include <wiringPi.h>
  2. #include <stdio.h>

  3. int main(void)
  4. {
  5.   wiringPiSetup();
  6.   pinMode(6, OUTPUT);
  7.   for (;;)
  8.   {
  9.     digitalWrite(6, HIGH);
  10.     delay(500);
  11.     digitalWrite(6, LOW);
  12.     delay(500);
  13.   }
  14.   return 0;
  15. }
Copy code
And I'm sorry for my English ^^

0

threads

5

posts

70

credits

Registered member

Rank: 2

credits
70
Published in 2016-2-16 21:18:23 | Show all floors
But I don't know how read data from gpio with this library. Can somebody help me?

12

threads

99

posts

375

credits

Intermediate member

Rank: 3Rank: 3

credits
375
Published in 2016-2-16 21:32:39 | Show all floors
digitalRead() doesn't work?

0

threads

5

posts

70

credits

Registered member

Rank: 2

credits
70
Published in 2016-2-16 21:52:11 | Show all floors
Edited by Impressive at 2016-2-16 21:55
cbm80 replied at 2016-2-16 21:32
digitalRead() doesn't work?

So, I tried the digitalRead(), prorgam compile d, but it didn't work. I think I need something else, somthing like pullup or bcm2835_gpio_pud(PIN_IN, 1); from RaspberryPi. Maybe my code is awful



2

threads

144

posts

1066

credits

Gold member

Rank: 6Rank: 6

credits
1066
Published in 2016-2-17 00:51:09 | Show all floors
Impressive replied at 2016-2-16 21:52
So, I tried the digitalRead(), prorgam compile d, but it didn't work. I think I need something else ...

You need to know whether you need a pull-up resistor or a pull-down resistor. If whatever you've connected to the pin is active on LOW then you need a pull-up, and if it's active on HIGH then you need a pull-down.

12

threads

99

posts

375

credits

Intermediate member

Rank: 3Rank: 3

credits
375
Published in 2016-2-17 01:47:12 | Show all floors
Are you sure your pins are properly defined as input?

2

threads

144

posts

1066

credits

Gold member

Rank: 6Rank: 6

credits
1066
Published in 2016-2-17 09:26:33 | Show all floors
I got fed up and took a look at this stuff. I fixed WiringOP to support interrupts and at least in my simple test - program it's working fine -- just make sure you don't have gpio-sunxi - module loaded! Grab the fix from https://github.com/WereCatf/WiringOP if you want to test. Here's a snippet that I tested it with (compile with gcc -o wpi wpi.c -lpthread -lwiringPi):
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <errno.h>
  4. #include <stdlib.h>
  5. #include <wiringPi.h>

  6. // Button connected to PG07, ie. WPi-pin 16
  7. #define BUTTON_PIN 16

  8. // the event counter
  9. volatile int eventCounter = 0;

  10. // -------------------------------------------------------------------------

  11. void myInterrupt(void) {
  12.    eventCounter++;
  13. }

  14. // -------------------------------------------------------------------------

  15. int main(void) {
  16.   // sets up the wiringPi library
  17.   if (wiringPiSetup () < 0) {
  18.       fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno));
  19.       return 1;
  20.   }

  21.   // set Pin 17/0 generate an interrupt on high-to-low transitions
  22.   // and attach myInterrupt() to the interrupt
  23.   if ( wiringPiISR (BUTTON_PIN, INT_EDGE_FALLING, &myInterrupt) < 0 ) {
  24.       fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno));
  25.       return 1;
  26.   }

  27.   // display counter value every second.
  28.   while ( 1 ) {
  29.     printf( "%d\n", eventCounter );
  30.     eventCounter = 0;
  31.     delay( 1000 ); // wait 1 second
  32.   }

  33.   return 0;
  34. }
Copy code
You need to log in before you can reply login | Register

Points Rule

Quick reply Top Return list