Android Programming Press on the image to return to the main documentation page.

IOIO

Written by Andrew Graham, inheried by Kolbe

This library contains a driver for the IOIO for Android board distributed
by Sparkfun electronics
The IOIO (pronounced "yo-yo") is a board specially designed to work with
Android devices (OS versions 1.5 and greater).
The board provides extensive and robust connectivity to an Android device via
a USB connection or Bluetooth and is fully controllable from within
a Basic4android application.

This library wraps the IOIOlib java library that Ytai provides.

CRITICAL: If you are new to the IOIO it is critical that you study
Ytai's github page
for detailed information on the board. It will be hard to understand this
library if you haven't understood Ytai's page on the IOIO.

The library should work with both v1 and v2 of the IOIO.

Current IOIOlib version is 4.00

List of types:

AnalogInput
CapSense
DigitalInput
DigitalOutput
IOIO
PulseInput
PwmOutput
SpiMaster
TwiMaster
Uart

AnalogInput

This object contains a representation of an analog input.

Events:

None

Members:


  Available As Int [read only]

  Buffer As Int [write only]

  Close

  IsInitialized As Boolean

  OverflowCount As Int [read only]

  Read As Float [read only]

  ReadBuffered As Float [read only]

  ReadSample (EventName As String, BufferSize As Int, samples As Int)

  ReadWait (EventName As String, msPause As Int)

  Reference As Float [read only]

  SampleRate As Float [read only]

  Voltage As Float [read only]

  VoltageBuffered As Float [read only]

  VoltageSample (EventName As String, BufferSize As Int, samples As Int)

  VoltageWait (EventName As String, msPause As Int)

Members description:

Available As Int [read only]
Gets the number of samples currently in the buffer. Reading that many
samples is guaranteed not to block.
Buffer As Int [write only]
Initializes or destroys an internal buffer, used for queuing sampled
data. When called with a positive argument, an internal buffer will be
created, and start storing sampled data.
Close
Close the pin and make it available for further use.
IsInitialized As Boolean
OverflowCount As Int [read only]
Gets the number of samples that have been dropped as result of overflow.
Read As Float [read only]
Use the ReadWait method instead.

Gets the analog input reading, as a scaled real value between 0 and 1.
It typically takes a few milliseconds between when the instance is
created and until the first value can be read. In this case, the method
may block shortly. If an absolute value is desired, consider using getVoltage().
ReadBuffered As Float [read only]
Use the ReadSample method instead.

Read one sample from the internal buffer. This method will block until at
least one sample is available.
ReadSample (EventName As String, BufferSize As Int, samples As Int)
Reads multiple scaled samples from the IOIO buffer. The buffer is initialized before
the loop and set to zero after. The EventName_done event returns a list of the samples
plus available samples and buffer overflow.

REQUIRED: use EventName_done to retrieve data or exceptions

AnalogInput.ReadSample("rsample",100,100)

sub rsample_done (noerror as Boolean, list1 as List, available as Int, overflow as Int)

if noerror then
'list1 contains the samples
'available contains the samples available after the samples are taken
'overflow contains the samples overflowed after the samples are taken
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if

end sub
ReadWait (EventName As String, msPause As Int)
Gets the analog input reading, as a scaled real value between 0 and 1.
Raises an EventName_done after obtaining the sample
and waiting a duration of msPause.

REQUIRED: use EventName_done to retrieve data or exceptions

AnalogInput.ReadWait("rwait",0)

sub rwait_done (noerror as Boolean, result as Float)

if noerror then
msgbox(result,"Scaled value read")
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if

end sub
Reference As Float [read only]
Gets the maximum voltage value against which read() values are scaled.
SampleRate As Float [read only]
Gets the sample rate used for obtaining buffered samples.
This is currently a constant.
Voltage As Float [read only]
Use the VoltageWait method instead.

Gets the analog input reading, as an absolute voltage in Volt units.
It typically takes a few milliseconds between when the instance is
created and until the first value can be read. In this case, the method
may block shortly. If a scaled value is desired, consider using read().
VoltageBuffered As Float [read only]
Use the VoltageSample method instead.

Read one sample from the internal buffer. This method will block until at
least one sample is available.
VoltageSample (EventName As String, BufferSize As Int, samples As Int)
Reads multiple voltage samples from the IOIO buffer. The buffer is initialized before
the loop and set to zero after. The EventName_done event returns a list of the samples
plus available samples and buffer overflow.

REQUIRED: use EventName_done to retrieve data or exceptions

AnalogInput.VoltageSample("vsamples",100,100)

sub vsamples_done (noerror as Boolean, list1 as List, Available as Int, Overflow as Int)

if noerror then
'list1 contains the samples
'available contains the samples available after the samples are taken
'overflow contains the samples overflowed after the samples are taken
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if

end sub
VoltageWait (EventName As String, msPause As Int)
Gets the analog input reading, as an absolute voltage in Volt units.
Raises an EventName_done after obtaining the sample
and waiting a duration of msPause.

REQUIRED: use EventName_done to retrieve data or exceptions

AnalogInput.VoltageWait("vwait",0)

sub vwait_done (noerror as Boolean, voltage as Float)

if noerror then
msgbox(voltage,"Voltage read")
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if

end sub

CapSense

This object contains a representation of a CapSense input.

Events:

None

Members:


  Close

  FilterCoef (filterTime As Float)

  IsInitialized As Boolean

  ReadWait (EventName As String, msPause As Int)

  WaitOver (EventName As String, threshhold As Float)

  WaitUnder (EventName As String, threshhold As Float)

Members description:

Close
Close the pin and make it available for further use.
FilterCoef (filterTime As Float)
Sets the low-pass filter coefficient.

This coefficient is the typical time constant of the system, which gives
us an order of magnitude of its response time. Slower response time
typically provides better noise immunity at the expense of higher
latency.

A value of 25 is a reasonable one in many cases

OPTION: use filtercoef_error to retrieve exceptions

CapSense.FilterCoef(25)

sub filtercoef_error ()

dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")

end sub
IsInitialized As Boolean
ReadWait (EventName As String, msPause As Int)
Gets the capacitance reading in pico-Farade units.

Capacitance is measured by pushing a known amount of charge into the circuit,
and measuring the increase in voltage. As capacitance gets bigger, this
increase becomes smaller, and thus less accurate. As capacitance gets
smaller, the increase may become fast enough so it can saturate, i.e. reach
the maximum voltage. The system has been tuned to effectively sense
capacitance values typical of the human body, for touch sensors. The lowest
possible capacitance is about 27pF, and at about 2700pF the precision will be
around 10% (with high noise level unless filtered). The internal capacitance
of the system with some parasitic capacitance will normally be 30pF or more.
Human-body capacitance will typically be about 150pF without grounding, and
greater with grounding or when touching a large metallic surface.

