Back to Table of Contents
phatIO Configuration and Scripting
The phatIO runfile “
PHATIO/io/run.lio” contains configuration script that can be used to customize the phatIO device.
It can be made to do things when input changes on pins (conditions) to imitate a USB keyboard (keyboard), to schedule events (scheduler), and to simplify interfacing to more complex devices (twi/i2c, spi, and devices and drivers)
When phatIO is started, or when the
run.lio file is written to,
- All existing configuration, schedules, conditions, drivers are deleted.
- The new file is parsed and code executed. If parsing or other error occurs, the red LED will be lit and an error message written to the
Normally script will be run immediately - to set pin modes/values etc. - but script to be executed later (as scheduled events, conditions, and drivers) is saved in persistent flash memory. When code is executed it is interleaved with the processing of filesystem requests (file read and writes from the host computer). For this reason code is expected to be event driven - there is no sleep/wait functionality - code should do its thing and return.
Note, that phatIO is meant for simple interfacing, it has a small CPU with limited memory. Do any heavy lifting on the host computer.
Coping with Errors
If you’ve written something to
run.lio that causes phatIO to crash or become unresponsive, the following can be done:
- Unplug the device
- Remove the SD card
- Plug phatIO back in
- The phatIO red LED will flash every 1 second indicating the SD card is missing
- Reinsert the SD card, phatIO will restart and connect to the host computer but not execute run.lio
- Delete or save a new run.lio file
During development a useful technique is to add “
(config 1 1)” at the start of the run file, this will make phatIO ‘print’ errors - send them to the keyboard as if they were typed.
Error handling and reporting in the current version of phatIO is quite limited but is being improved for the next version.
After reading the Syntax and Concepts and Variables and Functions sections the remaining can be read in any order or used as a reference when looking at the Ideas section.
- Syntax and Concepts
- Explains the LIO syntax and concepts.
- Some short pieces of example code - hello world, blink an LED etc.
- Variables and Functions
- Explains the (the currently limited) LIO for defining and using variables and functions.
- Functions: defvar, getvar, =, defconst, defun.
- Mathematical Operators
- +, +=, -, *, /, %, |, &, <<, >>.
- Control Flow and Comparison
- Functions to control flow of execution and do tests
- Functions: if, while, eq, <, >, and, or, not.
- Configuration of phatIO behaviour using the config function.
- How functions can communicate through phatIO’s pins
- Functions: pinmode, setpin, getpin, led, peek, poke
- Communicate with TWI/I2C devices on the TWI bus on pins 12 and 13.
- Functions: twi, twi_start, twi_data, twi_stop
- Functions: spi_conf, spi.
- How to do something when something else happens
- Functions: pin_goes_high, pin_goes_low, pin_changes, adc_goes_above, adc_goes_below.
- Allows code to be executed regularly with the every function.
- provides functionality for phatIO to simulate a USB keyboard
- Functions: keyboard, fmt
- Devices and Drivers
- Functions: driver
- File IO
- Some simple file reading functionality for use in drivers
- Functions: read_byte, read_hexbyte
- Coming Later
- Functionality not implemented yet