There are two approaches to supporting the optional TFT Gizmo display on a Circuit Playground Bluefruit (CPB):
- Provide configuration data to turn on (enable) the display. For a board with an attached display the enable would be manually set in the configuration for that board.
- Detect the presence of the attached display.
The configuration approach could be implemented with a configuration file to cleanly separate the per-instance data from the code. Detection of the screen can either be an alternative approach or the two can be combined.
The Challenge of Detecting the TFT Gizmo
The TFT Gizmo connects to a Circuit Playground Bluefruit (or Circuit Playground Express) using four of the pads for the display interface and one other pad for the backlight control. All of those pads are set as outputs making the interface unidirectional as a whole. This is known as simplex communication. Unfortunately, this means there is no method via standard signalling to detect whether the TFT Gizmo is present or not.
The 10k pull-down resistor in the backlight circuitry shown in the schematic at the top of the page luckily provides a crude way to detect the presence of that resistor. The A3 pad can momentarily be configured as an input with the processor's internal weaker (higher resistance) pull-up competing with the pull-down resistor. The external pull-down resistor is likely to win and this provides a method of detecting the TFT Gizmo. It can be fooled by other things attached to A3 but this is good enough to differentiate between nothing and the TFT Gizmo.
A sample CircuitPython function to detect the TFT Gizmo is shown below.
def tftGizmoPresent(): """Determine if the TFT Gizmo is attached. The TFT's Gizmo circuitry for backlight features a 10k pull-down resistor. This attempts to verify the presence of the pull-down to determine if TFT Gizmo is present. This is likely to get confused if anything else is connected to pad A3. Only use this on Circuit Playground Express or Circuit Playground Bluefruit boards.""" present = True try: with digitalio.DigitalInOut(board.A3) as backlight_pin: backlight_pin.pull = digitalio.Pull.UP present = not backlight_pin.value except ValueError: ### The Gizmo is already initialised, i.e. showing console output pass return present
This assumes that if A3 is already in use then the display is already active. Once the TFT Gizmo is used on a CPB (or CPX) it remains active until the power is removed.
Text editor powered by tinymce.