B4A Library IOIO board library

The request in this thread here introduced me to a product called IOIO that seems to have been designed by some Google engineers in the 20% of time that Google gives them to pursue their own interests,

The blog of the main mover of the project is at Microcontrollers, Electronics & Robotics: Meet IOIO - I/O for Android

The board will be available soon from here IOIO for Android - SparkFun Electronics

As the software has just been released I took a look at it and wrapped it in a couple of libraries for use with Basic4android. I obviously cannot test it as I have no board but the Basic4android library is a very thin veneer on top of the normal Android library so, typos and idiot errors aside, it should work with no problems and the software documentation should be pretty much applicable. I have copied a lot of the library help from the software documention so a B4A help viewer should give you a good grounding in how to use it.

I don't yet know if the board will be available this side of the pond - if anyone wants to ship me one for testing .... :)

EDIT :- Version 1.1 posted with INTERNET permission. See post #11 for details.

EDIT :- Version 1.2 posted with PulseInput. See post #37 for details.

EDIT :- Version 1.2 reposted with XML error fixed. See post #39 for details.

EDIT :- Version 1.3 posted with SPI and I2C support. See post #40 for details.

EDIT :- Version 1.3a posted with IOIOlib 3.2 included. See post #42 for details.

EDIT :- Version 1.4 posted. See post #47 for details.

EDIT :- IOIOlibBT 3.10 posted. See post#58 for details.

EDIT:- IOIOBT1.4 posted See post #63 for details

EDIT:- IOIOBT1.5 posted See post #77 for details.

THESE ATTACHMENTS ARE NOW OBSOLETE. SEE POST #105 FOR THE LATEST VERSIONS BY KOLBE: http://www.b4x.com/android/forum/threads/ioio-board-library.8942/page-6#post-90731
 

Attachments

  • IOIOBT1.5.zip
    102.3 KB · Views: 2,201
  • IOIO1.4.zip
    100.5 KB · Views: 1,663
Last edited by a moderator:

pinoy_ako

Member
Licensed User
Longtime User
Sir Agraham,
thanks for the continuous update on ioio. please continue doing so. once i get my diy ioio hardware working, i'll share it here. so others can enjoy your library with a cheaper hardware. :D


thank you sir Agraham! :sign0098:
 

agraham

Expert
Licensed User
Longtime User
Archive 1.3a now posted includes the unchanged Basic4android IOIO library version 1.3 together with the IOIOlib library version 3.2 which is the latest version on the Downloads page link here https://github.com/ytai/ioio/wiki

To use it you may have to upgrade your IOIO firmware to the App-IOIO0300.ioioapp Application Image Bundle found on the Downloads page by clicking the QR code image on the version 3.2 line and using the IOIO Manager Application available on the Market.
 

eric010101

Member
Licensed User
Longtime User
SPI Question

I tested the IOIO1.3, it worked fine with TwiMaster, but can't get through OpenSpiMaster, Here is my code:
Dim slaveselect(1) As DigitalOutput
Dim mosi As DigitalOutput
Dim miso As DigitalInput
Dim clk As DigitalOutput
mosi= YOYO.OpenDigitalOutput(3,mosi.OP_NORMAL ,True)
miso= YOYO.OpenDigitalInput(4,miso.IP_FLOATING)
clk=yoyo_OpenDigitalOutput(5,clk.OP_NORMAL,True)
slaveselect(0)=yoyo_OpenDigitalOutput(6,slaveselect(0).OP_NORMAL,True)
'OpenSpiMaster (miso As IOIO.lib.api.DigitalInput.Spec, mosi As IOIO.lib.api.DigitalOutput.Spec,
'clk As IOIO.lib.api.DigitalOutput.Spec, slaveSelect() As IOIO.lib.api.DigitalOutput.Spec[],
'rate As IOIO.lib.api.SpiMaster.Rate, invertClk As Boolean, sampleOnTrailing As Boolean) As IOIO.lib.api.SpiMaster

spi=yoyo_OpenSpiMaster(miso,mosi,clk,slaveselect,spi.RATE_125K,False,False)

and the error message,

