BBIO input returning strange value

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
mogar
 
Posts: 4
Joined: Mon Jun 01, 2015 8:44 pm

BBIO input returning strange value

Post by mogar »

Hi,

I'm trying to use a BBBrevC with Adafruit_BBIO. When I try to poll a pin for it's value, the returned value is always 397435. I have verified that I can read this pin (both high and low) using node.js through Cloud9 (the basic input example worked). Is there anything I'm doing wrong here?

I updated my install of Adafruit_BBIO today. I also tried restarting the BBB before testing (to see if another script had taken control of the GPIO), but that had the same effect.

Code: Select all

root@beaglebone:/usr/local/share/# python
Python 2.7.3 (default, Mar 14 2014, 17:55:54)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Adafruit_BBIO.GPIO as GPIO
>>> GPIO.setup("P9_14", GPIO.IN)
>>> GPIO.cleanup()
>>> GPIO.input("P9_14")
397435
If I then toggle the pin and read again, I get the same value.

Code: Select all

>>> GPIO.input("P9_14")
397435
Thanks for any help you can give.

User avatar
tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: BBIO input returning strange value

Post by tdicola »

I think you're probably running into an issue with the device tree & pin muxing state on the BBB. Check out the GPIO mapping here http://beagleboard.org/support/bone101 (scroll down to the 'Cape Expansion Headers' section) and you can see by default the pin P9_14 is assigned to the PWM hardware. You likely need to create a custom device tree overlay that turns off the PWM output for that pin and makes it a general purpose GPIO pin. The node.js & Cloud9 environment actually does this device tree manipulation in some cases for you, but the BBIO library doesn't dynamically change the device tree for GPIO pins yet. If you're curious you can see a high level overview of the device tree here: https://learn.adafruit.com/introduction ... e/overview

However an easier thing to do would be to switch to a different pin that's exposed as a GPIO with the default device tree setup. From the pin mapping picture in the above link look for any of GPIO_xx pins, like GPIO_60 on pin P9_12 right above P9_14. That pin should be usable from BBIO without any device tree modifications necessary. Let me know if you run into issues using it, thanks!

User avatar
mogar
 
Posts: 4
Joined: Mon Jun 01, 2015 8:44 pm

Re: BBIO input returning strange value

Post by mogar »

Thanks for the input.

I'm actually already using a device tree overlay (though I'm not totally sure it's correct). This is my .dts file:

Code: Select all

/dts-v1/;
/plugin/;
 
/ {
	compatible = "ti,beaglebone", "ti,beaglebone-black";
 
	part-number = "NRSGate";
	version = "00A0";
	
	exclusive-use =
	    "P9_12",
	    "P9_13",
	    "P9_14",
	    "P9_15",
	    "P9_16",
	    "P9_17",
	    "P9_18",
	    "P9_21",
	    "P9_23",
	    "P9_24",
	    "P9_26",
	    "P9_25",
	    "P9_27",
	    "P9_28",
	    "P9_29",
	    "P9_30",
	    "P9_31";
 
	fragment@0 {
		target = <&am33xx_pinmux>;
		__overlay__ {
			nrsgate: pinmux_nrsgate {
				pinctrl-single,pins = <
							0x078 0x2F  /* P9_12 - GPIO1_28 Mode7, GPIO input */
							0x074 0xF   /* P9_13 - GPIO0_31 Mode7, GPIO output */
							0x048 0x2F  /* P9_14 - GPIO1_18 Mode7, GPIO input */
							0x040 0xF   /* P9_15 - GPIO1_16 Mode7, GPIO output */
							0x04C 0xF   /* P9_16 - GPIO1_19 Mode7, GPIO output */
							0x15c 0xF   /* P9_17 - GPIO0_5  Mode7, GPIO output */
							0x158 0xF   /* P9_18 - GPIO0_4  Mode7, GPIO output */
							0x154 0x2F  /* P9_21 - GPIO0_3  Mode7, GPIO input */
							0x044 0xF   /* P9_23 - GPIO1_17 Mode7, GPIO output */
							0x184 0x2F  /* P9_24 - GPIO0_15 Mode7, GPIO input */
							0x180 0x2F  /* P9_26 - GPIO0_14 Mode7, GPIO input */
							0x1Ac 0x2F  /* P9_25 - GPIO3_21 Mode7, GPIO input */
							0x1A4 0xF   /* P9_27 - GPIO3_19 Mode7, GPIO output */
							0x19C 0x2F  /* P9_28 - GPIO3_17 Mode7, GPIO input */
							0x194 0xF   /* P9_29 - GPIO3_15 Mode7, GPIO output */
							0x198 0xF  /* P9_30 - GPIO3_16 Mode7, GPIO output */
							0x190 0xF  /* P9_31 - GPIO3_14 Mode7, GPIO output */
						      >;
			};
		};
	};
 
	fragment@1 {
		target = <&ocp>;
		__overlay__ {
			NRSGate_helper {
				compatible = "bone-pinmux-helper";
				pinctrl-names = "default";
				pinctrl-0 = <&nrsgate>;
				status = "okay";
			};
		};
	};
};
I've compiled this and loaded it into slots using:

Code: Select all

root@beaglebone:~# dtc -O dtb -o NRS-00A0.dtbo -b 0 -@ NRS-00A0.dts
root@beaglebone:~# cp NRS-00A0.dtbo /lib/firmware
root@beaglebone:~# echo NRS > /sys/devices/bone_capemgr.*/slots
I can then see that my dts file has been loaded:

