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.
Gets the number of samples currently in the buffer. Reading that many samples is guaranteed not to block.
BufferAsInt [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.
IsInitializedAsBoolean
OverflowCountAsInt [read only]
Gets the number of samples that have been dropped as result of overflow.
ReadAsFloat [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().
ReadBufferedAsFloat [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.
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 (EventNameAsString, msPauseAsInt)
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
ReferenceAsFloat [read only]
Gets the maximum voltage value against which read() values are scaled.
SampleRateAsFloat [read only]
Gets the sample rate used for obtaining buffered samples. This is currently a constant.
VoltageAsFloat [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().
VoltageBufferedAsFloat [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.
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 (EventNameAsString, msPauseAsInt)
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
Close the pin and make it available for further use.
FilterCoef (filterTimeAsFloat)
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
IsInitializedAsBoolean
ReadWait (EventNameAsString, msPauseAsInt)
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 (EventNameAsString, threshholdAsFloat)
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 (EventNameAsString, threshholdAsFloat)
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
Close the pin and make it available for further use.
IP_FLOATINGAsioio.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_DOWNAsioio.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_UPAsioio.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.
IsInitializedAsBoolean
ReadAsBoolean [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 (EventNameAsString, msPauseAsInt)
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 (EventNameAsString, valueAsBoolean)
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
Close the pin and make it available for further use.
IsInitializedAsBoolean
OP_NORMALAsioio.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).
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.
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
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
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.
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
BTPairedIOIOsAsInt [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.
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")
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 (BluetoothAsBoolean, BTpairAsInt)
DEPRECATED: Please use Connect to connect to the IOIO.
IsInitializedAsBoolean
Check if the IOIO instance has been initialized
OpenAnalogInput (EventNameAsString, pinAsInt)
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
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
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
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
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.
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
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
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
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
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
StateAsioio.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_BOOTLOADERAsioio.lib.api.IOIO.VersionType
The version type to obtain the version of the IOIO bootloader.
VER_FIRMWAREAsioio.lib.api.IOIO.VersionType
The version type to obtain the version of the IOIO firmware.
VER_HARDWAREAsioio.lib.api.IOIO.VersionType
The version type to obtain the version of the IOIO hardware.
VER_IOIOLIBAsioio.lib.api.IOIO.VersionType
The version type to obtain the version of the IOIOlib library.
VersionAsDouble [read only]
Returns the version of the library.
WaitForConnect
DEPRECATED: Please use the Connect method to connect to the IOIO.
Close the pin and make it available for further use.
Duration (EventNameAsString)
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
FREQAsioio.lib.api.PulseInput.PulseMode
The PulseMode for Frequency measurement (rising-edge-to-rising-edge).
FREQ_SCALE_16Asioio.lib.api.PulseInput.PulseMode
The PulseMode for Frequency measurement (rising-edge-to-rising-edge) with 16x scaling.
FREQ_SCALE_4Asioio.lib.api.PulseInput.PulseMode
The PulseMode for Frequency measurement (rising-edge-to-rising-edge) with 4x scaling.
Frequency (EventNameAsString)
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_FLOATINGAsioio.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_DOWNAsioio.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_UPAsioio.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.
IsInitializedAsBoolean
NEGATIVEAsioio.lib.api.PulseInput.PulseMode
The PulseMode for Negative pulse measurement (falling-edge-to-rising-edge).
POSITIVEAsioio.lib.api.PulseInput.PulseMode
The PulseMode for Positive pulse measurement (rising-edge-to-falling-edge).
RATE_16MHZAsioio.lib.api.PulseInput.ClockRate
The ClockRate for 16MHz.
RATE_250KHZAsioio.lib.api.PulseInput.ClockRate
The ClockRate for 250KHz.
RATE_2MHZAsioio.lib.api.PulseInput.ClockRate
The ClockRate for 2MHz.
RATE_625KHZAsioio.lib.api.PulseInput.ClockRate
The ClockRate for 625KHz.
WaitPulseDuration (EventNameAsString)
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
Close the pin and make it available for further use.
DutyCycle (dutyCycleAsFloat, msPauseAsInt)
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
IsInitializedAsBoolean
OP_NORMALAsioio.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).
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 (pulseWidthUsAsInt, msPauseAsInt)
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")
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
The digital output type to obtain an open drain output. See DigitalOuput.
RATE_1_3MAsioio.lib.api.SpiMaster.Rate
RATE_125KAsioio.lib.api.SpiMaster.Rate
RATE_142KAsioio.lib.api.SpiMaster.Rate
RATE_166KAsioio.lib.api.SpiMaster.Rate
RATE_1MAsioio.lib.api.SpiMaster.Rate
RATE_2_2MAsioio.lib.api.SpiMaster.Rate
RATE_2_6MAsioio.lib.api.SpiMaster.Rate
RATE_200KAsioio.lib.api.SpiMaster.Rate
RATE_250KAsioio.lib.api.SpiMaster.Rate
RATE_2MAsioio.lib.api.SpiMaster.Rate
RATE_3_2MAsioio.lib.api.SpiMaster.Rate
RATE_31KAsioio.lib.api.SpiMaster.Rate
RATE_333KAsioio.lib.api.SpiMaster.Rate
RATE_35KAsioio.lib.api.SpiMaster.Rate
RATE_41KAsioio.lib.api.SpiMaster.Rate
RATE_4MAsioio.lib.api.SpiMaster.Rate
RATE_5_3MAsioio.lib.api.SpiMaster.Rate
RATE_500KAsioio.lib.api.SpiMaster.Rate
RATE_50KAsioio.lib.api.SpiMaster.Rate
RATE_571KAsioio.lib.api.SpiMaster.Rate
RATE_62KAsioio.lib.api.SpiMaster.Rate
RATE_666KAsioio.lib.api.SpiMaster.Rate
RATE_800KAsioio.lib.api.SpiMaster.Rate
RATE_83KAsioio.lib.api.SpiMaster.Rate
RATE_8MAsioio.lib.api.SpiMaster.Rate
StatusAsBoolean [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.
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
Close the pins and make them available for further use.
IsInitializedAsBoolean
RATE_100KHZAsioio.lib.api.TwiMaster.Rate
RATE_1MHzAsioio.lib.api.TwiMaster.Rate
RATE_400KHZAsioio.lib.api.TwiMaster.Rate
Status() AsBoolean [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.
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
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