This module provides a simple, single-pole IIR filtering, with configurable
time constant. There is a trade-off when selecting the time-constant: a longer
time constant will provide better noise filtering, but at the cost of a
slower response. In other words, it will take more time for the measured
value to reach the actual. A value of 25 is a reasonable one in many cases
which is configured via with OpenCapSense or setFilterCoef.

REQUIRED: use EventName_done to retrieve data or exceptions

CapSense.ReadWait("capsensew",0)

sub capsensewt_done (noerror as Boolean, result as Float)

if noerror then
'result contains the capacitance value
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if
WaitOver (EventName As String, threshhold As Float)
Raise done event when sensed capacitance becomes greater than a given threshold.

For using a touch surface such as a digital button, a threshold of 50pF is
normally useful, with some hysteresis recommended.

REQUIRED: use EventName_done to detect event or exceptions

CapSense.WaitOver("waitover",50)

sub waitover_done (noerror as Boolean)

if noerror then
' capacitance > 50pF sensed
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if
WaitUnder (EventName As String, threshhold As Float)
Raise done event when sensed capacitance becomes less than a given threshold.

For using a touch surface such as a digital button, a threshold of 50pF is
normally useful, with some hysteresis recommended.

REQUIRED: use EventName_done to detect event or exceptions

CapSense.WaitUnder("waitunder",50)

sub waitunder_done (noerror as Boolean)

if noerror then
' capacitance < 50pF sensed
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if

DigitalInput

This object contains a representation of a digital input.

Events:

None

Members:


  Close

  IP_FLOATING As ioio.lib.api.DigitalInput.Spec.Mode

  IP_PULL_DOWN As ioio.lib.api.DigitalInput.Spec.Mode

  IP_PULL_UP As ioio.lib.api.DigitalInput.Spec.Mode

  IsInitialized As Boolean

  Read As Boolean [read only]

  ReadWait (EventName As String, msPause As Int)

  waitForValue (EventName As String, value As Boolean)

Members description:

Close
Close the pin and make it available for further use.
IP_FLOATING As ioio.lib.api.DigitalInput.Spec.Mode
The digital input type to obtain a floating input.
Pin is floating. When the pin is left disconnected the value
sensed is undefined. Use this mode when an external pull-up or
pull-down resistor is used or when interfacing push-pull type
logic circuits.
IP_PULL_DOWN As ioio.lib.api.DigitalInput.Spec.Mode
The digital input type to obtain a pull down input.
Internal pull-up resistor is used. When the pin is left
disconnected, a logical "HIGH" (true) will be sensed. This is
useful for interfacing with open drain circuits or for
interacting with a switch connected between the pin and ground.
IP_PULL_UP As ioio.lib.api.DigitalInput.Spec.Mode
The digital input type to obtain a pull up input.
Internal pull-down resistor is used. When the pin is left
disconnected, a logical "LOW" (false) will be sensed. This is
useful for interacting with a switch connected between the pin
and Vdd.
IsInitialized As Boolean
Read As Boolean [read only]
Use the ReadWait method instead.

Read the value sensed on the pin. May block for a few milliseconds if
called right after creation of the instance.
ReadWait (EventName As String, msPause As Int)
Reads the value sensed on the pin, waits for a duration of
msPause and then raises an EventName_done.

REQUIRED: use EventName_done to retrieve data or exceptions

DigitalInput.ReadWait("rwait",0)

sub rwait_done (noerror as Boolean, result as Boolean)

if noerror then
'result contains the boolean value of the digital input
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if
waitForValue (EventName As String, value As Boolean)
This method will raise an EventName_done when the desired logical level is sensed.

REQUIRED: use EventName_done to retrieve data or exceptions

DigitalInput.waitForValue("wait",True)

sub wait_done (noerror as Boolean)

if noerror then
'True detected
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if

DigitalOutput

This object contains a representation of a digital output.

Events:

None

Members:


  Close

  IsInitialized As Boolean

  OP_NORMAL As ioio.lib.api.DigitalOutput.Spec.Mode

  OP_OPEN_DRAIN As ioio.lib.api.DigitalOutput.Spec.Mode

  Pulse (EventName As String, msHi As Int, msLow As Int, Cycles As Int)

  WriteWait (EventName As String, value As Boolean, msPause As Int)

Members description:

Close
Close the pin and make it available for further use.
IsInitialized As Boolean
OP_NORMAL As ioio.lib.api.DigitalOutput.Spec.Mode
The digital output type to obtain a normal output.
Pin operates in push-pull mode, i.e. a logical "HIGH" is
represented by a voltage of Vdd on the pin and a logical "LOW" by
a voltage of 0 (ground).
OP_OPEN_DRAIN As ioio.lib.api.DigitalOutput.Spec.Mode
The digital output type to obtain an open drain output.
Pin operates in open-drain mode, i.e. a logical "HIGH" is
represented by a high impedance on the pin (as if it is
disconnected) and a logical "LOW" by a voltage of 0 (ground).
This mode is most commonly used for generating 5V logical signal
on a 3.3V pin: 5V tolerant pins must be used; a pull-up resistor
is connected between the pin and 5V, and the pin is used in open-
drain mode.
Pulse (EventName As String, msHi As Int, msLow As Int, Cycles As Int)
Commands the IOIO to output a pulse on the pin.
Once the pulse is done an EventName_done is raised.

OPTION: use EventName_done to indicate the end of the pulse or to retrieve exceptions

'pulse low 100msec then hi for 100ms, repeats 10 times
DigitalOutput.pulse("event1",100,100,10)

sub event1_done (noerror as Boolean)

if noerror then
DigitalOutput.pulse("event2",100,100,10)
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if

end sub

sub event2_done (noerror as Boolean)
...
end sub
WriteWait (EventName As String, value As Boolean, msPause As Int)
Sets the output of the pin, waits a duration of msPause,
and then raises an EventName_done.

OPTION: use EventName_done to indicate the end of the wait or to retrieve exceptions.

DigitalOutput.WriteWait("writew",True,0)

sub writew_done (noerror as Boolean)

if noerror then
'msPause wait done after setting output
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if

end sub

IOIO

This IOIO object contains the interface to an IOIO board connected by
USB or Bluetooth. This interface provides control over all
the IOIO board functions.

Previous versions of the library, v1.7 and below, ran on the
same thread as your b4a application. Starting with this v1.8,
most of the library runs on a separate thread. This has
caused to library to change significantly. Be sure to take a look at
the IOIO Workbench application and documentation that is included with
this library to see how the implementation has changed.

An instance of this interface is obtained by using the Connect
method. The Connect method takes care of all the details needed
to connect to the IOIO. With the Connect method you can also connect
to multiple IOIOs simultaneously.

