FlexiTacDocs
On this pageOverview

PyFlexiTac

Use the sensor from Python with PyFlexiTac. Check the signal, read and record frames, run several sensors, flash from the command line, and read the wire protocol.

PyFlexiTac is the flexitac Python package (MIT-licensed, maintained by Wesley Maa). Stream the sensor already used it for the live heatmap. This page covers the rest. Its README is the source of truth for every option.

Install

PyFlexiTac needs Python 3.11 or newer.

python3 -m venv .venv && source .venv/bin/activate
# [examples] adds matplotlib for the heatmap
pip install "flexitac[examples]"

This installs four commands: flexitac-find-port, flexitac-heatmap, flexitac-stream and flexitac-flash.

Check the signal

flexitac-stream prints the frame rate and signal statistics. It tells you whether the board, the firmware and the reader agree.

flexitac-stream --port /dev/ttyUSB0 --frames 3000
Expected output
frame=    10 fps=  85.3 raw_max=104 norm_max=0.000
frame=    20 fps=  87.1 raw_max=109 norm_max=0.123
FieldHealthyIf not
fpsSettles near 100+ for a 12 × 32 sensor0 or TimeoutError: the board isn't sending FlexiTac frames at this baud rate. See No frames. About half the expected rate: the reader expects more rows than the firmware sends. See Scrambled heatmap.
raw_maxBetween 0 and 255, and changes when you pressStuck at 0 or 255: a wiring or connector problem, not a flashing problem.
norm_maxNear 0 at rest, rises toward 1.0 on contactNever rises: check the Velostat and the connectors.

If some rows seem dead, add --per-row. It prints each row's mean baseline once, then each row's raw_max every 20 frames. Press along a column and check that every row responds.

Serial port permissions

Add yourself to the dialout group once, then log out and back in:

sudo usermod -aG dialout "$USER"

As a quick, temporary workaround (until the next replug), you can loosen permissions on the device instead:

sudo chmod a+rw /dev/ttyUSB0

Read frames in Python

hello_flexitac.py
from flexitac import FlexiTacSensor

# rows=12, cols=32 by default; the first read calibrates
with FlexiTacSensor("/dev/ttyUSB0") as sensor:
    for frame in sensor:
        print(frame.seq, frame.raw.max(), frame.normalized.max())

Each frame is a FlexiTacFrame:

FieldTypeMeaning
seqintFrame counter since the sensor was opened
timestamp_sfloatHost time when the frame was read (time.time())
rawuint8[rows, cols]Values exactly as sent by the firmware
normalizedfloat32[rows, cols]Baseline-subtracted, thresholded and scaled to 0–1

Useful methods and options:

  • sensor.read() returns the next frame in order. Use it when you're recording data and don't want to skip any.
  • sensor.read_latest() discards queued frames and returns the newest one. Use it for live control or visualization, so you never lag behind the sensor.
  • sensor.calibrate() re-captures the baseline, for example after mounting the sensor or changing the load at rest.
  • FlexiTacSensor(port, rows=…, cols=…, baud=…, init_frames=30, threshold=25.0, noise_scale=30.0, baseline=None). Pass baseline= with a saved array, or a scalar such as 20.0, to skip startup calibration.

Record a short dataset

record.py
import numpy as np
from flexitac import FlexiTacSensor

with FlexiTacSensor("/dev/ttyUSB0") as sensor:
    sensor.calibrate()          # don't touch the sensor here
    frames, stamps = [], []
    for _ in range(1000):       # about 10 s at ~100 fps
        f = sensor.read()       # in order, no dropped frames
        frames.append(f.raw)
        stamps.append(f.timestamp_s)

np.savez_compressed("tactile.npz", raw=np.stack(frames),
                    t=np.array(stamps), baseline=sensor.baseline)

More than one sensor

Each reading board is its own USB serial device. For a two-finger gripper, open one FlexiTacSensor per port (find each with flexitac-find-port) and read them in parallel threads, or call read_latest() on each in your control loop.

Flash from the command line

flexitac-flash puts the same sketch on the board as the Arduino IDE path, without opening the IDE, and can generate it for a custom sensor size.

  1. Install arduino-cli and the AVR core

    flexitac-flash compiles and uploads with arduino-cli.

    brew install arduino-cli
    arduino-cli core update-index
    arduino-cli core install arduino:avr
  2. Plug in the board and flash

    With exactly one Arduino connected, flexitac-flash finds the port and the board type on its own:

    flexitac-flash

    The defaults are for the standard V2 sensor: --rows 12 --cols 32 --baud 2000000 --mux-offset 4, meaning 12 rows wired to multiplexer channels 4–15. For a custom sensor, pass its geometry:

    flexitac-flash --rows 16 --cols 32 --mux-offset 0

Match the reader to the firmware

The reader must use the same rows and columns as the firmware. If they don't match, the reader splits the byte stream in the wrong places and the heatmap comes out cut off or scrambled (what each mismatch looks like).

FirmwareFrameRead with
PyFlexiTac's sketch, from the Arduino IDE or flexitac-flash (the default)12 × 32The defaults
A custom size: flexitac-flash --rows R --cols C --mux-offset MR × C--rows R --cols C
32_16_fast.ino from the hardware repo16 × 32; rows 0–3 stay near zero on a V2 sensor--rows 16 --cols 32

To build a custom size from the Arduino IDE instead, change ROW_COUNT, COLUMN_COUNT and MUX_CHANNEL_OFFSET at the top of the sketch before uploading. Custom sensors must fit the 32 × 16 board (up to 16 rows and 32 columns); the 32 × 32 board's firmware isn't covered by these docs yet. The hardware repo also includes fast_32_16.py, a standalone OpenCV viewer for 32_16_fast.ino.

Wire protocol

If you're writing your own reader, for a robot middleware, a microcontroller or another language, here is the whole protocol. For every frame, the firmware sends a two-byte start marker, then selects each row through a 16-channel analog multiplexer, steps through each column with shift registers, and reads each crossing with the Nano's 10-bit ADC, scaled to one byte.

FieldValue
TransportUSB serial, 2,000,000 baud, 8N1
Start marker2 bytes: 0xAA 0x55
Payloadrows × cols bytes, unsigned 8-bit, row-major (row 0 first, columns 0…cols−1)
ValueADC reading ÷ 4 (10-bit → 8-bit). Higher values mean more pressure.
Frame rateContinuous, with no text formatting; about 100+ fps for 12 × 32

A minimal reader with pyserial and NumPy:

read_raw.py
import numpy as np
import serial

ROWS, COLS = 12, 32                 # must match the firmware you flashed
MARKER, N = b"\xaa\x55", ROWS * COLS

with serial.Serial("/dev/ttyUSB0", 2_000_000, timeout=0.05) as ser:
    buf = bytearray()
    while True:
        buf += ser.read(4096)
        i = buf.find(MARKER)
        if i < 0:
            del buf[:-1]            # keep a possible half marker
            continue
        if len(buf) < i + 2 + N:
            continue                # wait for the rest of the frame
        start = i + 2
        frame = np.frombuffer(buf[start : start + N], dtype=np.uint8)
        frame = frame.reshape(ROWS, COLS)
        del buf[: start + N]
        print(frame.max())