Viam SDK
    Preparing search index...

    Interface Board

    Represents a physical general purpose compute board that contains various components such as analog readers, and digital interrupts.

    interface Board {
        name: string;
        doCommand(command: Struct | Record<string, JsonValue>): Promise<JsonValue>;
        getDigitalInterruptValue(
            digitalInterruptName: string,
            extra?: Struct,
        ): Promise<number>;
        getGPIO(pin: string, extra?: Struct): Promise<boolean>;
        getPWM(pin: string, extra?: Struct): Promise<number>;
        getPWMFrequency(pin: string, extra?: Struct): Promise<number>;
        getStatus(): Promise<JsonValue>;
        readAnalogReader(
            analogReader: string,
            extra?: Struct,
        ): Promise<ReadAnalogReaderResponse>;
        setGPIO(pin: string, high: boolean, extra?: Struct): Promise<void>;
        setPowerMode(
            powerMode: boardApi.PowerMode,
            duration: Duration,
            extra?: Struct,
        ): Promise<void>;
        setPWM(pin: string, dutyCyclePct: number, extra?: Struct): Promise<void>;
        setPWMFrequency(
            pin: string,
            frequencyHz: number,
            extra?: Struct,
        ): Promise<void>;
        streamTicks(
            interrupts: string[],
            queue: Tick[],
            extra?: Struct,
        ): Promise<void>;
        writeAnalog(pin: string, value: number, extra?: Struct): Promise<void>;
    }

    Hierarchy (View Summary)

    Implemented by

    Index

    Properties

    name: string

    The name of the resource.

    Methods

    • Send/Receive arbitrary commands to the resource.

      Parameters

      • command: Struct | Record<string, JsonValue>

        The command to execute. Accepts either a Struct or a plain object, which will be converted automatically.

      Returns Promise<JsonValue>

      // Plain object (recommended)
      const result = await resource.doCommand({
      myCommand: { key: 'value' },
      });

      // Struct (still supported)
      import { Struct } from '@viamrobotics/sdk';

      const result = await resource.doCommand(Struct.fromJson({ myCommand: { key: 'value' } }));
    • Return the current value of the interrupt which is based on the type of interrupt.

      Parameters

      • digitalInterruptName: string

        The name of the digital interrupt.

      • Optionalextra: Struct

      Returns Promise<number>

      const board = new VIAM.BoardClient(machine, 'my_board');

      // Get the number of times this DigitalInterrupt has been interrupted with a tick.
      const count = await board.getDigitalInterruptValue('my_example_digital_interrupt');

      For more information, see Board API.

    • Get the high/low state of the given pin.

      Parameters

      • pin: string

        The pin number.

      • Optionalextra: Struct

      Returns Promise<boolean>

      const board = new VIAM.BoardClient(machine, 'my_board');

      // Get if it is true or false that the state of the pin is high.
      const high = await board.getGPIO('15');

      For more information, see Board API.

    • Get the duty cycle of the given pin of a board.

      Parameters

      • pin: string

        The pin number.

      • Optionalextra: Struct

      Returns Promise<number>

      The duty cycle, which is a value from 0 to 1.

      const board = new VIAM.BoardClient(machine, 'my_board');

      // Get the duty cycle of this pin.
      const dutyCycle = await board.getPWM('15');

      For more information, see Board API.

    • Get the PWM frequency of the given pin of a board.

      Parameters

      • pin: string

        The pin.

      • Optionalextra: Struct

      Returns Promise<number>

      const board = new VIAM.BoardClient(machine, 'my_board');

      // Get the PWM frequency of this pin.
      const freq = await board.getPWMFrequency('15');

      For more information, see Board API.

    • Read the current value of an analog reader of a board.

      Parameters

      • analogReader: string

        The name of the analog reader.

      • Optionalextra: Struct

      Returns Promise<ReadAnalogReaderResponse>

      const board = new VIAM.BoardClient(machine, 'my_board');

      // Get the value of the analog signal "my_example_analog_reader" has most
      // recently measured.
      const reading = await board.readAnalogReader('my_example_analog_reader');

      For more information, see Board API.

    • Set the high/low state of the given pin of a board.

      Parameters

      • pin: string

        The pin number.

      • high: boolean

        When true, set the given pin to high. When false, set the given pin to low.

      • Optionalextra: Struct

      Returns Promise<void>

      const board = new VIAM.BoardClient(machine, 'my_board');

      // Set the pin to high.
      await board.setGPIO('15', true);

      For more information, see Board API.

    • Set power mode of the board.

      Parameters

      Returns Promise<void>

      const board = new VIAM.BoardClient(machine, 'my_board');

      // Set the power mode of the board to OFFLINE_DEEP.
      const duration = new VIAM.Duration({ seconds: 10n });
      await board.setPowerMode(VIAM.PowerMode.OFFLINE_DEEP, duration);

      For more information, see Board API.

    • Set the duty cycle of the given pin of a board.

      Parameters

      • pin: string

        The pin.

      • dutyCyclePct: number

        A value from 0 to 1.

      • Optionalextra: Struct

      Returns Promise<void>

      const board = new VIAM.BoardClient(machine, 'my_board');

      // Set the duty cycle to 0.6, meaning that this pin will be in the high state for
      // 60% of the duration of the PWM interval period.
      await board.setPWM('15', 0.6);

      For more information, see Board API.

    • Set the PWM frequency of the given pin of a board.

      Parameters

      • pin: string

        The pin.

      • frequencyHz: number

        The PWM frequency, in hertz. 0 will use the board's default PWM frequency.

      • Optionalextra: Struct

      Returns Promise<void>

      const board = new VIAM.BoardClient(machine, 'my_board');

      // Set the PWM frequency of this pin to 1600 Hz.
      await board.setPWMFrequency('15', 1600);

      For more information, see Board API.

    • Stream digital interrupt ticks on the board.

      Parameters

      • interrupts: string[]

        Names of the interrupts to stream.

      • queue: Tick[]

        Array to put the ticks in.

      • Optionalextra: Struct

      Returns Promise<void>

      const board = new VIAM.BoardClient(machine, 'my_board');

      // Stream ticks from pins 8 and 11.
      const ticks = await board.streamTicks(['8', '11']);

      for await (const tick of ticks) {
      console.log(
      `Pin ${tick.pinName} changed to ${tick.high ? 'high' : 'low'} at ${tick.time}`,
      );
      }

      For more information, see Board API.

    • Write an analog value to a pin on the board.

      Parameters

      • pin: string

        The pin name.

      • value: number

        An integer value to write.

      • Optionalextra: Struct

      Returns Promise<void>

      const board = new VIAM.BoardClient(machine, 'my_board');

      // Write the value 42 to "my_example_analog_writer".
      await board.writeAnalog('my_example_analog_writer', 42);

      For more information, see Board API.