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

Cableguy

Expert
Licensed User
Longtime User
I'll have this a go later on after diner. Thanks for the time...

IYHO, if you were to controle up to 10 servos, would you go the I2C way using only 2 wires or connect the data in directly to the ioio board thus using 10 wires... I mean, what are the real advantages in using the complex i2c scheme to the simplicity of code using individual output pins.?
 

Cableguy

Expert
Licensed User
Longtime User
This is what I got... at least there is something being trown at b4a
B4X:
An error occurred:
(Line: 0) null
java.lang.Exception: Sub pulsewidth_done signature does not match expected signature.
public static anywheresoftware.b4a.pc.RemoteObject b4a.example.main_subs_0._pulsewidth_done() throws java.lang.Exception

all I have in the done event is a log statement

[EDIT] I didn't notice at first that the event declaration had changed. In the popup help, the declaraion tells that success is a String, when in fact it expects a Boolean.
The event fires as expected, but I have yet to grasp the mechanics of servo motion. If I close the pin inside the done event, then the rotation does not reach its end... So I added a timer, and set a flag inside the done event in order to not close the pin before the rotation had ended.
It all seems to work quite well now.

Thank you @kolbe, for all you effort in this thread... hopefully, I'll become a servo expert and will pick after you, LOL
 
Last edited:

kolbe

Active Member
Licensed User
Longtime User
I'll have this a go later on after diner. Thanks for the time...

IYHO, if you were to controle up to 10 servos, would you go the I2C way using only 2 wires or connect the data in directly to the ioio board thus using 10 wires... I mean, what are the real advantages in using the complex i2c scheme to the simplicity of code using individual output pins.?

I think the I2C way may give you better control and be more robust. One thing I always feared is what if the servo goes bad and somehow sends back 5v to the IOIO pin... this is why I always use the 5v tolerant pins. Should the servo short to ground that would probably kill the IOIO, a current limiting resistor here might be a good idea. Your I2C chip may be more robust in these respects and even protect the IOIO should disaster strike. You are also offloading some work off the IOIO pic by using another chip. The IOIO is actually generating in real time the 10 square waves. If you are planning to do analog sampling on the IOIO at the same time or using inputpwm this might make a difference. I also noticed that when connecting to the IOIO the servos go nuts as the IOIO initializes, by default the pins are floating. You probably don't have this problem with the I2C chip as long as it has power.
 

kolbe

Active Member
Licensed User
Longtime User
This is what I got... at least there is something being trown at b4a
B4X:
An error occurred:
(Line: 0) null
java.lang.Exception: Sub pulsewidth_done signature does not match expected signature.
public static anywheresoftware.b4a.pc.RemoteObject b4a.example.main_subs_0._pulsewidth_done() throws java.lang.Exception

all I have in the done event is a log statement

[EDIT] I didn't notice at first that the event declaration had changed. In the popup help, the declaraion tells that success is a String, when in fact it expects a Boolean.
The event fires as expected, but I have yet to grasp the mechanics of servo motion. If I close the pin inside the done event, then the rotation does not reach its end... So I added a timer, and set a flag inside the done event in order to not close the pin before the rotation had ended.
It all seems to work quite well now.

Thank you @kolbe, for all you effort in this thread... hopefully, I'll become a servo expert and will pick after you, LOL

Good to hear it's working. I'll correct the javadocs.
 

Cableguy

Expert
Licensed User
Longtime User
Thanks for your input about the I2C. I' ll start messing with that next weekend.
Thanks for the updated lib. Please update the event declaration (change string to boolean )
 
Last edited:

Cableguy

Expert
Licensed User
Longtime User
[Bluetooth ]

Só I got my BT dongle and rushed to get it connected to my ioio... no luck..
it pairs ok with my Asus tablet, though it takes a while to pair, but it pairs...
in the workbench I can even see it listed.. but connection fails over and over again.
the best I got was state init. I have already turned the voltage trim all the way in each direction.
Any suggestions?

( I already have a new bundle ioio+otg cable+BT dongle in the mail )
 

kolbe

Active Member
Licensed User
Longtime User
[Bluetooth ]

Só I got my BT dongle and rushed to get it connected to my ioio... no luck..
it pairs ok with my Asus tablet, though it takes a while to pair, but it pairs...
in the workbench I can even see it listed.. but connection fails over and over again.
the best I got was state init. I have already turned the voltage trim all the way in each direction.
Any suggestions?

( I already have a new bundle ioio+otg cable+BT dongle in the mail )

Did you see post #347? Is it a BT dongle that others have shown to work? Did you pair using code 4545? Are you using the latest firmware and application on the IOIO?

Also try the IOIO hello app you can download from Ytai's github downloads page.
 

Cableguy

Expert
Licensed User
Longtime User
Did you see post #347?
Yes I did.

Is it a BT dongle that others have shown to work?
I have no idea. My bt dongle is unbranded.

Did you pair using code 4545? Are you using the latest firmware and application on the IOIO?
Yes, it takes an eternity to pair but it does seem to pair. My firmware is on 5.03 I think.

Also try the IOIO hello app you can download from Ytai's github downloads page.
I didn't try that yet... will do over the weekend.

To be on the safe side, as I said, I have already ordered a second board bundling a bt dongle.
 

Cableguy

Expert
Licensed User
Longtime User
Hi guys...

I created a small tool for us IOIO enthusiasts to easily find the address of a dubious I2C chip/module

You can find it Here, I hope you find it useful.
 

JTKEK

Member
Licensed User
Longtime User
Kolbe i just change the default bluetooth name ioio to other name
can you update the library, which is can connect to custom name
 

