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

kolbe

Active Member
Licensed User
Longtime User
Workbench 2.3 with library ioio2.02 and dialogs2.92. I am trying to start my first ioio-program with all this problems. Where from should I know which versions of different parts of the system belong together or are even compatible? In the tutorial I read I have to use API 8. Is this also wrong? The actual version is I think 16.
Error:
Parsing code. 0.02
Compiling code. 0.04
Compiling layouts code. 0.01
Generating R file. 0.03
Compiling debugger engine code. Error
java.lang.NoClassDefFoundError: com/sun/tools/javac/Main
Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.Main
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Exception in thread "main" Could not find the main class: com.sun.tools.javac.Main. Program will exit.

I am repeating myself but if you use the workbench app as is it will compile fine against the latest library regardless of API version. Other problems may occur later but it will at the very least compile.

Can you compile any applications at all? It's a wild guess but is the error above because you don't have the right version of Java installed?

Sorry but I'm going to have to give up on trying to help you. I don't know enough about what you are actually doing. Each error you have posted is different and seemingly unrelated. I have little idea of what you are doing or what you have changed and I get the feeling you are changing many things. I fear this is going nowhere. The language barrier doesn't help either... I saw you posting in the German forum as well.

My advice at this point is for you to start very simple and familiarize yourself with B4A first (use the examples in the tutorial) only after that start with other libraries. When you feel comfortable with the way libraries work ask again here if you are still having IOIO problems. If B4A is correctly setup and working it really isn't that difficult to get the IOIO library to work.
 

luigi.crocella

Member
Licensed User
Longtime User
Are you able to compile non IOIO applications??
Do you see the IOIO library in the library tab? What version is being reported?

Thanks Kolbe,
1) Yes, Other applications I can compile normally
2) Yes, I can see in the tab: ioio library 2.02

What happens? I hope you can help me.
 

kolbe

Active Member
Licensed User
Longtime User
@Fossil
@luigi.crocella

Try compiling this app. It simply connects when the application is created and then with a button you can turn on the onboard led. You need to choose the correct connection type.

Edit: Fossil see Erel's post below.
 

Attachments

  • simple ioio.zip
    16.8 KB · Views: 328
Last edited:

luigi.crocella

Member
Licensed User
Longtime User
Thanks Kolbe.
I tried the simple ioio. When I compile I get the error:
----------------------------------------------------------
Parsing code. 0.05
Compiling code. Error
Generata eccezione di tipo 'System.OutOfMemoryException'.
-----------------------------------------------------------

I had a doubt: I have not updated my B4A later versions and I'm working with the B4A 3.00.
Could this be causing my problem?
 

kolbe

Active Member
Licensed User
Longtime User
Thanks Kolbe.
I tried the simple ioio. When I compile I get the error:
----------------------------------------------------------
Parsing code. 0.05
Compiling code. Error
Generata eccezione di tipo 'System.OutOfMemoryException'.
-----------------------------------------------------------

I had a doubt: I have not updated my B4A later versions and I'm working with the B4A 3.00.
Could this be causing my problem?

Perhaps try to copy just the code text into a project you create. Maybe as you said a B4A v3.5 project is not compatible with a 3.0

Other than that I'm at a loss for ideas. The error doesn't give you much to go on, no line number, etc. Perhaps ask Erel for some help. What is parsing code 0.05?
 

Kevin L. Johnson

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

Apparently Samsung Galaxy S2's and S3's (others?) have some sort of issue with communicating properly with the IOIO via the usb port ... my Samsung Galaxy S3 is doing the same thing, while my older Android phone has no problem communicating with the same board via usb.
 

Kevin L. Johnson

Member
Licensed User
Longtime User
I've just recently purchased an IOIO inventors kit from Sparkfun, but am not able to access it via my Samsung Galaxy S3 running Android 4.3. I can however, access it via an older android phone.

My questions are ... Since the IOIO Lib now includes Open Accesorry ...
1.) Does this mean that we can now access the IOIO via open accessory (even for Android 4.1 and above)?
2.) If so, what are the requirements, (currently am using two IOIO lib files "IOIO" (version 1.40) and "IOIOLib" (version 3.20)
3.) What firmware might I need on my IOIO board?

My apologies for an earlier incorrect posting in the "Libraries" thread ... Thanks for the heads-up NJDude!

Thanks again, this product, community and dedicated individuals are all fantastic!
 

kolbe

Active Member
Licensed User
Longtime User
I've just recently purchased an IOIO inventors kit from Sparkfun, but am not able to access it via my Samsung Galaxy S3 running Android 4.3. I can however, access it via an older android phone.

My questions are ... Since the IOIO Lib now includes Open Accesorry ...
1.) Does this mean that we can now access the IOIO via open accessory (even for Android 4.1 and above)?
2.) If so, what are the requirements, (currently am using two IOIO lib files "IOIO" (version 1.40) and "IOIOLib" (version 3.20)
3.) What firmware might I need on my IOIO board?

