I recently purchased a Raspberry Pi version B+, a PiTFT with capacitive touch, some microswitches, a power supply, and a pre-loaded NOOBS SDCARD from you. Very convenient to get everything from one place!
I'm using the TFT without X, talking directly to the framebuffer device, and that works fine. SImilarly, I can read the touch panel input by talking to the touchscreen event input device.
However, although I soldered the GPIO micro switches onto the circuit board, I cannot get the GPIO system devices to return anything other than 0 for value.
Here's what I do:
echo 22 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio22/direction
while true; do cat /sys/class/gpio/gpio22/value; sleep 0.3; done
This just prints a row of 0s no matter whether I push the button or not.
What's going on? Did the GPIO numbers change with the B+?
Can't get GPIO on PiTFT to work
Moderators: adafruit_support_bill, adafruit
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
- adafruit_support_mike
- Posts: 67454
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Can't get GPIO on PiTFT to work
No, the pinouts are the same for the B and B+ over that part of the GPIO header.
Could you post a photo of the PiTFT please? Let's make sure the connections are all good there.
Could you post a photo of the PiTFT please? Let's make sure the connections are all good there.
- jwatte
- Posts: 53
- Joined: Thu May 31, 2012 11:25 pm
Re: Can't get GPIO on PiTFT to work
Thanks for the answer! I think the connections are OK. Here are photos:
(I had a number four but the forums denied me. Hope this is enough.)
(I had a number four but the forums denied me. Hope this is enough.)
- jwatte
- Posts: 53
- Joined: Thu May 31, 2012 11:25 pm
Re: Can't get GPIO on PiTFT to work
I have also used a continuity tester from the tops of the appropriate GPIO pins (on the header) to a ground test point, and made sure that there is no connection when buttons are not pressed, and there is connection when buttons are pressed.
Thus, this either means there is no pull-up on the GPIO pins, or there is a software problem somewhere.
I notice that I have only one "gpiochip" (the bcm chip) which I think means there's no soft control of the backlight?
I believe it's supposed to be shown as a second GPIO chip? Is this correct, and is this a problem, or is this as expected?
Measuring the top of the switches when the device is on and plugged in shows only 0.45-0.6V voltage. If this is supposed to be a pull-up, it's off by about 2.7V...
Thus, this either means there is no pull-up on the GPIO pins, or there is a software problem somewhere.
I notice that I have only one "gpiochip" (the bcm chip) which I think means there's no soft control of the backlight?
I believe it's supposed to be shown as a second GPIO chip? Is this correct, and is this a problem, or is this as expected?
Measuring the top of the switches when the device is on and plugged in shows only 0.45-0.6V voltage. If this is supposed to be a pull-up, it's off by about 2.7V...
- jwatte
- Posts: 53
- Joined: Thu May 31, 2012 11:25 pm
Re: Can't get GPIO on PiTFT to work
On an Arduino, there exist built-in pull-up resistors, so a momentary button that goes to ground when pressed is all I need to make a user interface.
Some ARM microcontrollers have even fancier GPIOs, with selectable pull-ups, pull-downs, open-gate, and other configurations.
The Raspberry Pi GPIO, however, is less fancy, and is just an open-gate input (at least in the way that's configurable for the Linux device drivers.) It is up to the external circuitry to pull the pin up or down depending on whether I want a 1 or 0.
The "shield" that I got for the PiTFT capacitive touch screen with GPIO button mounts seems to not provide pull-up resistors -- it only provides a path from the GPIO pin to the button, which can connect the pin to ground.
This means that when the button isn't pressed, the GPIO pin is floating freely. In some environments, with some creep voltage or static build-up or whatever, this might represent a "1" on the GPIO input. In others, it will cause random flapping of the I/O pin. And, in others, it will generally leak to ground and thus read as "0" no matter what.
I developed a patch for this problem, which you can see in this photo:
For the buttons to work right, the shield needs to have pull-up resistors. If the shield is supposed to have pull-ups, then my shield is defective. (Could you send me just the circuit board? I can re-plug the display from the old one.)
If the shield does not have built-in pull-up resistors, then everyone wishing to use these GPIO buttons will need to apply the same patch as I did. (4x 22 kOhm resistors, some shrink tubing, and soldering the high end of each button to the 3.3V supply on the Raspberry Pi.)
It would be great to understand which of these two is the actual case!
Some ARM microcontrollers have even fancier GPIOs, with selectable pull-ups, pull-downs, open-gate, and other configurations.
The Raspberry Pi GPIO, however, is less fancy, and is just an open-gate input (at least in the way that's configurable for the Linux device drivers.) It is up to the external circuitry to pull the pin up or down depending on whether I want a 1 or 0.
The "shield" that I got for the PiTFT capacitive touch screen with GPIO button mounts seems to not provide pull-up resistors -- it only provides a path from the GPIO pin to the button, which can connect the pin to ground.
This means that when the button isn't pressed, the GPIO pin is floating freely. In some environments, with some creep voltage or static build-up or whatever, this might represent a "1" on the GPIO input. In others, it will cause random flapping of the I/O pin. And, in others, it will generally leak to ground and thus read as "0" no matter what.
I developed a patch for this problem, which you can see in this photo:
For the buttons to work right, the shield needs to have pull-up resistors. If the shield is supposed to have pull-ups, then my shield is defective. (Could you send me just the circuit board? I can re-plug the display from the old one.)
If the shield does not have built-in pull-up resistors, then everyone wishing to use these GPIO buttons will need to apply the same patch as I did. (4x 22 kOhm resistors, some shrink tubing, and soldering the high end of each button to the 3.3V supply on the Raspberry Pi.)
It would be great to understand which of these two is the actual case!
- jwatte
- Posts: 53
- Joined: Thu May 31, 2012 11:25 pm
Re: Can't get GPIO on PiTFT to work
Ping!
Is this a design defect or a problem only with the board I've got?
Is this a design defect or a problem only with the board I've got?
- jwatte
- Posts: 53
- Joined: Thu May 31, 2012 11:25 pm
Re: Can't get GPIO on PiTFT to work
I would still like a reply.
Should I email support instead?
Should I email support instead?
- adafruit_support_mike
- Posts: 67454
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Can't get GPIO on PiTFT to work
Hi - sorry for the late reply. I thought I'd posted one earlier but it obviously isn't here.
The RasPi's CPU has built-in, configurable pull-up and pull-down resistors on all its GPIO pins:
http://sourceforge.net/p/raspberry-gpio ... ki/Inputs/
You don't need external pull-ups, you just need to enable the built-in one you want.
The RasPi's CPU has built-in, configurable pull-up and pull-down resistors on all its GPIO pins:
http://sourceforge.net/p/raspberry-gpio ... ki/Inputs/
You don't need external pull-ups, you just need to enable the built-in one you want.
- jwatte
- Posts: 53
- Joined: Thu May 31, 2012 11:25 pm
Re: Can't get GPIO on PiTFT to work
Thanks for the suggestion. I'm using the C sysfs API, and I can't find a reference for pull-ups / pull-downs other than using the mmap() interface, and I'd prefer to stay within the relative safety of error-checked kernel calls.
- adafruit_support_mike
- Posts: 67454
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Can't get GPIO on PiTFT to work
The sysfs interface explicitly avoids exposing pull-ups and pull-downs because programmers can't assume they'll be uniform across all hardware platforms.
Take a look at the WiringPi GPIO utility:
https://projects.drogon.net/raspberry-p ... o-utility/
It provides the same kind of well-tested command line interface for configuring GPIO pins, but supports the RasPi's existing hardware.
Take a look at the WiringPi GPIO utility:
https://projects.drogon.net/raspberry-p ... o-utility/
It provides the same kind of well-tested command line interface for configuring GPIO pins, but supports the RasPi's existing hardware.
- jwatte
- Posts: 53
- Joined: Thu May 31, 2012 11:25 pm
Re: Can't get GPIO on PiTFT to work
Thanks. If there's no sysfs interface for this, I think I'll have to use the mmap interface to configure the pull-ups, and then unmap when I'm done. That way, the risk of bugs causing havoc is at least minimized :-)
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/