RT
Interface BoardWeb Serial Console
Disconnected

Digital I/O

Choose OUT or IN for a pin, then click its LED to toggle the output or re-read the input. Reading a pin makes it an input, so avoid pins in use by I2C, SPI, PWM or servos.

Analogue

DAC output (pin 3)

DAC05-bit
0 · 0.00 V

PWM

Duty is sent as a 10-bit value (0–1023).

Servos

I²C

Devices:
not scanned

Register read / write (values in hex)

Bus primitives

SPI

UART

The board buffers up to 255 received bytes. Changing the baud rate is saved to the board's EEPROM.

Script

Ready
Script reference

Basics

# comment
x = adc.read 0              # command form: arguments separated by commas
i2c.write 0x68, 0x6B, 0x00
if adc.read(0) > 512        # inside expressions use brackets
  io.set 12, 1
elif x == 0
  io.set 12, 0
else
  print "x is", x, hex(x)
end
repeat 10 … end      loop … end      while cond … end
for i = 0 to 255 step 5 … end        for a in list … end
def name(a, b) … return v … end      break  continue  exit
wait 100             # milliseconds

Maths uses JavaScript operators: + - * / % << >> & | ^ == != < >, plus and / or. ^ is XOR, use pow(a,b) for powers. Variables set inside a def are local to it.

Board commands

io.set pin, vDrive pin 0–17 high (1) or low (0). Also io.high, io.low, io.toggle.
io.get pinMake pin an input and return 0 / 1.
adc.read ch10-bit reading (0–1023) from ADC0–2. adc.read8 gives 0–255, adc.volts gives volts.
dac.enable / dac.disableTurn the DAC output on pin 3 on or off.
dac.set vDAC level 0–31.
pwm.enable ch / pwm.disable chPWM channel 0 or 1.
pwm.duty ch, v8-bit duty 0–255. pwm.duty10 ch, v for 0–1023.
pwm.prescaler code0=1:1, 1=1:4, 2=1:16, 3=1:64.
servo.enable ch / servo.disable chServo channel 0–5 (S0–S5).
servo.set ch, posPosition 0–255. servo.angle ch, deg takes 0–180.
i2c.initInitialise the I²C master.
i2c.write addr, reg, data…Write bytes to a register. addr is the 7-bit address. Data can be numbers, lists or strings. Pass null as reg to skip it.
i2c.read addr, reg, nRead n bytes from a register and return a list. i2c.readByte addr, reg returns one byte. i2c.readWord addr, reg returns 16 bits, MSB first. i2c.readRaw addr, n reads without a register.
i2c.probe addr / i2c.scanCheck one address and return true or false, or scan and return a list of addresses.
i2c.start / restart / stopLow-level bus conditions.
i2c.send byteSend a raw byte. Returns 0 for ACK, 1 for NACK.
i2c.recv lastReceive a byte. Use last=1 on the final byte to send a NACK.
spi.init / spi.prescaler codeInitialise SPI. Prescaler codes: 0=1:1, 1=1:4, 2=1:16.
spi.transfer byteFull-duplex single byte. Chip select is not changed.
spi.xfer bytes…Pull CS low, transfer every byte, release CS and return the received list.
spi.cs pinSet the CS pin used by xfer (default 11, -1 for none). Also spi.select and spi.deselect.
uart.init / uart.baud rateInitialise the UART or set its baud rate (1200–115200).
uart.write data…Send numbers, lists or strings.
uart.availableNumber of bytes waiting.
uart.readRead one byte (255 if the buffer is empty).
uart.readAll / uart.readStringRead everything waiting, as a list or as text.
uart.readLine timeoutWait for a line of text. Returns null on timeout (default 1000 ms).
board.raw cmd, [params], nSend a raw protocol command and return n reply bytes.

Helpers

print a, b, …Write to the console. clear empties it.
hex(v) bin(v)Format a number, or a list of bytes, as hex or binary.
u16(msb, lsb) s16(msb, lsb) s8(v)Combine bytes, or convert to a signed value.
bit(v, n)Value of bit n.
str(list) bytes(…)Convert bytes to text, or text and values to a list of bytes.
len(x) map(v,a,b,c,d) constrain(v,lo,hi)Length, range mapping and clamping.
abs min max round floor ceil sqrt pow sin cos tan atan2 log exp random PI now()Maths functions. now() returns milliseconds.

Console