Please select To the mobile version | Continue to access the desktop computer version

OrangePi

 Login            
 Register            
Search
Hot search: orangepi
Author: linga51

GPIO library - WiringPi

[Copy link]

2

Threads

144

Posts

870

Credits

Senior member

Rank: 4

Credits
870
Post time 2016-2-15 18:43:08 | Show all posts
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
Post time 2016-2-16 17:33:18 | Show all posts
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 the 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
Post time 2016-2-16 18:35:20 | Show all posts
@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
Post time 2016-2-16 21:11:30 | Show all posts
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 the Code
And I'm sorry for my English ^^

0

Threads

5

Posts

70

Credits

Registered member

Rank: 2

Credits
70
Post time 2016-2-16 21:18:23 | Show all posts
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
Post time 2016-2-16 21:32:39 | Show all posts
digitalRead() doesn't work?

0

Threads

5

Posts

70

Credits

Registered member

Rank: 2

Credits
70
Post time 2016-2-16 21:52:11 | Show all posts
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

870

Credits

Senior member

Rank: 4

Credits
870
Post time 2016-2-17 00:51:09 | Show all posts
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
Post time 2016-2-17 01:47:12 | Show all posts
Are you sure your pins are properly defined as input?

2

Threads

144

Posts

870

Credits

Senior member

Rank: 4

Credits
870
Post time 2016-2-17 09:26:33 | Show all posts
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 the Code
You have to log in before you can reply Login | Register

Points Rules

Archiver|Mobile edition|Darkroom|OrangePi En ( 粤ICP备14086627号-2

2019-12-7 00:12 GMT+8 , Processed in 0.036019 second(s), 20 queries .

Powered by Discuz! X3.2

© 2014-2015 orangepibbs en.

Quick Reply To Top Return to the list