B4A Library IOIO board library

Jiemde

Member
Licensed User
Hi All, in 1 month I've do more with B4A than with Java/androîd in 6 month! that's fantastic!
But sometimes I don't know how to do something, example:
I try to use the BMP180 from Bosch, I can open the I2C connection, read the E²Prom registers like 0xAA and OxAB but in the documentation it's necessary to "group" these 2 octets, but I do not find how ?
Is someone can help me ?

Best regards

Jiemde
 

Kevin L. Johnson

Member
Licensed User
In preparation for Dual Servos (Az & El) ...

I thought that I'd simply take my single servo example app from ...

http://www.basic4ppc.com/android/forum/threads/ioio-board-library.8942/page-16#post-270678

and renamed the servo variable to first 'servoAz' and then tried 'Azservo'.

It seems that when preparing the code (carefully renaming variables and events) for dual servos some of the fired event names are particular (almost as if they are hardcoded) and don't like to be changed to differentiate which servo (like 'pwmoutput_open' to 'Azpwmoutput_open' because the minute I change variable names to reflect not just a servo but the Azimuth (Panning) Servo it will not fire the renamed events and therefore objects don't get initialized and therefore the code will not work properly.

UPDATE:

It appears that the following line of code ...
B4X:
yoyo.OpenPwmOutput("pwmoutaz",5,Azservo.OP_NORMAL,50)
can NOT handle uppercase letters in the event name therefore ...

pwmout is OK
pwmoutaz is OK
but
pwmoutAz or Azpwmout is NOT OK

Kolbe is this behavior by design or is it a bug?
AND before you answer that ... THANK YOU and Agraham both for all your previous hard work and current dedication to this library.
 
Last edited:

Jiemde

Member
Licensed User
Hi All, in 1 month I've do more with B4A than with Java/androîd in 6 month! that's fantastic!
But sometimes I don't know how to do something, example:
I try to use the BMP180 from Bosch, I can open the I2C connection, read the E²Prom registers like 0xAA and OxAB but in the documentation it's necessary to "group" these 2 octets, but I do not find how ?
Is someone can help me ?

Best regards

Jiemde
Hi,

Is somebody can help me about the BMP180 sensor ?

Best regards
Jiemde
 

kolbe

Active Member
Licensed User
Hello all, good to see the activity while I was gone. To answer the question below, because you are creating an event you can only use lower case. This is a b4a thing. I hope to answer some of the other questions today.


In preparation for Dual Servos (Az & El) ...

I thought that I'd simply take my single servo example app from ...

http://www.basic4ppc.com/android/forum/threads/ioio-board-library.8942/page-16#post-270678

and renamed the servo variable to first 'servoAz' and then tried 'Azservo'.

It seems that when preparing the code (carefully renaming variables and events) for dual servos some of the fired event names are particular (almost as if they are hardcoded) and don't like to be changed to differentiate which servo (like 'pwmoutput_open' to 'Azpwmoutput_open' because the minute I change variable names to reflect not just a servo but the Azimuth (Panning) Servo it will not fire the renamed events and therefore objects don't get initialized and therefore the code will not work properly.

UPDATE:

It appears that the following line of code ...
B4X:
yoyo.OpenPwmOutput("pwmoutaz",5,Azservo.OP_NORMAL,50)
can NOT handle uppercase letters in the event name therefore ...

pwmout is OK
pwmoutaz is OK
but
pwmoutAz or Azpwmout is NOT OK

Kolbe is this behavior by design or is it a bug?
AND before you answer that ... THANK YOU and Agraham both for all your previous hard work and current dedication to this library.
 
Last edited:

kolbe

Active Member
Licensed User
Spend some time reading this thread and you will figure it out. You are getting the error because you are missing the IOIO library. Good luck.

P.S. Reading your other posts, it looks like you figured it out.

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
 
Last edited:

kolbe

Active Member
Licensed User
About connections. I generally use Bluetooth because I find it the most flexible. Connecting and reconnecting is the simplest out of all the options, just don't forget to init btadmin or it won't work. I use the TrendNet TBW 106UB. I like this one because it is Class 1.

The only reason I find to use OpenAccessory is if you want the fastest transfer and lowest jitter possible. If you have a project that requires this, like a balancing robot, then this is essential.

The Device option is cool because you can power the IOIO from the Android device.

The ioio.ReceiverRegister should only be called once when the app process in created and then ioio.ReceiverUnregister when the app is closing, the process killed (activity_pause userclosed=true, or exitapplication). I don't think any harm is done when the app pauses to leave it registered and you might even lose functionality if you do. I'll explain, when an OpenAccessory device is plugged in the Android OS sends out a message to all the apps. Your app must register a receiver to be able to detect this message and be aware that the IOIO has been plugged in and consequently establish a data connection to it. If for example you have a service running in the background to reconnect if necessary, then unregistering while the app is in the background will not allow the IOIO to reconnect.

As for app program architecture to deal with IOIO connections, I generally use a service that monitors the connections. Every five seconds a timer checks the state of the IOIO. Based on the state it will take appropriate actions. A global variable allows other parts of the program to know if the IOIO connection is valid. I surround all my IOIO calls with TRY / CATCH in order to catch any connections errors.

