Table of Contents

Control digital outputs

The Sound Card can send a TTL pulse from its digital outputs (OUT0–OUT2) every time a sound starts, and the outputs can also be controlled directly from Bonsai. Upload a sound to sound index 2 with the Sound Card app or in Bonsai. Refer to the connections article to connect OUT0 to a digital input on an external device, which we will use for the rest of these examples.

Note

Pure tone playback from the internal sine wave generator is currently limited (as of firmware v3.0) to the Right Channel. Connect the amplifier and speaker to this channel if you plan to play pure tones.

This article covers how to send a pulse when a sound starts, set and clear outputs, toggle outputs, and write all outputs at once in Bonsai.

The complete workflow is shown below. Copy and paste it into Bonsai to get started immediately, or build each section by following the step-by-step instructions in the following sections.

Control digital outputs

Warning

The digital outputs are designed for logic-level signals and are not intended for driving loads. For small loads, such as a conventional LED, use a series current-limiting resistor of at least 330 Ω.

Pulse on sound start

Each digital output line has a configuration mode register that sets what the line does (e.g. ConfigureDO0 for OUT0). In PulseOnStart mode, the line sends a 400 µs pulse every time a sound or pure tone starts and every time the frequency of the pure tone changes. This applies whether the sound was started from Bonsai or from a digital input. By default, OUT0 is in PulseOnStart mode, and OUT1 and OUT2 are in Digital mode.

Pulse on sound start

  • Insert a KeyDown operator and set the Filter property to A.
  • Insert a CreateMessage operator and configure the following properties:
    • Payload - Select ConfigureDO0Payload.
    • ConfigureDO0 - Select PulseOnStart.
  • Insert a MulticastSubject operator named SoundCard Commands.

In a separate branch:

  • Insert a KeyDown operator and set the Filter property to S.
  • Insert a CreateMessage operator and configure the following properties:
    • Payload - Select StartPayload.
    • Start - Set the index of the sound to play (e.g. 2).
  • Insert a MulticastSubject operator named SoundCard Commands.

Run the workflow and press A to set the configuration, then press S to play sound index 2 and check the TTL pulse on the external device.

Set and clear outputs

In Digital mode, the output line can be set directly (e.g. to control external devices). This example reconfigures OUT0 to Digital mode first with ConfigureDO0, so the same connection can be used. It then demonstrates how to control the output line with OutputSet and OutputClear.

Set and clear outputs

  • Insert a KeyDown operator and set the Filter property to D.
  • Insert a CreateMessage operator and configure the following properties:
    • Payload - Select ConfigureDO0Payload.
    • ConfigureDO0 - Select Digital.
  • Insert a MulticastSubject operator named SoundCard Commands.

In a separate branch:

  • Insert a KeyDown operator and set the Filter property to F.
  • Insert a CreateMessage operator and configure the following properties:
    • Payload - Select OutputSetPayload.
    • OutputSet - Select the line to set high (e.g. DO0).
  • Insert a MulticastSubject operator named SoundCard Commands.

In a separate branch:

  • Insert a KeyDown operator and set the Filter property to G.
  • Insert a CreateMessage operator and configure the following properties:
    • Payload - Select OutputClearPayload.
    • OutputClear - Select the line to clear low (e.g. DO0).
  • Insert a MulticastSubject operator named SoundCard Commands.

Run the workflow and press D to enable Digital mode, then press F or G to set or clear OUT0 and check the TTL signal on the external device.

Note

A single command can control several lines at once. To set or clear multiple lines simultaneously, type the names separated by a comma (e.g. DO1, DO2) in the OutputSet or OutputClear field. Lines not specified remain unchanged.

Note

Software-triggered outputs are subject to operating system and hardware communication latencies.

Toggle outputs

OutputToggle flips the output line between low and high with a single command, so a workflow event can alternate the line without keeping track of its current state.

Toggle outputs

  • Insert a KeyDown operator and set the Filter property to H.
  • Insert a CreateMessage operator and configure the following properties:
    • Payload - Select OutputTogglePayload.
    • OutputToggle - Select the line to toggle (e.g. DO0).
  • Insert a MulticastSubject operator named SoundCard Commands.

Run the workflow and press H repeatedly to toggle OUT0 between high and low, then check the TTL signal on the external device.

Write all outputs

OutputState writes the state of all digital output lines with a single command. Selected lines are set high and all other lines are set low. Use it to set the whole output bank to a known state, for example when initializing an experiment.

Write all outputs

  • Insert a KeyDown operator and set the Filter property to J.
  • Insert a CreateMessage operator and configure the following properties:
    • Payload - Select OutputStatePayload.
    • OutputState - Select the lines to set high (e.g. DO0, DO1). All other lines are set low.
  • Insert a MulticastSubject operator named SoundCard Commands.

Run the workflow and press J, then check the TTL signal on the external device. OUT0 and OUT1 will be set to high and OUT2 will go low.

Warning

OutputState acts on every digital output line of the Sound Card. To change only selected lines, use OutputSet, OutputClear, or OutputToggle.



Documentation for release v3.0.0