B4A Library IOIO board library

headingwest

Member
Licensed User
Longtime User
thanks for the ioio library

Hi Kolbe,

Thanks for the great work, I went ahead with buying an IOIO only after I found VB4A and the libraries from you and Agraham. Java would have been too steep a learning curve for me as an aging VB programmer. Together IOIO and VB4A are dynamite.

My new touch screen interface is started and hopefully I'll have some photos in a couple of months. Please keep up the great work.

:sign0098:
 

kolbe

Active Member
Licensed User
Longtime User
Just ran your program and that is all I found too. The boolean in initialize is Bluetooth.

The only other thing I saw was that you only connect on firsttime and then disconnect on userclosed. If you userclose and disconnect and then bring the app back to foreground, the process never being killed, you no longer have a connection and it isn't the firsttime so it doesn't reconnect. At least on my Android the process is not killed unless it is in the background and Android kills it to free memory or you call ExitProgram. What I usually do is use IsInitialized and GetState to check for connection.


 

gbdroid

Member
Licensed User
Longtime User
Thank you,
that helped me to bring light in the case - the minimalistic IOIO program I use for testing was failing each second time I start it. I had not yet the time to find the reason - now it is clear.
I know now that it is also not yet correctly solved in the intruder alarm app, but as that should run for ever it does not mind much there.
 

skinner

New Member
Licensed User
Longtime User
IOIO users

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

I just got my IOIO board yesterday so add one more to the list.