Code: Select all

root@beaglebone:~# cat /sys/devices/bone_capemgr.9/slots
 0: 54:PF---
 1: 55:PF---
 2: 56:PF---
 3: 57:PF---
 4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G
 5: ff:P-O-L Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI
 7: ff:P-O-L Override Board Name,00A0,Override Manuf,NRSGate
Do you see anything in my .dts file that looks fishy? Any other ideas?

User avatar
paulf8080
 
Posts: 208
Joined: Sat Jan 18, 2014 10:25 pm

Re: BBIO input returning strange value

Post by paulf8080 »

I'm learning, too. Maybe a stupid question, but isn't __override__ used to change the something like PWM, instead of inserting. My problem on the pi device tree is my 'compatible' driver was excluded from raspian and I have been trying to compile it for days.

User avatar
tdicola
 
Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Re: BBIO input returning strange value

Post by tdicola »

Hrm I don't see anything jumping out as a major issue with the overlay, but I'm not really an expert on them either. However one thing to check is what the sysfs interface to GPIO is returning for P9_14 when your overlay is loaded. Check out a page like this for more details on how to access the sysfs GPIO interface: http://falsinsoft.blogspot.com/2012/11/ ... space.html You can interact with the GPIO pins through the filesystem and check what value is being returned (the BBIO library behind the scenes is just using this same sysfs interface to access GPIO).

One thing you might need to the mapping of GPIO names like P9_14 to sysfs GPIO numbers. You can actually find that in the BBIO source, for example here's the mapping for P9_14: https://github.com/adafruit/adafruit-be ... mon.c#L112 The 3rd column, 50, is the GPIO number to use when accessing the pin through sysfs. Try reading the value from sysfs and lets see if that also gives you odd values. If so then perhaps it is an issue with the device tree overlay. The best folks to ping about that would probably be the Beaglebone Black support group here: https://groups.google.com/forum/#!categ ... bone-black

User avatar
mogar
 
Posts: 4
Joined: Mon Jun 01, 2015 8:44 pm

Re: BBIO input returning strange value

Post by mogar »

Thanks for the advice.

I've gone through the filesystem to read my pin, and I can read it just fine. If I use my device tree file, I still have to export the pin in /sys/class/gpio as follows:

Code: Select all

root@beaglebone:/sys/class/gpio# echo 50 > export
Once I do this, I then have access to the pin as expected:

Code: Select all

root@beaglebone:/sys/class/gpio# ls
export  gpio50  gpiochip0  gpiochip32  gpiochip64  gpiochip96  unexport
root@beaglebone:/sys/class/gpio# cd gpio50
root@beaglebone:/sys/class/gpio/gpio50# ls
active_low  direction  edge  power  subsystem  uevent  value
root@beaglebone:/sys/class/gpio/gpio50# cat direction
in
root@beaglebone:/sys/class/gpio/gpio50# cat value
1

And if I change the pin state, I can see it:

Code: Select all

root@beaglebone:/sys/class/gpio/gpio50# cat value
0
However, if I use Adafruit_BBIO library, then I still get the behavior that I described originally.

Code: Select all

root@beaglebone:~# python
Python 2.7.3 (default, Mar 14 2014, 17:55:54)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Adafruit_BBIO.GPIO as GPIO
>>> GPIO.setup("P9_14", GPIO.IN)
>>> GPIO.cleanup()
>>> GPIO.input("P9_14")
397435
>>>
Furthermore, after I exit python, it looks like that GPIO is no longer exported:

Code: Select all

root@beaglebone:~# ls /sys/class/gpio
export  gpiochip0  gpiochip32  gpiochip64  gpiochip96  unexport

Has the adafruit team been able to use the Adafruit_BBIO library in this way for pins that aren't set up by default?

Thanks in advance for any more help you can give me.

User avatar
mogar
 
Posts: 4
Joined: Mon Jun 01, 2015 8:44 pm

Re: BBIO input returning strange value

Post by mogar »

Ok. Here's one more piece to the puzzle.

I've been using the Adafruit_BBIO library to set up interupts on P9_24 and P9_26. Those seem to work well, and I've actually implemented a simple Wiegand interpreter that works correctly.

Code: Select all

GPIO.setup("P9_24", GPIO.IN)
GPIO.setup("P9_24", GPIO.IN)
GPIO.cleanup()

GPIO.add_event_detect("P9_24", GPIO.FALLING, wiegandD0)
GPIO.add_event_detect("P9_26", GPIO.FALLING, wiegandD1)
So that code works. The following code does not work:

Code: Select all

root@beaglebone# python
Python 2.7.3 (default, Mar 14 2014, 17:55:54)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Adafruit_BBIO.GPIO as GPIO
>>> GPIO.setup("P9_24", GPIO.IN)
>>> GPIO.cleanup()
>>> GPIO.input("P9_24")
397435
So it seems to be a problem with the GPIO.input() function, and that doesn't happen with GPIO.add_event_detect()

Any ideas?

User avatar
yrrah
 
Posts: 5
Joined: Wed May 13, 2015 6:41 am

Re: BBIO input returning strange value

Post by yrrah »

The trick is to run the script in sudo!
Cheers,
Harke

Locked
Please be positive and constructive with your questions and comments.

Return to “Beagle Bone & Adafruit Beagle Bone products”