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,197
  • IOIO1.4.zip
    100.5 KB · Views: 1,659
Last edited by a moderator:

microbox

Active Member
Licensed User
Longtime User
I'm afraid somethings wrong with the ioio, I never got a steady connection state at all :(. I'm using the ioiotest.APK file...install it right away on to the device, please see the attach file...I hope I am wrong...at the bottom of the search log I see 230 930...ioio library version should display when connected.. am I right?
 

Attachments

  • ioioerror.jpg
    ioioerror.jpg
    87.7 KB · Views: 253
Last edited:

jransom2

Member
Licensed User
Longtime User
Wt files do I need?

Agraham-

What file names do I need from the ioio library to place in the basic4ppc library folder to be up to date?

I have tested the ioio board with your app, but when I try to compile I don't have all of the libraries installed.

Thanks
 

kolbe

Active Member
Licensed User
Longtime User
Microbox,

I can't make out the log from the picture. You can see the same log from the log tab in the B4A IDE. After it app runs connect to the PC and see if you can capture the log. I'll add a save button to the app too. You can also use an app like Elixir2 to capture filter and save logs on the device.
 

kolbe

Active Member
Licensed User
Longtime User
Agraham-

What file names do I need from the ioio library to place in the basic4ppc library folder to be up to date?

I have tested the ioio board with your app, but when I try to compile I don't have all of the libraries installed.

Thanks

Use 1.61 for now, follow Agraham link. Copy all four files (ioiolibbt and ioiobt, jar and xml) to your additional libraries folder. If the IDE is already open be sure to refresh and reload the library.

I have a new version just about ready but I need to document it. I'm also stalling a bit because Ytai is about to release a new version... next week maybe?
 

Tom Christman

Active Member
Licensed User
Longtime User
According to Engadget, the new IOIO board is about to be released featuring a lower price and Bluetooth.
 

kolbe

Active Member
Licensed User
Longtime User
According to Engadget, the new IOIO board is about to be released featuring a lower price and Bluetooth.

He doesn't mention built in Bluetooth here. I don't find the Engadget article particularly clear on that point either. The basic functionality is the same with board improvements... bigger power supply, ability to host and connect to a PC.

This would allow for a library for B4PPC so that you can use the IOIO with exes for the PC!

https://groups.google.com/forum/?pli=1#!topic/ioio-users/1Md8b_PbT0I
 

brookers

New Member
Licensed User
Longtime User
Hi peeps, new to the IOIO and basic4android..

Am just trying to get the IOIO test app with the latest (1.6) library installed..

I have commented out the 'connect' line as stated earlier in the forum, however am getting this..

Compiling code. Error
Error compiling program.
Error description: Unknown member: isinitialized
Occurred on line: 165
If yoyo.IsInitialized Then
Word: isinitialized

....

I read somewhere (I would imaging where I commented out the 'connect' line) there needs to be an alternative line to init the board.

It's probably an obvious one, but thanks for your help and patience with a newbie!

Jay
 

kolbe

Active Member
Licensed User
Longtime User
I'd originally said that I'd wait for Ytai to release a new version of his library before I'd release another one for B4A. However it seems that he is busy with v2 of the IOIO and that won't happen any time soon. I'll see what I can do before the end of the week. This way the test app and library will be in synch.
 

brookers

New Member
Licensed User
Longtime User
.. guys have managed to sort it, I had not initialized the ioio correctly...

Thanks for the reply though!
 

kolbe

Active Member
Licensed User
Longtime User
some IOIO code examples

I've posted the latest IOIO library here.

I'm curious to how many IOIO users we have? 5?? 10??

To help out here are some code examples. The code isn't complete, declarations missing, etc. It's just to give an idea.


To connect using Bluetooth
B4X:
Dim btadmin As BluetoothAdmin

btadmin.Initialize("btadmin")
If btadmin.IsEnabled Then yoyo.connect("ioio",True,0)

'event raised when connected
Sub ioio_connected (noexception As Boolean)
   If noexception Then
      'IOIO is connected
   Else
      'some error happened
      Dim trouble As Exception
      trouble=LastException
      Msgbox(trouble.Message,"Connection to IOIO failed")
   End If
End Sub

