Using Cynthion USER I/O with Facedancer
In addition to the four USB ports Cynthion also includes the following user i/o ports:
Apart from PMOD B, which is used for the Facedancer SoC UART and JTAG interface, all of these can be accessed from within Python Facedancer devices.
Before proceeding, please ensure you have completed all steps in the Getting Started with Cynthion and Using Cynthion with Facedancer sections.
Requirements
A Cynthion running the Facedancer bitstream.
Two USB Cables.
Using Cynthion APIs
To access Cynthion USER i/o using Python you first need an instance of the Cynthion object, which can be created as follows:
from cynthion import Cynthion
c = Cynthion()
Once you have a Cynthion instance you will be able to access USER i/o using the leds and gpio APIs.
For example, open a new Python shell:
$ python
Python 3.11.11 (main, Feb 12 2025, 14:40:14) [Clang 16.0.0 (clang-1600.0.26.6)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
First obtain a Cynthion instance:
>>> from cynthion import Cynthion
>>> c = Cynthion()
Turn on USER Led5:
>>> c.leds[5].on()
Turn off USER Led5:
>>> c.leds[5].off()
Toggle USER Led4:
>>> c.leds[4].toggle()
Get the USER Button:
>>> user_button = c.gpio.get_pin("USER")
Wait for the USER Button to be pressed: (hit enter twice to start)
>>> while user_button.read() == False: pass
...
USER Pmod inputs and outputs
In addition to the USER Button and Leds, Facedancer can also make use of Cynthion USER Pmod A (USER Pmod B is used for JTAG and UART duties) to trigger or respond to external hardware. They use the same gpio APIs as the USER Button but individual pins can also be configured as inputs or outputs.
Let’s build a simple example that uses two of the USER Pmod A pins to connect a switch and a LED to Cynthion.
You will need:
1x SPST Switch
1x 1 kOhm resistor
1x 10 kOhm resistor
1x LED
1x Breadboard
Circuit Diagram
Breadboard Layout
Source Code
Create a new Python file called cynthion-user-pmod.py with the following content:
1import time
2
3from cynthion import Cynthion
4from cynthion.interfaces.gpio import PinDirection
5
6# Get Cynthion instance
7c = Cynthion()
8
9# Get USER Pmod Pin A1 and configure it as an input
10a1 = c.gpio.get_pin("A1")
11a1.set_direction(PinDirection.Input)
12
13# Get USER Pmod Pin A3 and configure it as an output
14a3 = c.gpio.get_pin("A3")
15a3.set_direction(PinDirection.Output)
16
17# Continuously read the input value of Pin A1 and output it to Pin A3.
18while True:
19 value = a1.read()
20 a3.write(value)
21 time.sleep(0.1)
Open a terminal and run:
python ./cynthion-user-pmod.py
If all goes well, the LED should light up when you press the switch and turn off when you release it.