Hope this helps
 

kolbe

Active Member
Licensed User
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.
I just tried both IOIO v1 and v2 with a S4 mini. BT and OpenAccessory worked just fine but ADB and Device did not. So if by usb you mean ADB usb that is correct if you mean OpenAccessory by usb in my case it works. I also noticed that when I connected the S3 to the IOIO with usb the IOIO started humming a tiny bit. I've haven't seen this with another device.
 

kolbe

Active Member
Licensed User
Just released v2.04 of the IOIO library. This is just a maintenance release. No real changes other than the bug fixes from Ytai's library. Look here to see the changes.
 

Jiemde

Member
Licensed User
Just released v2.04 of the IOIO library. This is just a maintenance release. No real changes other than the bug fixes from Ytai's library. Look here to see the changes.

Hi Kolbe,
I'm already stopped by ( I think! ) a basic thing, I can read the 2 bytes from the calibrations registrys of an BMP180 sensor, but don't know how to concat these 2 bytes into a single one of 16 bits?
I've try the ByteConverter library without succes!
Can you help me?

Thanks in advance for your help
Jiemde
 

kolbe

Active Member
Licensed User
Hi Kolbe,
I'm already stopped by ( I think! ) a basic thing, I can read the 2 bytes from the calibrations registrys of an BMP180 sensor, but don't know how to concat these 2 bytes into a single one of 16 bits?
I've try the ByteConverter library without succes!
Can you help me?

Thanks in advance for your help
Jiemde
Try this
B4X:
Dim ut  As Long
msb=readbyte(0)
lsb=readbyte(1)
       
ut=Bit.ShiftLeft(Bit.AND(msb,0xff),8)+Bit.AND(lsb,0xff)
 

Jiemde

Member
Licensed User
Try this
B4X:
Dim ut  As Long
msb=readbyte(0)
lsb=readbyte(1)
      
ut=Bit.ShiftLeft(Bit.AND(msb,0xff),8)+Bit.AND(lsb,0xff)

Thank you very much Kolbe, it work for signed var but now I try to resolve the problem for unsigned var ! it's not easy to understand for me.

Best regards

jiemde
 

kolbe

Active Member
Licensed User
Thank you very much Kolbe, it work for signed var but now I try to resolve the problem for unsigned var ! it's not easy to understand for me.

Best regards

jiemde
Use this for signed two byte value

B4X:
Bit.ShiftLeft(readbyte(0),8)+Bit.AND(readbyte(1),0xff)
Accessing the byte directly uses 7th bit in a byte as a sign bit. Using Bit.AND uses all bits in the byte as value bits. So the example above gives you a 15 bit value and the 16 bit is a sign bit.
 

azhar28

New Member
Licensed User
Anyone manage to read from one wire sensor such as MAX6675 using twimaster or spimaster.
I try to use example for i2c and twimaster from kolbe and eric but the compiler give:

Compiling generated Java code. Error
javac 1.7.0_13
src\b4a\trytry\main.java:231: error: cannot find symbol
public static anywheresoftware.b4a.agraham.ioio.B4AIOIO.B4ATwiMaster _twi = null;
^
symbol: class B4ATwiMaster
location: class B4AIOIO
1 error
 

kolbe

Active Member
Licensed User
Anyone manage to read from one wire sensor such as MAX6675 using twimaster or spimaster.
I try to use example for i2c and twimaster from kolbe and eric but the compiler give:

Compiling generated Java code. Error
javac 1.7.0_13
src\b4a\trytry\main.java:231: error: cannot find symbol
public static anywheresoftware.b4a.agraham.ioio.B4AIOIO.B4ATwiMaster _twi = null;
^
symbol: class B4ATwiMaster
location: class B4AIOIO
1 error
Can't really help without seeing the code. However my guess is that you aren't getting a reference to a twi instance before calling a method.
 

James Costello

Member
Licensed User
Kolbe,

I`m trying to get PWM to work so I can control the brightness of some LED`s, Bluetooth connection works fine, tried the demo and can turn on/off the yellow LED on the board. But having a problem getting any of the pins to behave and control an LED.

James


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
 

kolbe

Active Member
Licensed User
Have you tried the workbench app? In this app you have an example of how to use ioio.openPwmOutput. There are many other method examples as well in this app. You need however to adapt the layout to your device.

Kolbe,

I`m trying to get PWM to work so I can control the brightness of some LED`s, Bluetooth connection works fine, tried the demo and can turn on/off the yellow LED on the board. But having a problem getting any of the pins to behave and control an LED.

James
 

James Costello

Member
Licensed User
Kolbe,

When I try to open the Workbench 2.32 I get an error "IOIO 20" library missing; but I`ve already downloaded the IOIO 2.04 library?


James
 

kolbe

Active Member
Licensed User
In the library tab of the IDE make sure you select the correct IOIO library. I named the library "ioio 20" and that is what the workbench app is looking for. Just select the right version (the version shows up in parenthesis once checked) in the tab or make sure the file name is "ioio 20.jar" and "ioio20.xml".


Kolbe,

When I try to open the Workbench 2.32 I get an error "IOIO 20" library missing; but I`ve already downloaded the IOIO 2.04 library?


James
 
Top