Most methods now return an event once it has completed on its own thread.
This event returns various types of data including all exceptions encountered.
Sometimes these events are made optional to facilitate writing code in B4A.
This however means that if you decide to not include an event you will not
see any exceptions thrown. Be sure to carefully look at each methods documentation
to see how the event is named and what data is returned.

Initially all pins are tri-stated (floating), and all functions are disabled.
Whenever a connection is lost or dropped, the board will immediately return
to the this initial state.

In the Basic4android IDE Library tab, ensure IOIO is selected. Once checked the
library version will be displayed.

Permissions:

android.permission.INTERNET
android.permission.BLUETOOTH
android.permission.BLUETOOTH_ADMIN

Events:

None

Members:


  BeginBatch

  BTPairedIOIOs As Int [read only]

  Connect (EventName As String, Bluetooth As Boolean, BTpair As Int, msPause As Int)

  Disconnect

  EndBatch

  getIOIOVersion (which As ioio.lib.api.IOIO.VersionType) As String

  HardReset

  Initialize (Bluetooth As Boolean, BTpair As Int)

  IsInitialized As Boolean

  OpenAnalogInput (EventName As String, pin As Int)

  OpenCapSense (EventName As String, pin As Int, filterTime As Float)

  OpenDigitalInput (EventName As String, pin As Int, mode As ioio.lib.api.DigitalInput.Spec.Mode)

  OpenDigitalOutput (EventName As String, pin As Int, mode As ioio.lib.api.DigitalOutput.Spec.Mode, startValue As Boolean)

  OpenPulseInput (EventName As String, pin As Int, ipmode As ioio.lib.api.DigitalInput.Spec.Mode, rate As ioio.lib.api.PulseInput.ClockRate, pulsemode As ioio.lib.api.PulseInput.PulseMode, doublePrecision As Boolean)

  OpenPwmOutput (EventName As String, pin As Int, mode As ioio.lib.api.DigitalOutput.Spec.Mode, freqHz As Int)

  OpenSpiMaster (EventName As String, misopin As Int, misomode As ioio.lib.api.DigitalInput.Spec.Mode, mosipin As Int, mosimode As ioio.lib.api.DigitalOutput.Spec.Mode, clkpin As Int, clkmode As ioio.lib.api.DigitalOutput.Spec.Mode, slaveselectpins() As Int, slaveselectmodes() As Object, rate As ioio.lib.api.SpiMaster.Rate, invertClk As Boolean, sampleOnTrailing As Boolean)

  OpenTwiMaster (EventName As String, twiNum As Int, rate As ioio.lib.api.TwiMaster.Rate, smbus As Boolean)

  OpenUart (EventName As String, rx As Int, rxmode As ioio.lib.api.DigitalInput.Spec.Mode, tx As Int, txmode As ioio.lib.api.DigitalOutput.Spec.Mode, baud As Int, parity As ioio.lib.api.Uart.Parity, stopbits As ioio.lib.api.Uart.StopBits)

  SoftReset

  State As ioio.lib.api.IOIO.State [read only]

  VER_BOOTLOADER As ioio.lib.api.IOIO.VersionType

  VER_FIRMWARE As ioio.lib.api.IOIO.VersionType

  VER_HARDWARE As ioio.lib.api.IOIO.VersionType

  VER_IOIOLIB As ioio.lib.api.IOIO.VersionType

  Version As Double [read only]

  WaitForConnect

Members description:

BeginBatch
Enables grouping a number of DigitalOutput.write() operations into a single
message that is sent to the IOIO, thus taking the latency hit only once
per group rather than once per operation. Call at the beginning
of a group of DigitalOutput.write() operations.

OPTION: you can use beginbatch_error to capture any exception

ioio.BeginBatch()

sub beginbatch_error

dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")

end sub
BTPairedIOIOs As Int [read only]
Returns the number of paired Bluetooth IOIOs that are available for connection.
Use the B4A Serial library to find out their addresses. The order here
should be the same as the Serial library but it is not guaranteed.

IMPORTANT: If Bluetooth is OFF on the Android device or the IOIO is OFF, this method will
still return the number of paired IOIOs that the Android device has remembered.
You will obviously not be able to connect until Bluetooth is ON and the IOIO is ON.
Connect (EventName As String, Bluetooth As Boolean, BTpair As Int, msPause As Int)
Use this method to connect to the IOIO.

The EventName_connected event is raised once the IOIO is connected.
It can be aborted by calling IOIO.disconnect.

BTpair is the IOIO paired to your device via Bluetooth to which you will
connect. If you are paired to multiple IOIO you can connect simultaneously
to the subsequent paired IOIOs. BTpair should be greater than 0 and
less than the max number of paired devices. It is ignored if Bluetooth is FALSE.

An exception will be thrown if you try to connect to a paired device but
Bluetooth is OFF or the IOIO is not ON.

IMPORTANT: You need to initialize an instance of BluetoothAdmin from the Serial library
before being able to connect to the IOIO using Bluetooth.

msPause is usually 0 but increase to 10 or more if you are having
problems connecting.

If the IOIO is already connected this method will first disconnect before
reconnecting.

In B4A you can use a timer to wait for a the connected
event. If the timer expires you can call disconnect and proceed
accordingly.

Below is an example connecting using Bluetooth.

Dim btadmin As BluetoothAdmin
btadmin.Initialize("btadmin")

if btadmin.IsEnabled Then IOIO.connect("event1",true,1,0)

sub event1_connected (noerror as Boolean)

if noerror then
'connected without problems
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if

end sub
Disconnect
Closes the connection to the board, or aborts a connection process

Once this method is called, this IOIO instance and all the instances
obtained from it become invalid and will throw an exception on every
operation. Connect can be called to obtain a new IOIO instance.

OPTION: you can use disconnect_done to tell when the disconnect is
complete.

ioio.Disconnect()

sub disconnect_done (noerror as Boolean)

if noerror then
'connected without problems
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if

end sub
EndBatch
Call to execute all DigitalOutput.write() operations cached
since ioio.beginBatch was called.

OPTION: you can use endbatch_error to capture any exception

ioio.EndBatch()

sub endbatch_error

dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")

end sub
getIOIOVersion (which As ioio.lib.api.IOIO.VersionType) As String
Query the implementation version of the system's components. The
implementation version uniquely identifies a hardware revision or a
software build. Returned version IDs are always 8-character long,
according to the IOIO versioning system: first 4 characters are the
version authority and last 4 characters are the revision.
HardReset
Equivalent to disconnecting and reconnecting the board power supply.
The connection will be dropped and not re-established. Full boot sequence
will take place, so firmware upgrades can be performed. A connection must
have been established prior to calling this method.

OPTION: you can use hardreset_error to capture any exception

ioio.HardReset()

sub hardreset_error

dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")