My apologies for an earlier incorrect posting in the "Libraries" thread ... Thanks for the heads-up NJDude!

Thanks again, this product, community and dedicated individuals are all fantastic!

Sorry I've been away for a few weeks.

Yes open accessory works with the latest ioiolib as does device mode. Open Accessory started with sdk 10 or android 2.3.3 or GINGERBREAD_MR1.

You will need the IOIO application firmware v5.xx to use the latest ioiolib v2.02

I have a samsung s3 mini. I'll give the library a try on that and see if there are any issues.

I hope to post ioiolib 2.04 with all the latest fixes from Ytai soon.
 
Last edited:

Kevin L. Johnson

Member
Licensed User
Longtime User
Sorry I've been away for a few weeks.

Yes open accessory works with the latest ioiolib as does device mode. Open Accessory started with sdk 10 or android 2.3.3 or GINGERBREAD_MR1.

You will need the IOIO application firmware v5.xx to use the latest ioiolib v2.02

I have a samsung s3 mini. I'll give the library a try on that and see if there are any issues.

I hope to post ioiolib 2.04 with all the latest fixes from Ytai soon.


Glad to have you back! Thanks for all your efforts ...

Q1: Do you have a rough order of magnitude (days, weeks, months) on when you're hoping to post ioiolib v2.04? If not, I can certainly understand.
Q2: After I update the firmware of my ioio board. Do I need to do anything special to use Open Accessory or do I just disable "USB debugging" in my Androids Developer options?

Thanks again!
 

kolbe

Active Member
Licensed User
Longtime User
Glad to have you back! Thanks for all your efforts ...

Q1: Do you have a rough order of magnitude (days, weeks, months) on when you're hoping to post ioiolib v2.04? If not, I can certainly understand.
Q2: After I update the firmware of my ioio board. Do I need to do anything special to use Open Accessory or do I just disable "USB debugging" in my Androids Developer options?

Thanks again!

Next few days.
Download v2.02 of the library and use the workbench app as an example. On the device side disable debugging an you said.
 

Jiemde

Member
Licensed User
Longtime User
@Fossil
@luigi.crocella

Try compiling this app. It simply connects when the application is created and then with a button you can turn on the onboard led. You need to choose the correct connection type.

Edit: Fossil see Erel's post below.

Hi Kolbe,
I'm new in B4A, I try to work with the IOIO OTG board and see in this forum that you publish an "simple.ioio" zip file.
I've deszipped this file and open it in the B4A.
First I receive an error : library ioio 20 is missing.

IN the Sub Button1_Down and Button1_Up I have an error with the "WriteWait" who is not recognized ( I use the IOIO lib 2.02 and the IOIOBT lib 1.61 ) ?
Can you make an short overview of the last lib necessary for working well with the IOIO board ?
Have you an idea about this problem

Best regards
 

luc primeau

Member
Licensed User
Longtime User
FYI. Andrew will no longer be supporting this library.

http://www.b4x.com/forum/bugs-wishlist/8774-wish-ioio-support.html#post90055

I'll post the new libraries here. It seems like it is better this way than to have two threads on the forum for the same library.

Latest Version: v2.02 (use this one)

This version brings heaps of long awaited features. You can now finally connect the IOIO in four ways.​

USB ADB: Possible on SDK 16 and below. After this release Goggle secured ADB and no support for this connection exists.

BLUETOOTH: This works on almost all versions of Android that have Bluetooth.

USB OPEN ACCESSORY: This works on SDK 10 and above. Your Android device must however support Open Accessory. Most newer devices do have support. For this to work you need to add items to the manifest file of your app. It also requires a two extra commands in your app to register and unregister a broadcast receiver.

USB DEVICE: Connects the IOIO to your Andorid device as a device. This requires that your Android supports Open_Accessory and OTG. In this mode your Android device powers the IOIO. Make sure the IOIO-OTG is set to Auto and not HOST mode.

There is now a Motor Control Sequencer (aka waveform/pwm sequencer). This is a very cool addition made by Ytai. You need application firmware v5 for this functionality.

There is now a synch() command that allows managing the multi-threaded nature of the Android OS with the synchronous nature of the IOIO.

IOIO.Initialize is now required. It also returns a string indicating which connection types are supported by the Andorid device.

Add the changes to your manifest file with the changes in "add this with manifest editor.txt".

Works with both the original IOIO and the IOIO-OTG.

This version requires that your IOIO be running application firmware v5!

This version is built on Ytai's IOIOlib v5.02

Remaining Issues

The sequencer has trouble closing and reopening if done too rapidly. I don't think this is an b4a library issue but an IOIOlib issue. If you try to reopen and an exception is thrown you will need to unplug and plug back in the IOIO to reconnect unless you are using BT of course.

