TCP/IP - Piezo Speaker Bricklet

This is the description of the TCP/IP protocol for the Piezo Speaker Bricklet. General information and technical specifications for the Piezo Speaker Bricklet are summarized in its hardware description.

API

A general description of the TCP/IP protocol structure can be found here.

Basic Functions

BrickletPiezoSpeaker.beep
Function ID:
  • 1
Request:
  • duration – Type: uint32, Unit: 1 ms, Range: [0 to 232 - 1] with meanings
  • frequency – Type: uint16, Unit: 1 Hz, Range: [585 to 7100]
Response:
  • no response

Beeps with the given frequency for the given duration.

Changed in version 2.0.2 (Plugin): A duration of 0 stops the current beep if any, the frequency parameter is ignored. A duration of 4294967295 results in an infinite beep.

The Piezo Speaker Bricklet can only approximate the frequency, it will play the best possible match by applying the calibration (see calibrate).

The following meanings are defined for the elements of this function:

For duration:

  • 0 = Off
  • 4294967295 = Infinite
BrickletPiezoSpeaker.morse_code
Function ID:
  • 2
Request:
  • morse – Type: char[60]
  • frequency – Type: uint16, Unit: 1 Hz, Range: [585 to 7100]
Response:
  • no response

Sets morse code that will be played by the piezo buzzer. The morse code is given as a string consisting of "." (dot), "-" (minus) and " " (space) for dits, dahs and pauses. Every other character is ignored.

For example: If you set the string "...---...", the piezo buzzer will beep nine times with the durations "short short short long long long short short short".

Advanced Functions

BrickletPiezoSpeaker.calibrate
Function ID:
  • 3
Request:
  • empty payload
Response:
  • calibration – Type: bool

The Piezo Speaker Bricklet can play 512 different tones. This function plays each tone and measures the exact frequency back. The result is a mapping between setting value and frequency. This mapping is stored in the EEPROM and loaded on startup.

The Bricklet should come calibrated, you only need to call this function (once) every time you reflash the Bricklet plugin.

Returns true after the calibration finishes.

BrickletPiezoSpeaker.get_identity
Function ID:
  • 255
Request:
  • empty payload
Response:
  • uid – Type: char[8]
  • connected_uid – Type: char[8]
  • position – Type: char, Range: ['a' to 'h', 'z']
  • hardware_version – Type: uint8[3]
    • 0: major – Type: uint8, Range: [0 to 255]
    • 1: minor – Type: uint8, Range: [0 to 255]
    • 2: revision – Type: uint8, Range: [0 to 255]
  • firmware_version – Type: uint8[3]
    • 0: major – Type: uint8, Range: [0 to 255]
    • 1: minor – Type: uint8, Range: [0 to 255]
    • 2: revision – Type: uint8, Range: [0 to 255]
  • device_identifier – Type: uint16, Range: [0 to 216 - 1]

Returns the UID, the UID where the Bricklet is connected to, the position, the hardware and firmware version as well as the device identifier.

The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port). A Bricklet connected to an Isolator Bricklet is always at position 'z'.

The device identifier numbers can be found here

Callbacks

BrickletPiezoSpeaker.CALLBACK_BEEP_FINISHED
Function ID:
  • 4
Response:
  • empty payload

This callback is triggered if a beep set by beep is finished

BrickletPiezoSpeaker.CALLBACK_MORSE_CODE_FINISHED
Function ID:
  • 5
Response:
  • empty payload

This callback is triggered if the playback of the morse code set by morse_code is finished.