0

I have been searching for clarification on PiTFT tactile switch, and folks have always been around #18 for backlight, and adafruit's tutorial requires to solder jumper 18 at the back of the board. I have 2 types of PiTFT as follow: 2.8" assembled capacitive PiTFT for B, 2.8" capacitive PiTFT mini kit

So I tried asking adafruit why everywhere else refers one of the tactile switches as 18 for backlight but the board is labeled #17, yet their answer was "#18 is used for the backlight. it is not brought out to the tactile switches".

I am a newbie on hardware, trying to familiarize myself with it. Can anyone please help clarify this confusion?

1 Answer 1

2

I'm not sure I understand the confusion.

Gpios 17, 22, 23, and 27 (21 on early models) are brought out on the unit exterior. You can connect buttons to those pads which you can then read in software.

Gpio 18 is apparently used to switch the backlight on and off. There is no need to bring that out to the unit exterior. It is assumed you'll control the backlight in software.


I give an example using my pigpio library.

#!/usr/bin/env python

# read_write.py
# 2015-06-06
# Public Domain

import time

import pigpio

BUTTON=23
BACKLIGHT=18

def cbf(gpio, level, tick):
   if gpio == BUTTON:
      print("set BACKLIGHT to {}".format(level))
      pi.write(BACKLIGHT, level)

pi = pigpio.pi() # open connection to pigpio

pi.set_mode(BUTTON, pigpio.INPUT)
pi.set_mode(BACKLIGHT, pigpio.OUTPUT)

# create callback to call whenever BUTTON changes state

cb = pi.callback(BUTTON, pigpio.EITHER_EDGE, cbf)

start = time.time()

while (time.time()-start) < 60.0: # run for 60 seconds
   time.sleep(1)

cb.cancel() # cancel callback

pi.stop() # close connection to pigpio

Save the file as read_write.py and make executable (chmod +x read_write.py).

To run make sure the pigpio daemon is running (sudo pigpiod) then enter

./read_write.py

To test without a working switch enter the following commands at the command line (a different shell to that running the script).

pigs w 23 0
pigs w 23 1
pigs w 23 0

to get the following output

set BACKLIGHT to 0
set BACKLIGHT to 1
set BACKLIGHT to 0
10
  • Like I said, I'm a newbie to hardware, so I can't quite grasp the relation. The way you say it, it looks like I can just use RPi.GPIO in python script to setup the backlight gpio by echoing 252, then configure the button from there?
    – Sean Lee
    Jun 4, 2015 at 22:52
  • The gpios are referred to by numbers. Write 1 to gpio 18 to switch on the backlight. Write 0 to gpio 18 to switch off the backlight. I don't know why you are relating the buttons to the backlight. Reading the buttons is an independent activity. How do you arrive at the number 252? Read gpio 17 to check the status of the tactile switch attached to gpio 17.
    – joan
    Jun 5, 2015 at 7:43
  • Tactile switch holes got labels: [link]adafruit.com/images/970x728/1983-00.jpg[/link]. Number 252 is a bad example taken from this resistive tutorial [link]learn.adafruit.com/…. My PiTFT is capacitive, which is [link]learn.adafruit.com/adafruit-2-8-pitft-capacitive-touch/…, shows just wiring and soft control. Bottom line, googled examples show folks assigning backlight to switch on board, but adafruit tech says no. Question is, how did folks do it then?
    – Sean Lee
    Jun 5, 2015 at 22:43
  • 1
    @SeanLee I have added an example.
    – joan
    Jun 6, 2015 at 11:13
  • 1
    This reads a bit like that "who's on first" sketch, lol. Joan's provided a good example here Sean, I hope your confusion clears: GPIO 18 is not used as a switch, it's a control. Notice here 23 is set as an input, that's something whose state the software monitors -- it's attached to the button. But 18, which controls the backlight, is set as an output. That's something whose state the software controls. When a change in state of the input is detected (a button press), the software changes the state of the output (to toggle the backlight).
    – goldilocks
    Jun 6, 2015 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.