Compiling code. 0.09
Generating R file. 0.00
Compiling generated Java code. Error
B4A line: 118
spi=yoyo_OpenSpiMaster(miso,mosi,clk,slaveselect,spi.RATE_125K,False,False)
javac 1.6.0_26
src\sweetek\ioio\experiment\main.java:344: inconvertible types
found : anywheresoftware.b4a.agraham.ioio.B4AIOIO.B4ADigitalOutputWrapper[]
required: ioio.lib.api.DigitalOutput.Spec[][]
mostCurrent._spi.setObject((ioio.lib.api.SpiMaster)(mostCurrent._yoyo_OpenSpiMaster((ioio.lib.api.DigitalInput.Spec)(_miso.getObject()),(ioio.lib.api.DigitalOutput.Spec)(_mosi.getObject()),(ioio.lib.api.DigitalOutput.Spec)(_clk.getObject()),(ioio.lib.api.DigitalOutput.Spec[][])(_slaveselect),mostCurrent._spi.RATE_125K,anywheresoftware.b4a.keywords.Common.False,anywheresoftware.b4a.keywords.Common.False)));
^
1 error

so, the question is: "how to define a valid digitaloutput array?
 

agraham

Expert
Licensed User
Longtime User
the question is: "how to define a valid digitaloutput array?
Indeed :( I overlooked the ramifications of it being an array of an IOIOlib type. I need to convert the Basic4android DigitalOutput wrapper types to unwrapped IOIO DigitalOutput types and copy them to an array of that type. I'll do it later today after I've done the weekly shopping! :(
 

eric010101

Member
Licensed User
Longtime User
thanks!

Indeed :( I overlooked the ramifications of it being an array of an IOIOlib type. I need to convert the Basic4android DigitalOutput wrapper types to unwrapped IOIO DigitalOutput types and copy them to an array of that type. I'll do it later today after I've done the weekly shopping! :(

after serveral hours searching and trying, I found the question is beyong my knoweledge.

let me know if I can help in anything.
 

agraham

Expert
Licensed User
Longtime User
Version 1.4 now posted corrects the method signature for OpenSpiMaster which I totally screwed up originally by being careless.

Dim spi As SpiMaster
Dim slavepins() As Int
slavepins = Array As Int(4, 5, 6)
Dim slavemodes() As Object
slavemodes = Array As Object( spi.OP_NORMAL, spi.OP_NORMAL, spi.OP_NORMAL)
spi=YOYO.OpenSpiMaster(1, spi.IP_PULL_UP, 2, spi.OP_NORMAL, 3, spi.OP_NORMAL, slavepins, slavemodes, spi.RATE_125K, False, False)
 

eric010101

Member
Licensed User
Longtime User
SPI Tested and is good but not perfect

Version 1.4 now posted corrects the method signature for OpenSpiMaster which I totally screwed up originally by being careless.
hello agraham,
I tested the SPI with an EEPROM - AT25AA320. and the code:

If FirstTime=True Then
activity.AddMenuItem("UART","aUART")
activity.AddMenuItem("I2C","aI2C")
activity.AddMenuItem("SPI","aSPI")
activity.AddMenuItem("IO","aIO")
activity.AddMenuItem("ADC","aADC")
activity.AddMenuItem("WiFi","aWiFi")


SetSpinner
'default mode0,DA=4, CL=5, rate=100KH)
spn_Twimode.SelectedIndex=2
spn_TWIRate.SelectedIndex=0
spn_Period.SelectedIndex=4
spn_Addbit.SelectedIndex=0
txt_WriteByteLength.text=1
txt_ReadByteLength.text=7
txtAddress.Text="104"
TimerLoop.Initialize("TimerLoop",1000)

go=False
looped=False
rbtn_Single.Checked=True

YOYO.Initialize
YOYO.WaitForConnect()



led = YOYO.OpenDigitalOutput(0,led.OP_NORMAL ,True) ' Enable LED_PIN for output
getSetUPValue
Dim spi As SpiMaster
Dim slavepins() As Int
slavepins = Array As Int(6, 7, 10)
Dim slavemodes() As Object
slavemodes = Array As Object( spi.OP_NORMAL, spi.OP_NORMAL, spi.OP_NORMAL)
spi=YOYO.OpenSpiMaster(3, spi.IP_PULL_UP, 4, spi.OP_NORMAL, 5, spi.OP_NORMAL, slavepins, slavemodes, spi.RATE_125K, False, False)
Dim i As Int
Dim wBuffer(2) As Byte
Dim rBuffer(7) As Byte
Dim Rs() As Boolean
Dim suc As Boolean
Dim tmp As String
suc=True
Do While (suc=True)
wBuffer(0)=0x05
If Spi.IsInitialized=True Then

spi.WriteRead(0,wBuffer,1,2,rBuffer,1)
lbStatus.Text="Read " & 1 & " bytes. @ " & DateTime.Time(DateTime.Now)
txtRX.Text=rbuffer(0)' Bit.ToHexString(rbuffer(0))
Else
Msgbox("NOT ready","")
End If
waitms(1000)
Loop

End If

*****************
the results were:
1. compilier was good with no error.
2. connected to IOIO with pins: 3,4,5,6, MISO,MOSI,CLK,CS. and data read.
3. send 0x05 to read eeprom's register byte and return should be 0x8C, but it showed "-116", negative? so strange.
4. confirmed the signal with LogicPort and is OK.see attached file
5. need to know how to convert -116 to 0x8C = 140 (256+(-116))=140, but how does it happen with a byte array?

thank you for your quick fix on lib. did you buy apple?
 

Attachments

  • SPI_IOIO_B4A.JPG
    SPI_IOIO_B4A.JPG
    15.8 KB · Views: 249
Last edited:

agraham

Expert
Licensed User
Longtime User
return should be 0x8C, but it showed "-116", negative? so strange
In Java bytes are treated as signed numbers -128 to 127. You can convert using an Int to get the unsigned value.
B4X:
   Dim unsignedi As Int
   Dim signedb As Byte
   signedb = 0x8c
   unsignedi = Bit.And(0xff, signedb)
   Msgbox(unsignedi, signedb)
did you buy apple?
Sorry! :confused:
 

eric010101

Member
Licensed User
Longtime User
know no java but basic

I started Anroid programming with Java, but after 2 weeks reading sample project, and eclipse, my face turned grey.
until I found B4A, my life turn color again. Thanks for your answer.

now I am ready to test different sensors.

I need to get some sleep now, I'll let you know if SPI works all night.

BTW, I don't do shopping, I eat only Apple.
 

bluedude

Well-Known Member
Licensed User
Longtime User
ADK Tinkerkit

Hi,

I know you have created the IOIO stuff but have you ever taken a look at the ADK stuff?

More and more hardware suppliers release an ADK en for example the ADK Tinkerkit is pretty amazing: Arduino ADK TinkerKit

Any plans to do something for the ADK stuff? I think it is broader supported compared to IOIO.

Cheers,
 

jboavida

Member
Licensed User
Longtime User
Sorry for the begginners question, but this library works on a tablet with Android 2.2 or needs 3.x?

I read somewhere that only honeycomb as hardware access...

Thanks
 

Nizze

Active Member
Licensed User
Longtime User
Dont work ??

Hi
Today i recived my IOIO module.
I hav edownloade the example and libs.
But nothing happands .
The red Led lights up but nothing more.

Have i forgotten something ??

Tested on Samsung S2 and Motorola XOOM

// Nizze
 

agraham

Expert
Licensed User
Longtime User
IOIOlibBT version 3.10 now posted. I have no idea if it will work but it compiles OK in Basic4android against IOIO.jar version 1.4.

This version of the IOIOlib is supposed to be able to connect with a IOIO board across a Bluetooth connection. It should be completely interchangeable with the original IOIOlib as far as IOIO.jar is concerned. Reference either IOIOlib or IOIOlibBT in your project but not both. It may not work on all versions of Android before API 10 - you can but try!

IOIOlibBT requires the the IOIO board be loaded with updated firmware that can recognise both an Android phone and a Bluetooth dongle and communicate appropriately.
 

pinoy_ako

Member
Licensed User
Longtime User
IOIOlibBT version 3.10 now posted. I have no idea if it will work but it compiles OK in Basic4android against IOIO.jar version 1.4.
hi sir agraham. i tried compiling a working ioio b4a sample with IOIOlibBT. it compiled ok. but when i tried to connect the app to a bt ioio board, the app hunged up. it seems it can't detect the bt ioio board.

is there something we can do with it? thanks
 
Top