Finally

Enjoy. Since this takes a dedicated effort to maintain I wouldn't mind hearing about your projects. Also... please study the workbench 2.32 code before posting "how to" questions. I kept the code as simple as possible and you have basic examples on how to do use just about all the functionality of the IOIO.​

Version: v1.9 (for reference only)

Only two noteworthy changes in this version.

Capacitive sensing functionality. 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.

The PulseWidthSweep method. 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 greater than end to count backwards.
This method is usefull for better control of servos.

Note that this version is built on Ytai's IOIOlib v4.0. This means that the IOIO firmware app needs to be v4.0 too.

Finally, a GIT is in the works for this code so that all interested can have access and improve the code. Judging from the download there seems to be a least 50 or so of you using the library.​

Version: v1.8 (for reference only)

Many things have changed in this version so be sure to read everything to avoid questions on the forum that are answered in the documentation. Be sure to read the documentation that Ytai provides for the IOIO on github. The latest B4A library is based on the Ytai's 3.26 version.

https://github.com/ytai/ioio/wiki/IOIOLib-Basics

Changes/Improvements

The library now supports connections to multiple IOIOs simultaneously. See the IOIO Workbench app for an example.
Most of the methods are now threaded so it all works with SDK > 9, no more NetworkOnMainThread exceptions.
Documentation improved, examples for most methods.
An IOIO Workbench app to verify most IOIO functionality.
Uses latest code from Ytai, so other bug fixes.

Remaining Issues

Starting with Android 4.1 Google has added encryption to the ADB interface that IOIO uses to communicate when connected through USB. Ytai doesn't currently have any plans to support this change. Because the B4A library doesn't support OpenAcc yet, the only way to connect to Android devices 4.1 and higher is via Bluetooth. OpenAcc is the next thing to figure out.​

Note:
IOIO Test is for v1.7
IOIO Workbench 2.0 is for v1.8
IOIO Workbench 2.1 is for v1.9
IOIO Workbench 2.32 is for v2.02

For IOIO Workbench you will most likely need to adapt your screen layout for your device.
 

Kevin L. Johnson

Member
Licensed User
Longtime User
I am trying to get my IOIO to drive a servo motor.

I am running KitKat on my Samsung Galaxy S3
I have upgraded all my firmware and Libs to the latest etc. and disabled USB debugging in the Developer options
Therefore I am running an Open_Accessory connection ..

I can run the simple IOIO example that blinks the yellow status light from my Basic4Andriod IDE and phone.

Next I started with Kolbes PWM code snippet and rolled it into the simple IOIO as a template (removing the code to blink the Yellow status LED)
therefore this short bit of code only tries to drive a PWM Servo...

THE PROBLEM:
It doesn't yet drive the PWM Servo AND I am getting an illogical error of "Sub aPwmOut_open was not found" as if the IDE or Libs are struggling to resolve something.

B4X:
Sub Process_Globals
  'These global variables will be declared once when the application starts.
  'These variables can be accessed from all modules.
  Dim yoyo As IOIO
  Dim servo As PwmOutput
End Sub

Sub Globals
  'These global variables will be redeclared each time the activity is created.
  'These variables can only be accessed from this module.
  Dim SeekBar1 As SeekBar
  Dim Label1 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)

  Activity.LoadLayout("main1")

  yoyo.Initialize()
   yoyo.ReceiverRegister 'only for open accesory connection
   yoyo.Connect("yoyo",yoyo.CONN_OPEN_ACC,1,0) 'change connection type as desired

   yoyo.OpenPwmOutput("aPwmOut",5,servo.OP_NORMAL,50)

  SeekBar1.Max=2000 ' no more than 2 ms

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

'   yoyo.ReceiverUnregister 'only for open accesory connection
'   yoyo.Disconnect
'   ExitApplication

End Sub

Public Sub aPwmOut_open (noerror As Boolean, result As Object)

   If noerror Then
    'assign instance
    servo=result
     If servo.IsInitialized Then Log("Servo is Initialized")
   Else
    Dim trouble As Exception
    trouble=LastException
    Msgbox("trouble.message","Exception")
   End If

End Sub

Sub SeekBar1_ValueChanged (Value As Int, UserChanged As Boolean)

   Dim fltValue As Float

   If Value < 1000 Then Value=1000 'do not allow less than 1 ms

   Label1.Text=Value
   fltValue = Value /1000.0
   Log (fltValue)

   If servo.IsInitialized Then
    Log("Servo Initialized")
    servo.PulseWidth(fltValue,1) 'in microseconds, 1.0 to 2.0 ms for a servo
   Else
    Log("Servo is NOT Initialized")
   End If

End Sub