end sub
Initialize (Bluetooth As Boolean, BTpair As Int)
DEPRECATED: Please use Connect to connect to the IOIO.
IsInitialized As Boolean
Check if the IOIO instance has been initialized
OpenAnalogInput (EventName As String, pin As Int)
Open a pin for analog input.
An analog input pin can be used to measure voltage. Note that not every
pin can be used as an analog input. See board documentation for the legal
pins and permitted voltage range.
The pin will operate in this mode until close() is invoked on the
returned interface. It is illegal to open a pin that has already been
opened and has not been closed. A connection must have been established
prior to calling this method.

REQUIRED: use EventName_open to retrieve instance or exceptions

ioio.OpenAnalogInput("anain",10)

sub anain_open (noerror As Boolean, result As Object)

if noerror then
'assign instance
analoginput=result
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if

end sub
OpenCapSense (EventName As String, pin As Int, filterTime As Float)
Open a pin for cap-sense.

A cap-sense input pin can be used to measure capacitance, typically in
touch sensing applications. Note that not every pin can be used as cap-
sense. See board documentation for the legal pins.

The pin will operate in this mode until close()

The CapSense module includes a built-in filter, which you can configure
to be fast-and-noisy or slow-and-smooth (or any point in between).
Controlling this filter is done by setting a single value, which has a
time dimension. This time will tell us the typical rate of change of our
filtered signal. For example, setting it to 20-50ms will give us a rather
fast response, suitable for human interactions.

filterTime is in milliseconds.

REQUIRED: use EventName_open to retrieve instance or exceptions

ioio.OpenCapSense("capsense",40,25)

sub capsense_open (noerror As Boolean, result As Object)

if noerror then
'assign instance
capsense=result
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if

end sub
OpenDigitalInput (EventName As String, pin As Int, mode As ioio.lib.api.DigitalInput.Spec.Mode)
Open a pin for digital input.
A digital input pin can be used to read logic-level signals. The pin will
operate in this mode until close() is invoked on the returned interface.
It is illegal to open a pin that has already been opened and has not been
closed. A connection must have been established prior to calling this
method.

REQUIRED: use EventName_open to retrieve instance or exceptions

ioio.OpenDigitalInput("digin",10,digitalinput.IP_FLOATING)

sub digin_open (noerror As Boolean, result As Object)

if noerror then
'assign instance
digitalinput=result
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if

end sub
OpenDigitalOutput (EventName As String, pin As Int, mode As ioio.lib.api.DigitalOutput.Spec.Mode, startValue As Boolean)
Open a pin for digital output.
A digital output pin can be used to generate logic-level signals. The pin
will operate in this mode until close() is invoked on the returned
interface. It is illegal to open a pin that has already been opened and
has not been closed. A connection must have been established prior to
calling this method.

REQUIRED: use EventName_open to retrieve instance or exceptions

ioio.OpenDigitalOutput("digout",10,digitaloutput.OP_NORMAL,False)

sub digout_open (noerror As Boolean, result As Object)

if noerror then
'assign instance
digitaloutput=result
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if

end sub
OpenPulseInput (EventName As String, pin As Int, ipmode As ioio.lib.api.DigitalInput.Spec.Mode, rate As ioio.lib.api.PulseInput.ClockRate, pulsemode As ioio.lib.api.PulseInput.PulseMode, doublePrecision As Boolean)
Open a pin for pulse input.
The pulse input module is quite flexible. It enables several kinds of
timing measurements on a digital signal: pulse width measurement
(positive or negative pulse), and frequency of a periodic signal.
Note that not every pin can be used as pulse input. In addition, the
total number of concurrent pulse input modules in use is limited. See
board documentation for the legal pins and limit on concurrent usage.
The pin will operate in this mode until close() is invoked on the
returned interface. It is illegal to open a pin that has already been
opened and has not been closed. A connection must have been established
prior to calling this method.

rate
The clock rate to use for timing the signal. A faster clock
rate will result in better precision but will only be able to
measure narrow pulses / high frequencies.
pulse mode
The mode in which to operate. Determines whether the module
will measure pulse durations or frequency.
doublePrecision
Whether to open a double-precision pulse input module. Double-
precision modules enable reading of much longer pulses and
lower frequencies with high accuracy than single precision
modules. However, their number is limited, so when possible,
and if the resources are all needed, use single-precision.

For more details see
this link

REQUIRED: use EventName_open to retrieve instance or exceptions

ioio.OpenPulseInput("pulsein",10,pulseinput.IP_FLOATING,
pulseinput.RATE_250KHZ,pulseinput.FREQ,True)

sub pulsein_open (noerror As Boolean, result As Object)

if noerror then
'assign instance
pulseinput=result
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if

end sub
OpenPwmOutput (EventName As String, pin As Int, mode As ioio.lib.api.DigitalOutput.Spec.Mode, freqHz As Int)
Open a pin for PWM (Pulse-Width Modulation) output in the specified mo.
A PWM pin produces a logic-level PWM signal. These signals are typically
used for simulating analog outputs for controlling the intensity of LEDs,
the rotation speed of motors, etc. They are also frequently used for
controlling hobby servo motors.
Note that not every pin can be used as PWM output. In addition, the total
number of concurrent PWM modules in use is limited. See board
documentation for the legal pins and limit on concurrent usage.
The pin will operate in this mode until close() is invoked on the
returned interface. It is illegal to open a pin that has already been
opened and has not been closed. A connection must have been established
prior to calling this method.

IMPORTANT: Call pulsewidth or dutycycle to start the pwm signal

REQUIRED: use EventName_open to retrieve instance or exceptions

ioio.OpenPulseOutput("pulseout",10,pulseoutput.OP_NORMAL,500)

sub pulseout_open (noerror As Boolean, result As Object)

if noerror then
'assign instance
pulseoutput=result
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if

end sub
OpenSpiMaster (EventName As String, misopin As Int, misomode As ioio.lib.api.DigitalInput.Spec.Mode, mosipin As Int, mosimode As ioio.lib.api.DigitalOutput.Spec.Mode, clkpin As Int, clkmode As ioio.lib.api.DigitalOutput.Spec.Mode, slaveselectpins() As Int, slaveselectmodes() As Object, rate As ioio.lib.api.SpiMaster.Rate, invertClk As Boolean, sampleOnTrailing As Boolean)
Open a SPI master module, enabling communication with multiple
SPI-enabled slave modules.

SPI is a common hardware communication protocol, enabling full-duplex,
synchronous point-to-multi-point data transfer. It requires MOSI, MISO
and CLK lines shared by all nodes, as well as a SS line per slave,
connected between this slave and a respective pin on the master. The MISO
line should operate in pull-up mode, using either the internal pull-up or
an external resistor.

See board documentation for the legal pins and limit on concurrent usage.

The SPI module will operate, and the pins will work in their respective
modes until close() is invoked.