'connection timeout timer
Sub timer1_tick
   'timer over and still no connection
   timer1.Enabled=False
   
   'cancel attempt to connect
   If yoyo.IsInitialized Then yoyo.Disconnect
   
   If conn_attemps > 5 Then 
      edittext1.Text="Connection Failed"
      Return
   Else
      conn_attemps=conn_attemps+1
      edittext1.Text="Connection attempt: "&conn_attemps
   End If
   
   'try new connection
   yoyo.connect("yoyo",BtnBT.Checked,1)
   timer1.Enabled=True
End Sub

'periodically check if IOIO connection is valid
Sub timer2_tick
   If yoyo.IsInitialized Then
      If yoyo.State = "DEAD" Then
         timer2.Enabled=False
         'first disconnect old connections
         yoyo.Disconnect
         'try new connection
         yoyo.connect("yoyo",BtnBT.Checked,1)
         timer1.Enabled=True
      End If
   End If
End Sub


An example of I2C
B4X:
dim twi as TwiMaster
twi= yoyo.OpenTwiMaster(0, twi.RATE_1MHz, False) 'pins 4,5

Dim readbyte() As Byte
Dim writebyte() As Byte
readbyte = Array As Byte (0,0)
writebyte = Array As Byte (0)
   
Dim result As Boolean

'this is the register we want to read 
writebyte(0)=170

'119 is the chip address

'write 1 byte register address
'read 2 byte output from register
result=twi.WriteRead("119",False,writebyte,1,readbyte,2) 'eprom address,7bit,register,result bytes)

'write 2 bytes, read 2 bytes
writebyte(0)=244 'register address 0xf4
writebyte(1)=46 'request type 0x2e
   
result=Main.twi.WriteRead("119",False,writebyte,2,readbyte,2)


An example of serial comm
B4X:
dim mtserial as Uart

'uart order is is rx,spec,tx,spec,baud,pariy,stop
mtserial=yoyo.OpenUart(28,mtserial.IP_FLOATING,27,mtserial.OP_NORMAL,9600,mtserial.PARITY_NONE,mtserial.STOPBIT_ONE)

Dim out As OutputStream
Dim in As InputStream

Dim bufferin(8), bufferout(8) As Byte
Dim temp As String
   
out=mtserial.OutputStream
in=mtserial.InputStream
   
'send 83 and read result
bufferin(0)=83 'S
out.WriteBytes(bufferin,0,1)
in.ReadBytes(bufferout,0,1)

temp="result="&Bit.And(bufferout(0),0xFF)


Example of AnalogInput.VoltageSample
B4X:
Dim ain as AnalogInput

samples=10 'should be even
mid=Round(samples/2)
      
'collect voltage readings
ain1.VoltageSample("ain1",samples*2,samples)

'event raised when samples are ready
Sub ain1_done (noexception As Boolean, list1 As List, Available As Int, Overflow As Int)
   If noexception Then
      Dim average

      'sort result to filter and just use middle values
      list1.Sort(True)

      'average the three middle values
      average=(list1.Get(mid+1) + list1.Get(mid) + list1.Get(mid-1))/3
      motortemp = NumberFormat2(Round2(average,1),1,1,1,False)
   Else
      Dim trouble As Exception
      trouble=LastException
      If trouble.IsInitialized Then
         Log("ain1 done "&trouble.Message)
      End If
      
      If trouble.Message.Contains("ConnectionLost") Then
         'reconnect to IOIO
      Else
         'different error
      End If
   End If
End Sub


Pulse example
B4X:
Dim stp, mtrled as DigitalOutput

'stepper motor advance 10 steps
stp.pulse("step",25,25,10)

Sub step_done (noerror As Boolean)
   If noerror Then
      'now blink motor leds 3 times
      mtrled.pulse("led",500,10,3)
   Else
      Dim trouble As Exception
      trouble=LastException
      If trouble.IsInitialized Then
         Log(trouble.Message)
      End If
   End If
End Sub

Sub led_done (noerror As Boolean)
   If noerror Then
      'done with blink
   Else
      Dim trouble As Exception
      trouble=LastException
      If trouble.IsInitialized Then
         Log(trouble.Message)
      End If
   End If
End Sub
 

schuerstedt