kolbe

Active Member
Licensed User
Longtime User
Kolbe i just change the default bluetooth name ioio to other name
can you update the library, which is can connect to custom name

I don't understand the question. Maybe post an example.
 

JTKEK

Member
Licensed User
Longtime User
image.jpg
[/url][/IMG] The picture below show original IOIO default bluetooth name
image.png


image.jpg
[/url][/IMG] The picture below show modifed IOIO bluetooth name

image.png


i just modified, the name of IOIO bluetooth
the existing library is search for IOIO (original name)

can you make an update, so that the library can work with any IOIO bluetooth name
 

kolbe

Active Member
Licensed User
Longtime User
anyone has twi working example
can you share with me

Here is some working code. The hard part is figuring out how the chip you have works, the registers to use, order to access, what to send it and understanding the data you get back. You figure this out reading the spec sheets.

Below the chip address is 64. I first access register e3 and expect a 2 byte return. The done event returns the 2 bytes. I then do the same for register e5. I don't show the done event.

B4X:
Sub humid_temp

    Try
        'get inside temp from humid sensor
        Dim readbyte(2) As Byte
        Dim writebyte(1) As Byte
 
        writebyte(0)=0xe3 'read temp register

        'chip address,7bit,write,bytes,result,bytes,pause)
        Main.twi.WriteRead("htemp",64,False,writebyte,1,readbyte,3,0)

    Catch
        common.note_trouble("Sensors  humid_temp")
        get_temp
    End Try

    If Main.parms.logs Then Log("humid temp end")
End Sub

Sub htemp_done(noerror As Boolean, success As Boolean, writebyte() As Byte, readbyte() As Byte)

    If noerror Then
        If success Then
            Dim partial=(Bit.ShiftLeft(Bit.And(readbyte(0),0xff),8)+Bit.And(readbyte(1),0xfc)) As Int
            temp2=NumberFormat2(-46.85+(175.72*(partial/65536)),1,2,2,False)
     
            'get humidity from humid sensor
            Dim readbyte(2) As Byte
            Dim writebyte(1) As Byte
     
            writebyte(0)=0xe5 'read temp register
            Main.twi.WriteRead("hhumid",64,False,writebyte,1,readbyte,3,0)
        Else
            Log("htemp_done error "&noerror&" "&success)
            get_temp
        End If
    Else
        common.note_trouble("Sensors htemp_done ERROR ")
        get_temp
    End If

    If Main.parms.logs Then Log("htemp_done end")
End Sub
 
Last edited:

kolbe

Active Member
Licensed User
Longtime User
image.jpg
[/url][/IMG] The picture below show original IOIO default bluetooth name
image.png


image.jpg
[/url][/IMG] The picture below show modifed IOIO bluetooth name

image.png


i just modified, the name of IOIO bluetooth
the existing library is search for IOIO (original name)

can you make an update, so that the library can work with any IOIO bluetooth name

Sorry life has been keeping me busy with other things. What you ask is possible but it requires changing the library I get from Ytai. I don't really care to do that because of the extra maintenance then for each release.
 

JTKEK

Member
Licensed User
Longtime User
Here is some working code. The hard part is figuring out how the chip you have works, the registers to use, order to access, what to send it and understanding the data you get back. You figure this out reading the spec sheets.

Below the chip address is 64. I first access register e3 and expect a 2 byte return. The done event returns the 2 bytes. I then do the same for register e5. I don't show the done event.

B4X:
Sub humid_temp

    Try
        'get inside temp from humid sensor
        Dim readbyte(2) As Byte
        Dim writebyte(1) As Byte

        writebyte(0)=0xe3 'read temp register

        'chip address,7bit,write,bytes,result,bytes,pause)
        Main.twi.WriteRead("htemp",64,False,writebyte,1,readbyte,3,0)

    Catch
        common.note_trouble("Sensors  humid_temp")
        get_temp
    End Try

    If Main.parms.logs Then Log("humid temp end")
End Sub

Sub htemp_done(noerror As Boolean, success As Boolean, writebyte() As Byte, readbyte() As Byte)

    If noerror Then
        If success Then
            Dim partial=(Bit.ShiftLeft(Bit.And(readbyte(0),0xff),8)+Bit.And(readbyte(1),0xfc)) As Int
            temp2=NumberFormat2(-46.85+(175.72*(partial/65536)),1,2,2,False)
    
            'get humidity from humid sensor
            Dim readbyte(2) As Byte
            Dim writebyte(1) As Byte
    
            writebyte(0)=0xe5 'read temp register
            Main.twi.WriteRead("hhumid",64,False,writebyte,1,readbyte,3,0)
        Else
            Log("htemp_done error "&noerror&" "&success)
            get_temp
        End If
    Else
        common.note_trouble("Sensors htemp_done ERROR ")
        get_temp
    End If

    If Main.parms.logs Then Log("htemp_done end")
End Sub

sorry for my question
what is main variable? i means main.twi
 

Reyes5

Member
Licensed User
Longtime User
Hello all,

For a new project, I need 40 digital outputs and 80 digital inputs. My idea is to have 3 IOIO boards attached to a tablet. I could find somewhere on the net it should be possible to work with multiple IOIO boards together. Has anyone experience with multiple IOIO boards connected to 1 tablet? And if yes, do you think or know it is possible over USB, using a USB HUB ? My customer is afraid of connecting over BT and realy wants a wired connection, no radio.
Has anyone got experience to share about this ?
Thanks a lot for your kind reply !
 
Top