Weft I/O
This module talks to a Raspberry Pi Pico or Pico 2 running the Weft firmware. Weft turns the Pico into a digital and analog I/O board for experiments: it timestamps digital edges and analog samples on the board itself, so the times Syntalos records do not depend on USB latency.
Pins can be digital inputs (with or without pull resistor), digital outputs, PWM outputs, or analog inputs on the pins that have an ADC channel. Other modules control the pins through the Line Control port.
Setup
Flash the Weft firmware onto the Pico as described in the Weft README. Once flashed, the board shows up as Syntalos Weft serial device.
Usage
Select the board in the settings dialog. Syntalos asks a newly selected board for its pin layout and sets up the pin table for it; the Identify button does the same explicitly. The board is remembered by its serial number, so it is found again even if its device path changes.
In the pin table, every GPIO has a Mode:
- Digital In, Digital In (pull-up), Digital In (pull-down): the board reports edges of the input on the Line Readings port. Debounce ignores further edges for a while after a reported edge, and Report selects which edges are reported. If only rising or only falling edges are reported, all readings of the line have the same level, so modules that wait for level changes will not see any.
- Digital Out and PWM Out: outputs, controlled by other modules (see below). All PWM outputs share the frequency set under Acquisition.
- Analog In: the pin is sampled continuously at the analog sampling rate, and its samples are sent on the Analog Signals port. If Readings (Hz) is set, single samples of the input are emitted at that (lower) rate on the Analog Readings port as well, which is handy for scripts that only need an occasional value.
The Label of a pin names its line or signal in the recorded data.
Analog values are raw 12-bit ADC counts (0 to 4095). The ADC reference of a Pico is its 3.3 V supply, so converting counts to volts would only be as accurate as that supply.
The board picks the sampling rate closest to the requested one that it can generate. If that is not close enough to the requested rate, the run does not start, and the error message names the rate the board can do.
Digital inputs whose edges come faster than the board can report them are paused for a moment by the board. Their level is still reported when the pause starts and ends, but the edges in between are not. Pauses, lost events and USB transmission problems are logged, shown in the module status and listed in the run statistics.
Timestamps
All timestamps are taken on the board. Syntalos measures the offset and drift of the board’s clock with short ping exchanges, and converts the board’s timestamps to Syntalos’ master clock. Right after the start, the module pings faster for a few seconds to fit the drift, then switches to the clock sync interval. The status line shows the jitter of the clock measurements.
The measurements need a USB connection with low latency. Connect the board directly to the computer, not through a hub or a virtual machine.
Controlling Pins
Other modules, like Manual HWLine Control or a
Python Script, control the pins by sending LineCommands to the Line Control port.
The line ID of a command is the GPIO number.
A command that would not change the pin is not sent to the board, as the board sets up a pin anew for every mode change: a digital output would briefly go low, and an input would report its level again. Mode changes made during a run are applied to the pin table, and saved with the project.
Failed commands are counted and logged, together with the reason.
A Python script that briefly lights an LED on GPIO 15 for every reading of the analog input on GPIO 26 that is above half of its range, and also records every button press on line 8 could look like this:
import syntalos_mlink as syl
from datetime import timedelta
iport_a = syl.get_input_port('analog-in') # connected to "Analog Readings"
iport_d = syl.get_input_port('digital-in') # connected to "Line Readings"
oport_ctl = syl.get_output_port('ctl-out') # connected to "Line Control"
oport_tab = syl.get_output_port('presses-out')
led = syl.HwOutputLine(ctl_out, 15)
button = syl.HwInputLine(oport, 8, pull=syl.LinePull.UP)
def prepare() -> bool:
oport_tab.set_metadata_value('table_header', ['Time (usec)', 'Line'])
oport_tab.set_metadata_value('data_name_proposal', 'events/button-presses')
iport_a.on_data = on_reading_analog
iport_d.on_data = on_reading_digital
return True
def start():
led.send_mode()
button.send_mode()
def on_reading_analog(r):
# blink the LED on every 5th analog reading (10 Hz readings -> 2 Hz blink)
if r.line_id == 26 and n_events_a % 5 == 0:
led.pulse(20000)
def on_reading_digital(r):
# the button pulls the line LOW when pressed (it has a pull-up)
if r.line_id == button.line_id and r.value == 0:
oport_tab.submit([int(r.time / timedelta(microseconds=1)), r.line_id])Ports
| Name | Direction | Data Type | Description |
|---|---|---|---|
| 🠺 Line Control | In | LineCommand | Commands for the pins, see above. |
| Line Readings 🠺 | Out | LineReading | Edges of the digital inputs, and (if enabled) their level at the start of a run. |
| Analog Signals 🠺 | Out | SignalBlockU16 | Samples of all analog inputs. Only present if the pin table has analog inputs. |
| Analog Readings 🠺 | Out | LineReading | Single samples of analog inputs. Only present if an input has a readings rate. |
Stream Metadata
Analog Signals carries the standard signal-stream metadata. Its columns are the analog inputs in ascending GPIO order, and the timestamp of a row is the time its first column was sampled.
| Key | Value |
|---|---|
sample_rate | The analog sampling rate per channel, in Hz. |
time_unit | Always microseconds. |
signal_names | The labels of the analog inputs, or GPIO<n> without one. |
data_unit | Always adc-counts. |
The two LineReading ports have this metadata:
| Key | Value |
|---|---|
time_unit | Always microseconds. |
data_unit | ttl for Line Readings, adc-counts for Analog Readings. |
is_digital | true for Line Readings, false for Analog Readings. |
lines | The GPIOs of the port: all digital inputs, or the analog inputs with a readings rate. |
signal_names | The labels of these GPIOs, in the same order as lines. |