MISOXXX: Pin and mode specification for the MISO (Master In Slave Out) pin,
consisting of the pin number, as labeled on the board, and the
mode. See DigitalInput for more mode information.
MOSIXXX: Pin and modespecification for the MOSI (Master Out Slave In) pin,
consisting of the pin number, as labeled on the board, and the
mode. See DigitalOutput for more mode information.
CLKXXX: Pin and mode specification for the CLK pin, consisting of the pin number,
as labeled on the board, and the mode. See DigitalOutput for more mode information.
SLAVESELECTXXX(): Arrays of pin and mode specifications for each of the slaves' SS
(Slave Select) pin. The index of an array designates the slave index,
used later to refer to this slave. Slaveselectpins is an Int array
specify the pin number, as labeled on the board, and slaveselectmodes is an
Object array of DigitalOut.(modes). See DigitalOutput for more mode information.
RATE: Data rate.
INVERTCLK: Whether to invert clock polarity.
SAMPLEONTRAILING: Whether to do the input and output sampling on the
trailing clock edge.

REQUIRED: use EventName_open to retrieve instance or exceptions

Dim slave(1) as Int
slave(0)=14 'Pin # of attached Slave's SS pin
Dim slavemode(1) As Object
slavemode(0)=digitalout.OP_NORMAL 'slave pin mode

ioio.OpenSpiMaster("spi",10,spi1.IP_FLOATING,11,spi1.OP_NORMAL,13,spi1.OP_NORMAL
slave,slavemode,spi1.RATE_125K,False,False)

sub spi_open (noerror As Boolean, result As Object)

if noerror then
'assign instance
spi1=result
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if

end sub
OpenTwiMaster (EventName As String, twiNum As Int, rate As ioio.lib.api.TwiMaster.Rate, smbus As Boolean)
Open a TWI (Two-Wire Interface, such as I2C/SMBus) master module,
enabling communication with multiple TWI-enabled slave modules.

TWI is a common hardware communication protocol, enabling half-duplex,
synchronous point-to-multi-point data transfer. It requires a physical
connection of two lines (SDA, SCL) shared by all the bus nodes, where the
SDA is open-drain and externally pulled-up.

Note that there is a fixed number of TWI modules, and the pins they use
are static. Client has to make sure these pins are not already opened
before calling this method. See board documentation for the number of
modules and the respective pins they use.

The TWI module will operate, and the pins will work in their respective
modes until close() is invoked on the returned interface. It is illegal
to use pins that have already been opened and has not been closed. A
connection must have been established prior to calling this method.

TWINUM: The TWI module index to use. Will also determine the pins used.
RATE: The clock rate. Can be RATE_100KHz / RATE_400KHz / RATE_1MHz.
SMBUS: When true, will use SMBus voltage levels. When false, I2C voltage levels.

REQUIRED: use EventName_open to retrieve instance or exceptions

ioio.OpenPulseOutput("twi",10,twi1.RATE_100KHZ,False)

sub twi_open (noerror As Boolean, result As Object)

if noerror then
'assign instance
twi1=result
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if

end sub
OpenUart (EventName As String, rx As Int, rxmode As ioio.lib.api.DigitalInput.Spec.Mode, tx As Int, txmode As ioio.lib.api.DigitalOutput.Spec.Mode, baud As Int, parity As ioio.lib.api.Uart.Parity, stopbits As ioio.lib.api.Uart.StopBits)
Open a UART module, enabling a bulk transfer of byte buffers.
UART is a very common hardware communication protocol, enabling full-
duplex, asynchronous point-to-point data transfer. It typically serves
for opening consoles or as a basis for higher-level protocols, such as
MIDI RS-232, and RS-485.

Note that not every pin can be used for UART RX or TX. In addition, the
total number of concurrent UART modules in use is limited. See board
documentation for the legal pins and limit on concurrent usage.

The UART module will operate, and the pins will work in their respective
modes until close() is invoked on the returned interface. It is illegal
to use pins that have already been opened and has not been closed. A
connection must have been established prior to calling this method.

RX: Pin specification for the RX pin, consisting of the pin number
as labeled on the board. Uart.NO_PIN can be passed to designate
that we do not want RX input.

RXMODE: The mode of the rx pin. Uart.

TX: Pin specification for the TX pin, consisting of the pin number
as labeled on the board. Uart.NO_PIN can be passed to designate
that we do not want TX output.

TXMODE: The mode of the rx pin. Uart.

BAUD: The baud rate: 9600, 19200, 38400, 115200, etc. Int.

PARITY: The parity mode: NONE, EVEN, ODD. Uart

STOPBITS: Number of stop bits: ONE, TWO. Uart

REQUIRED: use EventName_open to retrieve instance or exceptions

ioio.OpenUart("uart",10,uart1.IP_FLOATING,11,uart1.IP_NORMAL,9600,
uart1.PARITY_NONE,uart1.STOPBIT_ONE)

sub uart_open (noerror As Boolean, result As Object, in As Object, out As Object)

if noerror then
uart1=result 'assign instance
instrm=in 'retrieve InputStream here
outstrm=out 'retrieve OutputSteam here
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if

end sub
SoftReset
Resets the entire state (returning to initial state), without dropping
the connection. It is equivalent to calling close() on every interface
obtained from this instance. A connection must have been established
prior to calling this method, by invoking waitForConnect().

OPTION: you can use softreset_error to capture any exception

ioio.SoftReset()

sub softreset_error

dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")

end sub
State As ioio.lib.api.IOIO.State [read only]
Returns the state of the IOIO connection.

INIT - Connection not yet established.
CONNECTED - Connected.
INCOMPATIBLE - Connection established, incompatible firmware detected.
DEAD - Disconnected. Instance is useless.
VER_BOOTLOADER As ioio.lib.api.IOIO.VersionType
The version type to obtain the version of the IOIO bootloader.
VER_FIRMWARE As ioio.lib.api.IOIO.VersionType
The version type to obtain the version of the IOIO firmware.
VER_HARDWARE As ioio.lib.api.IOIO.VersionType
The version type to obtain the version of the IOIO hardware.
VER_IOIOLIB As ioio.lib.api.IOIO.VersionType
The version type to obtain the version of the IOIOlib library.
Version As Double [read only]
Returns the version of the library.
WaitForConnect
DEPRECATED: Please use the Connect method to connect to the IOIO.

PulseInput

This object contains a representation of a pulse input.

Events:

None