Is the source code for the library available? (I'm new to b4a so im not sure where to look.)

I found the docs for the 1.5 version but not for the 1.7version. Where can they be found?

Thanks,
Skinner
 

kolbe

Active Member
Licensed User
Longtime User

Good point. I should get Erel to update the wiki page.

The library actually has all of the documentation built in however. Each method will have a popup appear that explains the function.
 

gillano

Member
Licensed User
Longtime User
digital input

i having trouble with the digital input

this is what i have


Sub Activity_Create(FirstTime As Boolean)
Dim IOIO As IOIO
Dim in As DigitalInput
DigitalInput in = IOIpenDigitalInput(37, DigitalInput.Spec.Mode.PULL_DOWN)
in.waitForValue(True)

in.close()
End Sub


and i am getting an error
Error parsing program.
Error description: Undeclared variable 'digitalinput' is used before it was assigned any value.
Occurred on line: 17
DigitalInput in = IOIpenDigitalInput(37, DigitalInput.Spec.Mode.PULL_DOWN)


what am i doing wrong? i really am in over my head here:sign0085:

i need the digital input to trigger an action that was "Button1_Down"
 

gillano

Member
Licensed User
Longtime User
still getting error

Undeclared variable 'digitalinput' is used before it was assigned any value.
 

headingwest

Member
Licensed User
Longtime User
Ideas for pulse input counting with IOIO

Hi All,

I wanted some ideas for a pulse input counter with the IOIO library.

I have a hall effect device which will send a 3.3v or 5v pulse at varying intervals. The pulse is activated on each rotation which measures rotational speed. I need to count the pulses. Accuracy only needs to be average. The counting is while doing other things with the IOIO. So I'm opening and closing pins etc, but in the background I need to count the pulses.

If I use the DigitalInput.WaitForValue event
- will it block the rest of the program?
- Or does it just sit there and wait for a pulse? Which I can increment a counter.
- If I raise the .WaitForValue event within the event itself, how frequently will it count?

Any other ideas or thoughts on the best way to do this?

Thanks.
 

gillano

Member
Licensed User
Longtime User
got it to compile and run but it pauses on the line

in = IOIpenDigitalInput (37, in.IP_PULL_DOWN)

still not sure how to make this work as a "Button_Down"
 

headingwest

Member
Licensed User
Longtime User
DigitalInput.WaitForValue - Event error

Hi,

I'm trying to use the DigitalInput.WaitForValue which goes to an event. But I get the following error:

java.lang.Exception: Sub flowtick_done signature does not match expected signature.

B4X:
Sub FlowCountSub
   pinFlowmeter.waitForValue("flowtick", True )
End Sub

'Event to handle the pulse
Sub flowtick_done(noexceptions As Boolean, list1 As List, Available As Int, Overflow As Int)
   lFlowCount = lFlowCount + 1
   pinFlowmeter.waitForValue("flowtick", True)
End Sub

Any ideas? Is my event_done structure correct?
 

kolbe

Active Member
Licensed User
Longtime User
Try.

B4X:
Sub flowtick_done(noexceptions As Boolean)

Copy/paste error in the documentation. Sorry. I'll fix it in the next version.

 

kolbe

Active Member
Licensed User
Longtime User
Do you have it working?

From your previous posts... I wouldn't put this code in the create method, it will only get run once. I usually check for a connection to the IOIO in the resume method. If none is detected then I create one. In my apps the work part of the IOIO code is usually event driven by a timer, scheduled process, button, etc.

If you are still having problems post some current code... explain fully what you are trying to do.


got it to compile and run but it pauses on the line

in = IOIpenDigitalInput (37, in.IP_PULL_DOWN)

still not sure how to make this work as a "Button_Down"
 

kolbe

Active Member
Licensed User
Longtime User
I would use the waitfor if the pulse is non periodic (just counting random pulses) and pulseinput.frequency if periodic. Note the waitfor documentation error in the above post.

The waitfor is non-blocking, runs an a separate thread, so you can do whatever while you wait for the event to be raised.

As to the pulse count frequency limit with waitfor. ???? It would depend mostly on the speed of your device and USB latency. I believe Ytai has measured the USB ADB latency to be around 10ms, so thats' 100Hz. Not much. Open Accessory latency is less.

Since you are counting revolutions the pulses should be periodic so I would use pulseinput, plus you can count at much higher frequencies. Check the GitHub page for setting the counter bit width and frequency.

Make sure you use a 5V compatible pin!!!



 

Kbogle24

Member
Licensed User
Longtime User
I need help

I cant wrap my head around this, can someone please help me. I followed this step by step diy on using the ioio with a motor driver breakout board.

Connecting DC motors to the IOIO through the TB6612FNG, a motor driver break out board | Jay Chakravarty

I have everything done but the software. His code was written in java. This is what I wrote for b4a. I cant seem to get it working. Any Ideas?

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 Pwmb As PwmOutput
   Dim STBY_PIN As DigitalOutput 
   Dim BIN1 As DigitalOutput
   Dim BIN2 As DigitalOutput
   
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 MotorFWD As Button 
End Sub

Sub Activity_Create(FirstTime As Boolean)
         YOYO.Initialize(False)
         YOYO.WaitForConnect()
         MotorFWD.Initialize ("motorfwd")
         Activity.AddView (MotorFWD,20,20,100,100)
      
         Pwmb = YOYO.OpenPwmOutput(45,Pwmb.OP_NORMAL,100)
         STBY_PIN = YOYO.OpenDigitalOutput (42,STBY_PIN.OP_NORMAL,False)
         BIN1 = YOYO.OpenDigitalOutput (43,BIN1.OP_NORMAL,True)
         BIN2 = YOYO.OpenDigitalOutput (44,BIN2.OP_NORMAL,True)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub motorfwd_Click()
YOYO.BeginBatch
         Pwmb.DutyCycle = 1.0
         BIN1.Write = True
         BIN2.Write = False
YOYO.EndBatch 
End Sub

I am using the newest ioio lib. Which I have noticed that when using the .write command true is off and false is on. Is this right?
 

kolbe

Active Member
Licensed User
Longtime User
Ok here's some ideas that might help.

At some time after the activity_create, check to make sure you have a connection to the IOIO. Check the state of the IOIO.

You set the PWM to 100Hz, should work but the board works up to 100kHz. Is there a recommended frequency?

The batch only works with writes, I'm not sure if your dutycycle call will do anything.

I don't think you really need to use the batch function. To simplify and debug just set one of the pins to false because you init both pins to True. You can test this with a DMM.

Vcc should be 3.3v not 5v. The digitalout should be 3.3v when HIGH or True, 0 when LOW or False. Test this first without the motor driver connected. If you find different behavior when connected you have an electrical problem, drawing to much current etc.

Your standby should be init to True.

Don't connect the Motor V+ to the IOIO unless you are absolutely sure they never max out the current sourcing ability of the IOIO (stall current is usually a problem). This will at best cause weird IOIO behavior, at worst fry your IOIO.


 

Kbogle24

Member
Licensed User
Longtime User
The following code works perfect now thanks to Kolbes help. Thank you !


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 Pwmb As PwmOutput
   Dim STBY_PIN As DigitalOutput 
   Dim BIN1 As DigitalOutput
   Dim BIN2 As DigitalOutput
   
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 MotorFWD As Button 
End Sub

Sub Activity_Create(FirstTime As Boolean)
         YOYO.Initialize(False)
         YOYO.WaitForConnect()
         MotorFWD.Initialize ("motorfwd")
         Activity.AddView (MotorFWD,20,20,100,100)
      
         Pwmb = YOYO.OpenPwmOutput(45,Pwmb.OP_NORMAL,100)
         STBY_PIN = YOYO.OpenDigitalOutput (42,STBY_PIN.OP_NORMAL,True)
         BIN1 = YOYO.OpenDigitalOutput (43,BIN1.OP_NORMAL,True)
         BIN2 = YOYO.OpenDigitalOutput (44,BIN2.OP_NORMAL,True)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub motorfwd_Click()

         Pwmb.DutyCycle = 1.0
         BIN1.Write = True
         BIN2.Write = False

End Sub

I just made two changes to the code. First the STBY_PIN should be set to true and second I took off the batch commands.

 

gillano

Member
Licensed User
Longtime User

Still not working:BangHead: this is what I have
B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

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 Label1 As Label
   Dim Pulse As Button   
   Dim Reset As Button
   Dim Label1 As Label
   Dim Addition As RadioButton
   Dim Subtraction As RadioButton
   
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("testscreen")
End Sub

Sub Activity_Resume

Dim IOIO As IOIO
Dim PulseIn As PulseInput
PulseIn = IOIO.OpenPulseInput (31,PulseIn.IP_FLOATING,PulseIn.RATE_16MHZ,PulseIn.NEGATIVE , True)

Dim Add1 As DigitalInput
Add1 = IOIO.OpenDigitalInput (34, Add1.IP_PULL_UP) 

Dim Subt1 As DigitalInput
Subt1 = IOIO.OpenDigitalInput (35, Add1.IP_PULL_UP) 


End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Pulse_Click
Dim P As Int

If Addition.Checked = True Then 
P= Label1.Text+1
Label1.Text = NumberFormat (P, 1, 0)
End If


If Subtraction.Checked = True Then
P= Label1.Text-1 
Label1.Text = NumberFormat (P, 1, 0)
End If

End Sub
Sub Reset_Click
Label1.Text = "0"

End Sub


Sub Exit_Click
Dim Result As Int
Result = Msgbox2 ("Are you sure?", "Exit", "Yes", "No", "", Null)
If Result = DialogResponse.Positive Then
ExitApplication

End If
End Sub

What I am trying to do:
Pin 31 will be getting pulses from a transducer that will break a connection of 5v giving a momentary Low voltage (this will be done with photo-resistor or a hall sender/ reed switch) There will be no pattern or regular frequency to this signal it will almost always be slowing down or accelerating, some times it will be static with no pulses for minutes(or more).
This pulse will replace the "Pulse" button and make the value of the label increase or decrease, depending on the state of the radio buttons. The pulse must always be running until the app is exited regardless if the home screen or any other apps are opened(it will run in the background) or the usage of the radio buttons (or future buttons).

The radio buttons can also be controlled by digital inputs on Pins 34 and 35, and will show getting checked on the screen, so a hardware switch or the screen tap can be used.

Please help me out:sign0163: I am feeling very over my head here so code that I can paste in will be greatly appreciated. Please feel free to school me on how/why it works, so I can begin trying to make sense of this and hopefully understand it someday.
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…