top
About Buy News Guide Ideas
Get a phatIO device here!

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)

Startup

When phatIO is started, or when the run.lio file is written to,

  1. All existing configuration, schedules, conditions, drivers are deleted.
  2. 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 PHATIO/io/status file.

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:

  1. Unplug the device
  2. Remove the SD card
  3. Plug phatIO back in
  4. The phatIO red LED will flash every 1 second indicating the SD card is missing
  5. Reinsert the SD card, phatIO will restart and connect to the host computer but not execute run.lio
  6. 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.

Function Reference

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.
Examples
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
Configuration of phatIO behaviour using the config function.
IO
How functions can communicate through phatIO’s pins
Functions: pinmode, setpin, getpin, led, peek, poke
TWI
Communicate with TWI/I2C devices on the TWI bus on pins 12 and 13.
Functions: twi, twi_start, twi_data, twi_stop
SPI
Functions: spi_conf, spi.
Conditions
How to do something when something else happens
Functions: pin_goes_high, pin_goes_low, pin_changes, adc_goes_above, adc_goes_below.
Scheduler
Allows code to be executed regularly with the every function.
Keyboard
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
@Contact  |   Legal & Privacy  |    RSS  |   Development Twitter  |   Official Twitter
© phatIO 2012, All Rights Reserved.