Member
Licensed User
Longtime User
I have the board, but never had time to test it out. But should do know :). Thx for the library. Will save me a lot of time.

:sign0098::sign0098::sign0098:
 

gbdroid

Member
Licensed User
Longtime User
Thank you Kolbe!
IOIO is a very interesting peace of hardware.
I am struggling around to use it as intruder alarm system (send sms alarm depending on state of IOIO-pin(s).
It is already working with IOIO lib 1.4 via USB (which is the better connection for a safety system) and try now to have it running with the new 1.7, but get stuck at the command: "pin20.Write (False)" which was working with lib 1.4 but now the compiler is saying:
Compiling code. Error
Error compiling program.
Error description: Property: Write is writeonly.
Occurred on line: 57
pin20.Write (False)
Word: write
 

kolbe

Active Member
Licensed User
Longtime User
Yes this I forgot to mention. I made the digitaloutput.write write only.

Try pin20.write=false not pin20(false).


Thank you Kolbe!
IOIO is a very interesting peace of hardware.
I am struggling around to use it as intruder alarm system (send sms alarm depending on state of IOIO-pin(s).
It is already working with IOIO lib 1.4 via USB (which is the better connection for a safety system) and try now to have it running with the new 1.7, but get stuck at the command: "pin20.Write (False)" which was working with lib 1.4 but now the compiler is saying:
Compiling code. Error
Error compiling program.
Error description: Property: Write is writeonly.
Occurred on line: 57
pin20.Write (False)
Word: write
 

gbdroid

Member
Licensed User
Longtime User
Thanks Kolbe,
at least it compiles now without errors.
Obviously there has also changed also something with connecting via USB, because my application not gets stuck at "YOY.WaitForConnect()"
If you are interested in how others are using IOIO, have a look at my application attached (I altered only the mobile number), and perhaps have a easy explanation was has changed. But, as already mentioned it is working with lib 1.40 - so I am happy with the actual result.
I had been struggling a lot of time to have the app reacting also when the screen is turned off - my (surely not perfect) solution with a service perhaps of interest for some of you (as to past posts).
By the way: I find it very difficult to sort out the correct syntax from the library documentations (where are the good old times of Commodore PET2001 basic? ;-).
Only making the output "write only" caused this change in syntax?
Why did you make it write only? In a lot of cases it might be usefull to read the output instead of the necessity to use an additional variable.

Edit 14.07.2012:
found the reason for not connecting, correct syntax: YOYO.Initialize (False) 'False is needed for USB connection, True is for BT!
 

Attachments

  • IOIO-Alarm106.zip
    5.6 KB · Views: 236
Last edited:

kolbe

Active Member
Licensed User
Longtime User
I'll take a look at your code. I don't see why it shouldn't work w/ USB from the B4A library standpoint. Do you have the latest IOIO firmware and application loaded, v3.23?

The change to write only clarifies its use and better catches usage errors. To read the value from the same pin you would have to close the pin and reopen as a digitalinput, then use value=pin40.read.

To have you're app work when the screen is off you need to run your code as a service (as you mention) and also bring your process to the foreground to make sure Android never kills your process. You can also wakeup the device when needed. There are a few discussions about these things and specifics on the forum already. I've done similar things with a motion detector and the camera on the device. When the device is off, if motion is detected it wakes up, turns on the lights and then takes a picture. Works well except the camera fails to initialize from time to time.

Thanks Kolbe,
at least it compiles now without errors.
Obviously there has also changed also something with connecting via USB, because my application not gets stuck at "YOY.WaitForConnect()"
If you are interested in how others are using IOIO, have a look at my application attached (I altered only the mobile number), and perhaps have a easy explanation was has changed. But, as already mentioned it is working with lib 1.40 - so I am happy with the actual result.
I had been struggling a lot of time to have the app reacting also when the screen is turned off - my (surely not perfect) solution with a service perhaps of interest for some of you (as to past posts).
By the way: I find it very difficult to sort out the correct syntax from the library documentations (where are the good old times of Commodore PET2001 basic? ;-).
Only making the output "write only" caused this change in syntax?
Why did you make it write only? In a lot of cases it might be usefull to read the output instead of the necessity to use an additional variable.
 
Top