Sub yoyo_connected(noerror As Boolean)

   If noerror Then
     ToastMessageShow("ioio connected",True)
     Activity.Title="IOIO Connected"
     'yoyo.OpenDigitalOutput("pin0",0,pin0.OP_NORMAL,True) 'for led true is ON and false is OFF
   Else
       ToastMessageShow("ioio error",True)
   End If

End Sub

UPDATE: I've deleted the previously attached non-working example file because there is a working and improved V2 example found below
 
Last edited:

luc primeau

Member
Licensed User
Longtime User
You should wait for yoyo connected
and then openpwm

Sub yoyo_connected(noerror As Boolean)

If noerror Then
ToastMessageShow("ioio connected",True)
Activity.Title="IOIO Connected"
yoyo_OpenPwmOutput("aPwmOut",5,servo_OP_NORMAL,50)
Else
ToastMessageShow("ioio error",True)
End If

End Sub
 

Kevin L. Johnson

Member
Licensed User
Longtime User
Thanks luc primeau ... I could not see the forest for the trees but, thanks to your input, IT NOW WORKS FOR SINGLE SERVO .

OK, Now I am at a point where I need to trial and error / test a few things.
AND In order to save me a bit of time I have two more questions that I hope someone has the answers to or at least some insight into the issue...

1 - Does anyone have any best practices or architecture for robust connection, communication and operations using the IOIO (I am currently using it hardwired through my phones USB port, but could go to a mushroom like USB Bluetooth dongle if there were additional benefits like simplicity or robustness of communication or operation with the IOIO).

I am having to do a lot of disconnecting and reconnecting of the usb cables to get the ioio to connect etc.

AND Secondly,

2 - Now I need to mod the PWM Servo code for two servos ( one for Azimuth servo of Gimbal, and one for Elevation servo of Gimbal). My lesson learned above was to wait for completion events regarding connecting to the IOIO and opening the PWM Output etc. But I'm wondering how best to handle this overall and especially now that I'm coding and waiting for two servos (perhaps through boolean variables or ???) This is where I'm down to trial and error methods at the moment.

I need to clean up my single servo code and will post it after doing so.

Any ideas ... And Thanks in advance
Kevin
 

luc primeau

Member
Licensed User
Longtime User
http://www.robotshop.com/en/bluetooth-usb-adapter-mini.html
they sell the usb bluetooth that work well

First : how do you connect to your ioio
this is the way i connect and work fine but i'll explain later some issue

Try

YOYO.Initialize
YOYO.ReceiverRegister

If openacc then
' open accesory
YOYO.connect("yoyo",YOYO.CONN_OPEN_ACC,0,10 )

' dont forget to put in your activity_resume

if openacc then
YOYO.ReceiverUnregister

end if





Else
' open Bluetooth
YOYO.connect("yoyo",YOYO.CONN_BT ,1,10 )
End If

Catch
Msgbox("Error ioio","Error")

End Try


Note : When we open ioio in USB mode we have to be sure to close everything ( pvm,serial ,etc) and then close activity
Of course when the application stop for any reason the usb port is still block ( this is in accessory mode not in Bluetooth)


We been developing apps with ioio and b4a and this is a very good match :)

We just finish an beverage control system with RFID reader and 4 serial port , all with ioio included in our on pcb

Erel did the best programming language on the market
 

Kevin L. Johnson

Member
Licensed User
Longtime User
"luc primeau, post: 270486, member: 64247"]http://www.robotshop.com/en/bluetooth-usb-adapter-mini.html
they sell the usb bluetooth that work well
Thanks ...
I purchased two today!

First : how do you connect to your ioio
I have been using the Open Accessory connection

B4X:
' dont forget to put in your activity_resume
if openacc then
YOYO.ReceiverUnregister
end if
Did you mean 'don't forget to put in your activity_pause'?

Note : When we open ioio in USB mode we have to be sure to close everything ( pvm,serial ,etc) and then close activity
OK, close everything on startup (just in case?) or before shutting down. What does this look like and where does this code go

the only thing i'm doing in my Activity_Pause is ...
B4X:
  yoyo.Disconnect

  ExitApplication

I am not currently closing my PWM output which could be my biggest problem (the reason why I keep needing to unplug and then plug in my IOIO usb cable during each run.

Of course when the application stop for any reason the usb port is still block ( this is in accessory mode not in Bluetooth)
Is there any way to prevent this when using OPEN_ACC because this may be part of my issue as well.

Erel did the best programming language on the market
Yes, I agree wholeheartedly!

UPDATE: As promised ... here is my best practices attempt at an example of using an IOIO OTG via USB and Open Accessory to drive a single R/C Hobby Servo using PWM.


Thanks for all the help too!
Kevin
 

Attachments

  • Simple_IOIO_PWM_Servo V2.zip
    19.4 KB · Views: 243
Last edited:
Top