Members:


  Close

  Duration (EventName As String)

  FREQ As ioio.lib.api.PulseInput.PulseMode

  FREQ_SCALE_16 As ioio.lib.api.PulseInput.PulseMode

  FREQ_SCALE_4 As ioio.lib.api.PulseInput.PulseMode

  Frequency (EventName As String)

  IP_FLOATING As ioio.lib.api.DigitalInput.Spec.Mode

  IP_PULL_DOWN As ioio.lib.api.DigitalInput.Spec.Mode

  IP_PULL_UP As ioio.lib.api.DigitalInput.Spec.Mode

  IsInitialized As Boolean

  NEGATIVE As ioio.lib.api.PulseInput.PulseMode

  POSITIVE As ioio.lib.api.PulseInput.PulseMode

  RATE_16MHZ As ioio.lib.api.PulseInput.ClockRate

  RATE_250KHZ As ioio.lib.api.PulseInput.ClockRate

  RATE_2MHZ As ioio.lib.api.PulseInput.ClockRate

  RATE_625KHZ As ioio.lib.api.PulseInput.ClockRate

  WaitPulseDuration (EventName As String)

Members description:

Close
Close the pin and make it available for further use.
Duration (EventName As String)
Gets the pulse duration in case of pulse measurement mode, or the period
in case of frequency mode. When scaling is used, this is compensated for
here, so the duration of a single cycle will be returned.

Result is the duration, in seconds.

REQUIRED: use EventName_done to indicate result is ready or to retrieve exceptions

PulseInput.Duration("pulsedur")

sub pulsedur_done (noerror as Boolean, result as Float)

if noerror then
msgbox(result,"Duration read")
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if

end sub
FREQ As ioio.lib.api.PulseInput.PulseMode
The PulseMode for Frequency measurement (rising-edge-to-rising-edge).
FREQ_SCALE_16 As ioio.lib.api.PulseInput.PulseMode
The PulseMode for Frequency measurement (rising-edge-to-rising-edge) with 16x scaling.
FREQ_SCALE_4 As ioio.lib.api.PulseInput.PulseMode
The PulseMode for Frequency measurement (rising-edge-to-rising-edge) with 4x scaling.
Frequency (EventName As String)
Gets the momentary frequency of the measured signal. When scaling is
used, this is compensated for here, so the true frequency of the signal
will be returned.

Result is the frequency in Hz.

REQUIRED: use EventName_done to indicate result is ready or to retrieve exceptions

PulseInput.Frequency("freq")

sub freq_done (noerror as Boolean, result as Float)

if noerror then
msgbox(result,"Frequency read")
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if

end sub
IP_FLOATING As ioio.lib.api.DigitalInput.Spec.Mode
The digital input type to obtain a floating input.
Pin is floating. When the pin is left disconnected the value
sensed is undefined. Use this mode when an external pull-up or
pull-down resistor is used or when interfacing push-pull type
logic circuits.
IP_PULL_DOWN As ioio.lib.api.DigitalInput.Spec.Mode
The digital input type to obtain a pull down input.
Internal pull-up resistor is used. When the pin is left
disconnected, a logical "HIGH" (true) will be sensed. This is
useful for interfacing with open drain circuits or for
interacting with a switch connected between the pin and ground.
IP_PULL_UP As ioio.lib.api.DigitalInput.Spec.Mode
The digital input type to obtain a pull up input.
Internal pull-down resistor is used. When the pin is left
disconnected, a logical "LOW" (false) will be sensed. This is
useful for interacting with a switch connected between the pin
and Vdd.
IsInitialized As Boolean
NEGATIVE As ioio.lib.api.PulseInput.PulseMode
The PulseMode for Negative pulse measurement (falling-edge-to-rising-edge).
POSITIVE As ioio.lib.api.PulseInput.PulseMode
The PulseMode for Positive pulse measurement (rising-edge-to-falling-edge).
RATE_16MHZ As ioio.lib.api.PulseInput.ClockRate
The ClockRate for 16MHz.
RATE_250KHZ As ioio.lib.api.PulseInput.ClockRate
The ClockRate for 250KHz.
RATE_2MHZ As ioio.lib.api.PulseInput.ClockRate
The ClockRate for 2MHz.
RATE_625KHZ As ioio.lib.api.PulseInput.ClockRate
The ClockRate for 625KHz.
WaitPulseDuration (EventName As String)
Reads a single measurement from the queue. If the queue is empty, will
block until more data arrives. The calling thread may be interrupted in
order to abort the call. See interface documentation for further
explanation regarding the read queue.

This method may not be used if the interface has was opened in frequency
mode.

Result is the duration, in seconds.

REQUIRED: use EventName_done to indicate result is ready or to retrieve exceptions

PulseInput.WaitPulseDuration("wpulsedur")

sub wpulsedur_done (noerror as Boolean, result as Float)

if noerror then
msgbox(result,"Duration read")
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if

end sub

PwmOutput

This object contains a representation of an PWM output.

Events:

None

Members:


  Close

  DutyCycle (dutyCycle As Float, msPause As Int)

  IsInitialized As Boolean

  OP_NORMAL As ioio.lib.api.DigitalOutput.Spec.Mode

  OP_OPEN_DRAIN As ioio.lib.api.DigitalOutput.Spec.Mode

  PulseWidth (pulseWidthUs As Int, msPause As Int)

  PulseWidthSweep (EventName As String, pulseWidthStart As Int, pulseWidthEnd As Int, step As Int, msPause As Int)

Members description:

Close
Close the pin and make it available for further use.
DutyCycle (dutyCycle As Float, msPause As Int)
Sets the duty cycle of the PWM output. The duty cycle is defined to be
the pulse width divided by the total cycle period. For absolute control
of the pulse with, consider using PulseWidth(int).

msPause is the time in ms to wait before raising done event.

OPTION: use dutycycle_error to retrieve exceptions

PulseOutput.DutyCycle(0.25,10)

sub dutycycle_done

dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")

end sub
IsInitialized As Boolean
OP_NORMAL As ioio.lib.api.DigitalOutput.Spec.Mode
The digital output type to obtain a normal output.
Pin operates in push-pull mode, i.e. a logical "HIGH" is
represented by a voltage of Vdd on the pin and a logical "LOW" by
a voltage of 0 (ground).
OP_OPEN_DRAIN As ioio.lib.api.DigitalOutput.Spec.Mode
The digital output type to obtain an open drain output.
Pin operates in open-drain mode, i.e. a logical "HIGH" is
represented by a high impedance on the pin (as if it is
disconnected) and a logical "LOW" by a voltage of 0 (ground).
This mode is most commonly used for generating 5V logical signal
on a 3.3V pin: 5V tolerant pins must be used; a pull-up resistor
is connected between the pin and 5V, and the pin is used in open-
drain mode.
PulseWidth (pulseWidthUs As Int, msPause As Int)
Sets the pulse width of the PWM output to the specified number of microSeconds. (micro not milli!)
The pulse width is duration of the high-time within a single period of the signal.
For relative control of the pulse with, consider using DutyCycle(float).

msPause is the time in ms to wait before raising done event.

OPTION: use pulsewidth_done to detect end or to retrieve exceptions

PulseOutput.pulsewidth(500,10)

sub pulsewidth_done

dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")

