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

Back to Table of Contents

The following detail the lio functionality for accessing the core IO features of phatIO, sending and receiving data from the pins.

See the Introduction to IO section for more information on the input/output modes.

The default, initial pin mode is IN.

(pinmode <pin> <mode> [opt value])

Set the specified pin to the mode, if a third argument is given it is used as the initial value. This is equivalent to writing to the “PHATIO/io/mode/<pin>” files for the pin.

IN
Pin behaves as a digital input, getpin will return 0 or 1 depending on voltage applied to the specified pin. setpin will do nothing.
HIGH
Pin behaves as a digital input and the pin is held high with a 20KOhm resistor to 5V, when no input is applied to the pin it will read high. setpin will do nothing.
ADC
Pin behaves as an analog input, getpin will return a value between 0..1024 depending on the voltage applied to the specified pin, setpin will do nothing.
OUT
Pin behaves as a digital output, (setpin <pin> 1) will connect the output to 5V, (setpin <pin> 0) to 0V. getpin will return 0.
PWM

Pin behaves as a PWM output, (setpin <pin> <value>) will set the PWM intensity of the pin: 0 always off 255 always on. getpin will return 0.

For example, to set pin 0 to an output and turn off:

(pinmode 0 OUT 0)

Note that the mode value is case insensitive and only the first character is used to determine the mode: “IN”, “in”, “i”, “I”, “input”, “Indigo” are all equivalent and would set the mode to IN

(setpin <pin> <value>)

Set the value of the pin depending on pinmode - see pinmode for the effect in each mode.

(getpin <pin>)

Gets the value of the pin depending on pinmode - see pinmode for what is returned in each mode.

(port <value> <pin1> <pin2> ...)

This is the first version of a more sophisticated port functionality, currently when called, port will just output each bit of value to the pins: bit 0 (LSB) to pin1, bit 1 to pin2, bit 3 to pin3 etc. for as many pins as have been passed (upto 16). This is equivalent to the following:

(setpin pin1 (& value (0x01))
(setpin pin2 (& value (0x02))
(setpin pin3 (& value (0x04))
...

This version is likely to be retired for a more capable port functionality in the future. For now it offers a slightly more succinct and efficient way of writing to multiple pins.

(led <RED|GREEN> [1|0])

Turns the named phatIO built in LED on (1) or off (0). Note that after using (led) on an LED it will no longer flash to indicate disk activity or error, to reenable this call with no value argument (e.g. (led RED)).

For example the following maps the LEDs to device files PHATIO/io/dev/red and PHATIO/io/dev/green allowing controlling the LEDs by writing “0” and “1” to those files

(driver green (led GREEN (read_hexbyte 0)))
(driver red (led RED (read_hexbyte 0)))

(peek <register address>)

Returns the value of the MCU register at the given address. See Section 31 Register Summary Atmega32u4 datasheet for the address of the registers. The following would print the values of the DDRD and PORTD registers:

(keyboard (fmt "DDRD=0x%02X " (peek 0x2A)) (fmt "PORTD=0x%02X" (peek 0x2B)))

(poke <register address> <value>)

Sets the value of the MCU register at the given address. Obviously Care should be taken in doing this. See Section 31 Register Summary Atmega32u4 datasheet for the address of the registers.

The following would provide 2 drivers “PHATIO/io/dev/DDRD” and “PHATIO/io/dev/PORTD” that map DDRD and PORTD to files. Writing “FF” to them would set the registers to 0xFF turning PORT D to output and setting the pins high (these are mapped to pins 13..20).

(driver DDRD (poke 0x2A (read_hexbyte 0)))
(driver PORTD (poke 0x2B (read_hexbyte 0)))
@Contact  |   Legal & Privacy  |    RSS  |   Development Twitter  |   Official Twitter
© phatIO 2012, All Rights Reserved.