This is a "cheat sheet" for Arduino extension by Buff, updated by YellowAfterlife.

The extension can be found on GitHub.

Click on sections to expand/collapse them.
Quick display controls: Categories · Sections · Everything ·

General functions
Reading data

Classic functions:

arduino_read(index, length)​

Reads length bytes from the Arduino and returns them as a string.

Returns "" if Arduino doesn't exist, is not connected, or data cannot be read.

arduino_read_to(index, delim)​

Reads bytes from the given Arduino until it encounters a delimiter byte (provided as a string).

Delimiter is not returned as part of the resulting string.

Returns "" if Arduino doesn't exist, is not connected, or data cannot be read.

arduino_read_line(index)​

Reads data until a new line (\n, byte 10) and returns it as a string.

Returns "" if Arduino doesn't exist, is not connected, or data cannot be read.

Slight updates:

arduino_read_text(index, length)​

Reads up to length bytes from the given Arduino and returns them as a string.

Returns undefined in case of trouble.

arduino_read_to_new(index, delim_u8)​

Like arduino_read_to, but takes delimiter as a byte value (so ord(" ") or 32 instead of a " ") and returns undefined in case of trouble (to tell apart from an empty string).

arduino_read_line_new(index)​

Like arduino_read_line, but returns undefined in case of trouble.

Buffers:

arduino_read_buffer(index, buffer, pos, len)​

Reads up to len bytes to a buffer (placed at position pos and onward).

Returns the number of bytes read.

Special return values:

  • -1: Arduino does not exist
  • -2: Arduino is not connected
arduino_read_buffer_to(index, buffer, pos, len, delim_u8)​

Reads up to len bytes to a buffer (placed at position pos and onward), stops at delim_u8 byte (not added to the buffer / counted towards return).

Returns the number of bytes read.

Special return values:

  • -1: Arduino does not exist
  • -2: Arduino is not connected

Primitives:

Buffer-like functions

The naming convention of the following mimics the buffer_* constants and they are used much like those in buffer_read - so arduino_read_u8(ind) reads an unsigned byte, and arduino_read_s16(ind) reads a signed 16-bit integer.

Functions return undefined in case of trouble.

arduino_read_s8(index)​
arduino_read_u8(index)​
arduino_read_s16(index)​
arduino_read_u16(index)​
arduino_read_s32(index)​
arduino_read_u32(index)​
arduino_read_s64(index)​
arduino_read_f32(index)​
arduino_read_f64(index)​
arduino_read_string(index:number)​

Reads a NUL-terminated string.

Technically this is just arduino_read_to_new(index, 0).

Writing data

Classic functions:

arduino_write(index, buffer, length)​

Writes length bytes from the buffer (either a string or buffer_get_address) to the given Arduino.

This function is kept around for backwards compatibility, is unsafe, and I encourage you to use arduino_write_string, arduino_write_text, or arduino_write_buffer depending on what you're after.

Return values:

  • 1: Success
  • 0: Failed to write
  • -1: Arduino does not exist
  • -2: Arduino is not connected

New functions:

arduino_write_string(index, string)​

Writes a NUL-terminated string to the given Arduino.

Return values:

  • 1: Success
  • 0: Failed to write
  • -1: Arduino does not exist
  • -2: Arduino is not connected
arduino_write_text(index, string)​

Writes an unterminated string to the given Arduino.

When storing string length separately from the string, remember to use string_byte_length so that non-Latin characters don't break your code!

Return values:

  • 1: Success
  • 0: Failed to write
  • -1: Arduino does not exist
  • -2: Arduino is not connected
arduino_write_buffer(index, buffer, pos, len)​

Writes len bytes from the buffer to the given Arduino, starting at pos.

Return values:

  • 1: Success
  • 0: Failed to write
  • -1: Arduino does not exist
  • -2: Arduino is not connected

Primitives:

Buffer-like functions

The naming convention of the following mimics the buffer_* constants and they are used much like those in buffer_write - so arduino_write_u8(ind, 50) writes 50 as a byte and arduino_write_s16(ind, 150) writes 150 as a signed 16-bit integer.

Return values:

  • 1: Success
  • 0: Failed to write
  • -1: Arduino does not exist
  • -2: Arduino is not connected
arduino_write_s8(index, value)​
arduino_write_u8(index, value)​
arduino_write_s16(index, value)​
arduino_write_u16(index, value)​
arduino_write_s32(index, value)​
arduino_write_u32(index, value)​
arduino_write_s64(index, value)​
arduino_write_f32(index, value)​
arduino_write_f64(index, value)​