end sub
PulseWidthSweep (EventName As String, pulseWidthStart As Int, pulseWidthEnd As Int, step As Int, msPause As Int)
Changes the pulsewidth from pulseWidthStart to pulseWidthEnd by step with a msPause in ms b/w each loop.
Step should always be positive. Just make start is greater than end to count backwards.

Usefull for better control of servos

OPTION: use EventName_done to indicate progression is done or to retrieve exceptions

sub pulsewidthsweep_done (noerror as Boolean)

if noerror then
msgbox("sweep finished")
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if

end sub

SpiMaster

This object contains a representation of an SpiMaster.

Events:

None

Members:


  Close

  IP_FLOATING As ioio.lib.api.DigitalInput.Spec.Mode

  IP_PULL_DOWN As ioio.lib.api.DigitalInput.Spec.Mode

  IP_PULL_UP As ioio.lib.api.DigitalInput.Spec.Mode

  IsInitialized As Boolean

  OP_NORMAL As ioio.lib.api.DigitalOutput.Spec.Mode

  OP_OPEN_DRAIN As ioio.lib.api.DigitalOutput.Spec.Mode

  RATE_1_3M As ioio.lib.api.SpiMaster.Rate

  RATE_125K As ioio.lib.api.SpiMaster.Rate

  RATE_142K As ioio.lib.api.SpiMaster.Rate

  RATE_166K As ioio.lib.api.SpiMaster.Rate

  RATE_1M As ioio.lib.api.SpiMaster.Rate

  RATE_2_2M As ioio.lib.api.SpiMaster.Rate

  RATE_2_6M As ioio.lib.api.SpiMaster.Rate

  RATE_200K As ioio.lib.api.SpiMaster.Rate

  RATE_250K As ioio.lib.api.SpiMaster.Rate

  RATE_2M As ioio.lib.api.SpiMaster.Rate

  RATE_3_2M As ioio.lib.api.SpiMaster.Rate

  RATE_31K As ioio.lib.api.SpiMaster.Rate

  RATE_333K As ioio.lib.api.SpiMaster.Rate

  RATE_35K As ioio.lib.api.SpiMaster.Rate

  RATE_41K As ioio.lib.api.SpiMaster.Rate

  RATE_4M As ioio.lib.api.SpiMaster.Rate

  RATE_5_3M As ioio.lib.api.SpiMaster.Rate

  RATE_500K As ioio.lib.api.SpiMaster.Rate

  RATE_50K As ioio.lib.api.SpiMaster.Rate

  RATE_571K As ioio.lib.api.SpiMaster.Rate

  RATE_62K As ioio.lib.api.SpiMaster.Rate

  RATE_666K As ioio.lib.api.SpiMaster.Rate

  RATE_800K As ioio.lib.api.SpiMaster.Rate

  RATE_83K As ioio.lib.api.SpiMaster.Rate

  RATE_8M As ioio.lib.api.SpiMaster.Rate

  Status As Boolean [read only]

  WriteRead (EventName As String, slave As Int, writeData() As Byte, writeSize As Int, totalSize As Int, readData() As Byte, readSize As Int)

  WriteReadAsync (EventName As String, slave As Int, writeData() As Byte, writeSize As Int, totalSize As Int, readData() As Byte, readSize As Int, msPause As Int)

Members description:

Close
Close the pins and make them available for further use.
IP_FLOATING As ioio.lib.api.DigitalInput.Spec.Mode
The digital input type to obtain a floating input. See DigitalInput.
IP_PULL_DOWN As ioio.lib.api.DigitalInput.Spec.Mode
The digital input type to obtain a pull down input. See DigitalInput.
IP_PULL_UP As ioio.lib.api.DigitalInput.Spec.Mode
The digital input type to obtain a pull up input. See DigitalInput.
IsInitialized As Boolean
OP_NORMAL As ioio.lib.api.DigitalOutput.Spec.Mode
The digital output type to obtain a normal output. See DigitalOuput.
OP_OPEN_DRAIN As ioio.lib.api.DigitalOutput.Spec.Mode
The digital output type to obtain an open drain output. See DigitalOuput.
RATE_1_3M As ioio.lib.api.SpiMaster.Rate
RATE_125K As ioio.lib.api.SpiMaster.Rate
RATE_142K As ioio.lib.api.SpiMaster.Rate
RATE_166K As ioio.lib.api.SpiMaster.Rate
RATE_1M As ioio.lib.api.SpiMaster.Rate
RATE_2_2M As ioio.lib.api.SpiMaster.Rate
RATE_2_6M As ioio.lib.api.SpiMaster.Rate
RATE_200K As ioio.lib.api.SpiMaster.Rate
RATE_250K As ioio.lib.api.SpiMaster.Rate
RATE_2M As ioio.lib.api.SpiMaster.Rate
RATE_3_2M As ioio.lib.api.SpiMaster.Rate
RATE_31K As ioio.lib.api.SpiMaster.Rate
RATE_333K As ioio.lib.api.SpiMaster.Rate
RATE_35K As ioio.lib.api.SpiMaster.Rate
RATE_41K As ioio.lib.api.SpiMaster.Rate
RATE_4M As ioio.lib.api.SpiMaster.Rate
RATE_5_3M As ioio.lib.api.SpiMaster.Rate
RATE_500K As ioio.lib.api.SpiMaster.Rate
RATE_50K As ioio.lib.api.SpiMaster.Rate
RATE_571K As ioio.lib.api.SpiMaster.Rate
RATE_62K As ioio.lib.api.SpiMaster.Rate
RATE_666K As ioio.lib.api.SpiMaster.Rate
RATE_800K As ioio.lib.api.SpiMaster.Rate
RATE_83K As ioio.lib.api.SpiMaster.Rate
RATE_8M As ioio.lib.api.SpiMaster.Rate
Status As Boolean [read only]
Use the WriteRead method.

Returns a Boolean indicating the status of the last writeReadAsync call.
If successful the read data will be available in the array passed to WriteReadAsync.
WriteRead (EventName As String, slave As Int, writeData() As Byte, writeSize As Int, totalSize As Int, readData() As Byte, readSize As Int)
Perform a single SPI transaction which includes optional transmission and
optional reception of data to a single slave.

SLAVE: The slave index. It is determined by the index of its
slave-select pin, as per the array passed to OpenSpiMaster. For the
first slave pass 0, for the second 1, etc.

WRITEDATA: A byte array of data to write. May be 0 if writeSize is 0.
WRITESIZE: Number of bytes to write. Valid values are 0 to totalSize.
TOTALSIZE: Total transaction length, in bytes. Valid values are 1 to 64.
READATA: An array where the response is to be stored. May be 0 if readSize is 0.
READSIZE: The number of expected response bytes. Valid values are 0 to totalSize.
MSPAUSE: Delay before raising done event in ms.

OPTION: use EventName_done to retrieve exceptions

