Skip to content
Uwe Post edited this page Nov 13, 2019 · 16 revisions

Documentation of supported words

+ - Standard Forth, adds the two values from the stack and pushes the result.

- - see above

* - see above

/ - see above

. - pulls the top value from the stack and writes it to Serial

and - Standard Forth (added in 0.1.8)

or - Standard Forth (added in 0.1.8)

0= - Standard Forth (added in 0.1.8)

stk

swap - swaps the top two values on the stack

dup - duplicates the top value on the stack

words - shows available words in the dictionary

drop - removes top value from the stack

= - adds 1 to the stack if the top two values are equal, 0 else

negate

delay - pulls the top value from the stack and delays execution for that many milliseconds

digwrite - writes data to an IO pin. Syntax is: 1 13 digwrite, so the pin number is last on the stack.

pinmode - sets pinmode to in or out, Syntax is 1 3 pinmode to set pin 3 to

dis - disasm

if - Standard Forth

else - Standard Forth

then - Standard Forth

begin - Standard Forth

until - Standard Forth

> - Standard Forth (use negate if you need to check for "less than")

emit

freemem

digread - reads value from a pin and puts it onto the stack, i.e. 11 digread reads from pin 11.

analogread - reads analog value from a channel (using A/D-converter) and puts it onto the stack, i.e. 0 analogread reads from channel 0 (which is hopefully connected to pin A0).

analogwrite - writes analog value (PWM) to a pin. Note that not all Arduino models support this on all pins.

auto - stores a value in the first (0th) position in the EEPROM. On start of FINF, if that value == 1, assumes the text in the EEPROM is a program, and then loads and executes that text.

in - set pin to digital read

out - set pin to digital write

on - write 1 to a pin

off - write 0 to a pin

relay - add RELAY_BASE_PIN to the number on the stack in order to get the right pin number

led - the LED pin number (13)

pwm - set PWM on pin (same as analogwrite)

reset - reset the arduino board

rnd - random generator. Example: 100 rnd adds a random number 0..99 to stack (added in 0.1.8, fixed in 0.2.1)

millis - pushes milliseconds since start to the stack. Note this is an int, so this overflows from +32767 to -32768 each ~65.5 seconds (added in 0.1.8)

micros - microseconds since start as signed int, so this overflows from +32767 to -32768 each ~65.5 milliseconds (added in 0.1.8)

tone - ( freq pin "tone" -- ) plays tone of frequency on pin (added in 0.1.8)

notone - ( pin "notone" --) stops playing tone (added in 0.1.8)

load - load from eeprom: executes the text in the EEPROM. Text starts at the 1st postition. 0th positions indicates whether to autoload on device start.

save - save to eeprom: reads text from Serial into the EEPROM. ^Z quits

list - list eeprom: outputs the text in the EEPROM to the serial device.

erase - erase eeprom: erases all text in the EEPROM. Does this by putting a 0 in position 1. All other trxt is preserved.

! - store: ( value address/variable "!" -- ) Implements the FORTH "!" opcode. Stores value in SRAM. You can use a variable name here if defined with the word "variable"

@ - fetch: ( address/variable "@" -- memory-location-contents-as-int ) implements the FORTH "@" opcode. Pulls SRAM address-value to the stack. You can use a variable name here.

? - fetch and print: ( address/variable "?" -- ) prints the value stored in an address

var or variable - ( "var or variable" varname -- ) creates a variable of name "varname". "var" or "variable" both execute this. Choose short variable names because memory is limited

e! - eeprom store: ( value eeprom-address "e!" -- ) stores an integer in an EEPROM address. EEPROM size is for example 1 KB on Arduino Nano. Make sure you don't overwrite the program source you saved in EEPROM. Remember that EEPROM can wear off if written too often.

e@ - eeprom fetch: ( eeprom-address "e@" -- eeprom-address-contents ) gets the value of the EEPROM location, and puts it on the stack.

e? - eeprom fetch and print: ( eeprom-address "e?" -- ) prints the value at the given EEPROM address

key - waits for a keypress and stores the value on the stack

step - ( steps direction port 'step' -- ) run a stepper motor attached to an AdaFruit MShield

motor - ( speed direction port 'motor' -- ) run a DC motor attached to an AdaFruit MShield. Directions are 1,2, motors are 1-4.

forward - ( speed motor_bank 'forward' -- ) on an AdaFruit MShield, start both DC motors on the specified bank running so that a skid-steer two motor robot would move forward.

back - ( speed motor_bank 'back' -- ) on an AdaFruit MShield, start both DC motors on the specified bank running so that a skid-steer two motor robot would move backward.

turn - ( direction speed motor_bank 'turn' -- ) on an AdaFruit MShield, start both DC motors on the specified bank running so that a skid-steer two motor robot would turn in the specified direction.

stop - ( motor_bank 'stop' -- ) stop both motors attached to the specified bank of an AdaFruit MShield.

pad - ( "pad" -- pad-address ) if area for the PAD has not been allocated, allocate PAD_LENGTH bytes. Return the location on the stack.

const - define const: ( value "const" constname ) define a constant of value "value" and name "constname"

readln - ( memory-address max-length "readln" -- bytes-received ) read from the serial port into the memory locaiton specified, until max-length bytes are received, or carriage return or line feed are received.

print - ( mwmory-address "print" -- ) prints the contents of a memory location to the serial port

move - ( source-address target-address length "move" -- ) executes memmove

strlen - ( memory-address "strlen" -- ) executes strlen

Notes

  • check the hardware support of your Arduino. For example, the Nano (or Nano clones) cannot use the PWM on the onboard LED, so 127 13 pwm won't dim the LED as you might expect.
  • Terminal line length is limited to 128-2=126. So if you have more to tell, it's not possible on one line. Defining a word works over multiple lines.

Roadmap

support for additional Arduino functions:

  • delayMicroseconds()
  • attachInterrupt()
  • serial i/o

support for Arduino libraries:

  • SPI
  • LCD
  • SD
  • TFT
  • I²C
Clone this wiki locally