spi1.WriteRead("spi",0,bufferout,5,5,bufferin,5)

sub spi_done (noerror as Boolean, writebuffer() as Byte, readbuffer() as Byte, msPause as Int)

if noerror then
'check bufferin for data
writebuffer 'bytes sent to address
readbuffer 'bytes sent from address
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if

end sub
WriteReadAsync (EventName As String, slave As Int, writeData() As Byte, writeSize As Int, totalSize As Int, readData() As Byte, readSize As Int, msPause As Int)
Use the WriteRead method instead.

The same as writeRead(int, byte[], int, int, byte[], int)}, but returns immediately.
Use Status to determine when the transaction is complete.

spi1.WriteReadAsync("spi",0,bufferout,5,5,bufferin,5)

sub spi_done (noerror as Boolean, writebuffer() as Byte, readbuffer() as Byte)

TwiMaster

This object contains a representation of a TwiMaster.

Events:

None

Members:


  Close

  IsInitialized As Boolean

  RATE_100KHZ As ioio.lib.api.TwiMaster.Rate

  RATE_1MHz As ioio.lib.api.TwiMaster.Rate

  RATE_400KHZ As ioio.lib.api.TwiMaster.Rate

  Status() As Boolean [read only]

  WriteRead (EventName As String, address As Int, tenBitAddr As Boolean, writeData() As Byte, writeSize As Int, readData() As Byte, readSize As Int, msPause As Int)

  WriteReadAsync (EventName As String, address As Int, tenBitAddr As Boolean, writeData() As Byte, writeSize As Int, readData() As Byte, readSize As Int)

Members description:

Close
Close the pins and make them available for further use.
IsInitialized As Boolean
RATE_100KHZ As ioio.lib.api.TwiMaster.Rate
RATE_1MHz As ioio.lib.api.TwiMaster.Rate
RATE_400KHZ As ioio.lib.api.TwiMaster.Rate
Status() As Boolean [read only]
Use the WriteRead method instead.

Returns a Boolean(2) array indicating the status of the last writeReadAsync call.
The value at index 0 indicates whether the transaction has completed.
If index 0 is True then index 1 indicates whether the transaction succeeded.
If successful the read data will be available in the array passed to WriteReadAsync.
WriteRead (EventName As String, address As Int, tenBitAddr As Boolean, writeData() As Byte, writeSize As Int, readData() As Byte, readSize As Int, msPause As Int)
Perform a single TWI transaction which includes optional transmission and
optional reception of data to a single slave.

ADDRESS: The slave address, either 7-bit or 10-bit. Note that in some
TWI device documentation the documented addresses are actually
2x the address values used here, as they regard the trailing
0-bit as part of the address.
TENBITADDR: Whether this is a 10-bit addressing mode.
WRITEDATA: The request data.
WRITESIZE: The number of bytes to write. Valid value are 0-255.
READDATA: The array where the response should be stored.
READSIZE: The expected number of response bytes. Valid value are 0-255.
MSPAUSE: Delay before raising done event in ms.

OPTION: use EventName_done to see if transaction succeeded or retrieve exceptions

twi1.WriteRead("twi",1,False,bufferout,5,bufferin,5)

sub twi_done (noerror as Boolean, result as Boolean, writebuffer() as Byte, readbuffer() as Byte, msPause as Int)

if noerror then
msgbox(result,"Success?")
writebuffer 'bytes sent to address
readbuffer 'bytes sent from address
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if

end sub
WriteReadAsync (EventName As String, address As Int, tenBitAddr As Boolean, writeData() As Byte, writeSize As Int, readData() As Byte, readSize As Int)
Use the WriteRead method instead.

Asynchronous version of writeRead. Returns immediately.
Use Status to determine when the transaction is complete.

twi1.WriteReadAsync("twi",1,False,bufferout,5,bufferin,5)

sub twi_done (noerror as Boolean, writebuffer() as Byte, readbuffer() as Byte)

Uart

This object contains a representation of a Uart.

Events:

None

Members:


  Close

  InputStream (EventName As String)

  IP_FLOATING As ioio.lib.api.DigitalInput.Spec.Mode

  IP_PULL_DOWN As ioio.lib.api.DigitalInput.Spec.Mode

  IP_PULL_UP As ioio.lib.api.DigitalInput.Spec.Mode

  IsInitialized As Boolean

  NO_PIN As Int

  OP_NORMAL As ioio.lib.api.DigitalOutput.Spec.Mode

  OP_OPEN_DRAIN As ioio.lib.api.DigitalOutput.Spec.Mode

  OutputStream (EventName As String)

  PARITY_EVEN As ioio.lib.api.Uart.Parity

  PARITY_NONE As ioio.lib.api.Uart.Parity

  PARITY_ODD As ioio.lib.api.Uart.Parity

  STOPBIT_ONE As ioio.lib.api.Uart.StopBits

  STOPBITS_TWO As ioio.lib.api.Uart.StopBits

Members description:

Close
Close the pins and make them available for further use.
InputStream (EventName As String)
IMPORTANT: This method is not needed. Use OpenUart to get the InputStream

sub EventName_done (noexception as Boolean, result as InputStream)

if noexception then
' InputStream returned in result
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if

end sub
IP_FLOATING As ioio.lib.api.DigitalInput.Spec.Mode
The digital input type to obtain a floating input. See DigitalInput.
IP_PULL_DOWN As ioio.lib.api.DigitalInput.Spec.Mode
The digital input type to obtain a pull down input. See DigitalInput.
IP_PULL_UP As ioio.lib.api.DigitalInput.Spec.Mode
The digital input type to obtain a pull up input. See DigitalInput.
IsInitialized As Boolean
NO_PIN As Int
The pin number to specify if either RX or TX is not required.
OP_NORMAL As ioio.lib.api.DigitalOutput.Spec.Mode
The digital output type to obtain a normal output. See DigitalOuput.
OP_OPEN_DRAIN As ioio.lib.api.DigitalOutput.Spec.Mode
The digital output type to obtain an open drain output. See DigitalOuput.
OutputStream (EventName As String)
IMPORTANT: This method is not needed. Use OpenUart to get the OutputStream

sub EventName_done (noexception as Boolean, result as OutputStream)

if noexception then
' OutputStream returned in result
else
dim trouble as Exception
trouble=LastException
msgbox("trouble.message","Exception")
end if

end sub
PARITY_EVEN As ioio.lib.api.Uart.Parity
Selects even parity
PARITY_NONE As ioio.lib.api.Uart.Parity
Selects no parity
PARITY_ODD As ioio.lib.api.Uart.Parity
Selects odd parity
STOPBIT_ONE As ioio.lib.api.Uart.StopBits
Selects one stopbit
STOPBITS_TWO As ioio.lib.api.Uart.StopBits
Selects two stopbits
Top