IOIO first try project

121 views
Skip to first unread message

Synn Yong Tan

unread,
Dec 16, 2013, 7:39:58 AM12/16/13
to ioio-...@googlegroups.com
Hi, 
This is my 1st try on IOIO. I done everything according to the OIOI OTG Beginners Guide. But when i toggled the button, the led on IOIO board didn't light up. 
Any ideas what caused this problem ? Anyone has the solution for this ? Or how to debug it ?
Secondly is the conversion to dalvik format failed with error 1. I can export the project into apk file for the 1st time. But the second time I try to export the project, this error comes out.
Anyone knows what is the problem caused this error and how to solve it ?

Thanks for your help.

Al B

unread,
Dec 16, 2013, 12:03:53 PM12/16/13
to ioio-...@googlegroups.com
If you are using eclipse, then try to trace the problem with the debugger and report back here.


Ytai Ben-Tsvi

unread,
Dec 16, 2013, 8:15:41 PM12/16/13
to ioio-...@googlegroups.com
A good place to start is to try the prebuilt HelloIOIO.apk. This will tell us whether this is a problem with your app / build environment or a problem with the IOIO / Android comms.


On Mon, Dec 16, 2013 at 9:03 AM, Al B <cagi...@gmail.com> wrote:
If you are using eclipse, then try to trace the problem with the debugger and report back here.


--
You received this message because you are subscribed to the Google Groups "ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ioio-users+...@googlegroups.com.
To post to this group, send email to ioio-...@googlegroups.com.
Visit this group at http://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/groups/opt_out.

Synn Yong Tan

unread,
Dec 17, 2013, 6:32:39 AM12/17/13
to ioio-...@googlegroups.com
Can help me see on my code ? The led just can't light on after i toggled my button.
**********************************************************************************************************
package ioio.examples.simple;

import ioio.lib.api.DigitalOutput;

import ioio.lib.api.IOIO;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import ioio.lib.api.Uart;
import ioio.lib.api.exception.ConnectionLostException;
import ioio.lib.util.BaseIOIOLooper;
import ioio.lib.util.IOIOLooper;
import ioio.lib.util.android.IOIOActivity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.ToggleButton;

public class IOIOSimpleApp extends IOIOActivity {
private TextView textView_;
private ToggleButton toggleButton_;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textView_ = (TextView) findViewById(R.id.TextView);
toggleButton_ = (ToggleButton) findViewById(R.id.ToggleButton);

enableUi(false);
}

class Looper extends BaseIOIOLooper {
private Uart input_;
private DigitalOutput led_;

@Override
public void setup() throws ConnectionLostException {
led_ = ioio_.openDigitalOutput(IOIO.LED_PIN, true);
input_ = ioio_.openUart(6, 7, 9600, Uart.Parity.NONE, Uart.StopBits.ONE);
enableUi(true);
}

@Override
public void loop() throws ConnectionLostException, InterruptedException {
InputStream in  = input_.getInputStream();
String reading = convertStreamToString(in);
setText(reading);
led_.write(!toggleButton_.isChecked());
Thread.sleep(10);
}

@Override
public void disconnected() {
enableUi(false);
}
}

@Override
protected IOIOLooper createIOIOLooper() {
return new Looper();
}

private void enableUi(final boolean enable) {
runOnUiThread(new Runnable() {
@Override
public void run() {
toggleButton_.setEnabled(enable);
}
});
}

private String convertStreamToString(InputStream reading){
BufferedReader rd=new BufferedReader(new InputStreamReader(reading),4096);
String line;
StringBuilder sb=new StringBuilder();
try {
while ((line = rd.readLine()) != null) {
sb.append(line);
}
rd.close();
}catch (IOException e) {
e.printStackTrace();
}
String contentOfMyInputStream = sb.toString();
return contentOfMyInputStream;
}
private void setText (final String str) {
runOnUiThread(new Runnable() {
@Override
public void run() {
textView_.setText(str);
}
});
}
}


--
You received this message because you are subscribed to a topic in the Google Groups "ioio-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ioio-users/wTlJJcG6LS8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ioio-users+...@googlegroups.com.
Message has been deleted

Matanel

unread,
Dec 17, 2013, 8:07:09 AM12/17/13
to ioio-...@googlegroups.com
Did you download 3.3v firmware of IOIOLibs??

בתאריך יום שני, 16 בדצמבר 2013 14:39:58 UTC+2, מאת Synn Yong Tan:

Synn Yong Tan

unread,
Dec 17, 2013, 8:15:17 AM12/17/13
to ioio-...@googlegroups.com
yea. my apps actually works for the ori version of IOIO sample app. But after i edited the code as the code i posted above, then the led light cannot turn on.


--

Ytai Ben-Tsvi

unread,
Dec 17, 2013, 11:41:54 AM12/17/13
to ioio-...@googlegroups.com
Your code is stuck waiting on the UART. Did you get the example code working?


--
You received this message because you are subscribed to the Google Groups "ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ioio-users+...@googlegroups.com.

Synn Yong Tan

unread,
Dec 17, 2013, 11:47:32 AM12/17/13
to ioio-...@googlegroups.com
ya. the example code works, I also found that the UART part gt problem after i tried it part by part.
But i have no clue for it. Any clue or guide for me to correct the code?! 
Thanks for your kind help.

Ytai Ben-Tsvi

unread,
Dec 17, 2013, 11:56:41 AM12/17/13
to ioio-...@googlegroups.com
readLine() will block until a new line sequence appears on the input. If you want to do that, you'll have to run it on a separate thread. What are you really trying to achieve?

Synn Yong Tan

unread,
Dec 17, 2013, 12:05:27 PM12/17/13
to ioio-...@googlegroups.com

I want to get feedback of an absolute encoder through the uart. Means I separate the inputstream and the led to two thread?

Ytai Ben-Tsvi

unread,
Dec 17, 2013, 8:12:34 PM12/17/13
to ioio-...@googlegroups.com
A separate thread might make sense in this case, since it will allow you to keep the code simple (as opposed to having to assemble strings out of fragmented readings).
Having said that, if your original program got stuck, a separate thread wouldn't fix that (it will get stuck too), so you might have another problem.

Synn Yong Tan

unread,
Dec 18, 2013, 8:21:04 AM12/18/13
to ioio-...@googlegroups.com
The code is working until i added the UART part into it. So means, i just have to separate them into two thread instead of one single thread ?

Ytai Ben-Tsvi

unread,
Dec 18, 2013, 11:11:06 AM12/18/13
to ioio-...@googlegroups.com
Yes. But what I meant is that your UART didn't get any readings (that's why your program got stuck), so there's probably something else going wrong there.

Synn Yong Tan

unread,
Dec 19, 2013, 8:44:46 AM12/19/13
to ioio-...@googlegroups.com
I see. Then i have to try it out 1st because i just tried the led part without connecting the encoder. 
Thanks for your help, Ytai. 
This is a very good discussion groups for all IOIO-users.

Synn Yong Tan

unread,
Jan 2, 2014, 10:09:41 AM1/2/14
to ioio-...@googlegroups.com
Hi,
I used a 9v battery as the power supply of my IOIO OTG. The problem comes when i connect my IOIO board with UART to RS232 converter on the 5v pin and gnd, there is no power supply for the IOIO board. What is the problem that caused this ? OR what are the potential reasons caused this ? 

Ytai Ben-Tsvi

unread,
Jan 3, 2014, 12:31:47 AM1/3/14
to ioio-...@googlegroups.com
Either your battery is finished or there's a short circuit somewhere.
In general a 9V battery isn't a great idea for the IOIO, since it will typically not be able to source enough current to maintain charging of the Android. LiPo packs are a great choice for battery powered applications.

Synn Yong Tan

unread,
Jan 9, 2014, 2:30:24 AM1/9/14
to ioio-...@googlegroups.com
Hi, there,
my apps is working now. But there is a problem, how should i do so that my apps only display the latest string as the encoder continuous send string to my phone.

Ytai Ben-Tsvi

unread,
Jan 9, 2014, 3:46:30 AM1/9/14
to ioio-...@googlegroups.com
See IOIOSimpleApp as an example: from your thread that reads the encoder, you can pass the string you want to display to the main task using runOnUiThread, and it will then get displayed on a TextView that you can assign for it.

Synn Yong Tan

unread,
Jan 9, 2014, 4:50:01 AM1/9/14
to ioio-...@googlegroups.com
Hi, Ytai..
I did use the IOIOsimpleApp as my example. and it able to display. The problem now is the string keep on display until the whole screen is occupied.
What i want is just display the latest string only by replacing the previous input stream.
How should i do this or any example for me to refer ?

Ytai Ben-Tsvi

unread,
Jan 9, 2014, 4:55:07 AM1/9/14
to ioio-...@googlegroups.com

setText() on a TextView replaced any previous text it displays. Try to run IOIOSimpleApp and see. If you still can't solve your problem, please share your code.

Synn Yong Tan

unread,
Jan 9, 2014, 6:04:54 AM1/9/14
to ioio-...@googlegroups.com
Hi, Ytai. The following is my code. Another problem is the strings only display after the IOIO's power supply is disconnected.

package ioio.examples.simple;


import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import ioio.lib.api.Uart;
import ioio.lib.api.IOIO;
import ioio.lib.api.exception.ConnectionLostException;
import ioio.lib.util.BaseIOIOLooper;
import ioio.lib.util.IOIOLooper;
import ioio.lib.util.android.IOIOActivity;
import android.os.Bundle;
import android.widget.TextView;

public class IOIOSimpleApp extends IOIOActivity {
private TextView textView_;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

textView_ = (TextView)findViewById(R.id.TextView);
}

class Looper extends BaseIOIOLooper {
private Uart input_;
@Override
public void setup() throws ConnectionLostException {
input_ = ioio_.openUart(6, 7, 19200, Uart.Parity.NONE, Uart.StopBits.ONE);
}

@Override
public void loop() throws ConnectionLostException, InterruptedException {
InputStream in = input_.getInputStream();
String reading = convertStreamToString(in);
setText(reading);
}
}

@Override
protected IOIOLooper createIOIOLooper() {
return new Looper();
}

private String convertStreamToString(InputStream reading){
BufferedReader rd=new BufferedReader(new InputStreamReader(reading),4096);
String line;
StringBuilder sb=new StringBuilder();
try {
while ((line = rd.readLine()) != null) {
sb.append(line);
}
rd.close();
}catch (IOException e) {
e.printStackTrace();
}
String contentOfMyInputStream = sb.toString();
return contentOfMyInputStream;
}
private void setText (final String str) {
runOnUiThread(new Runnable() {
@Override
public void run() {
textView_.setText(str);
}
});
}
}

Ytai Ben-Tsvi

unread,
Jan 9, 2014, 9:18:24 PM1/9/14
to ioio-...@googlegroups.com
Your convertStreamToString() function hangs in a loop until the stream is closed, and keeps appending new lines to the string until it does. Then, the IOIO disconnects and readLine() finally returns null and your function exits and you get a really long string.
What you probably want is along the lines of:

class Looper {
...
private BufferedReader reader_;
...
void setup() {
  ...
  reader_ = new BufferedReader(new InputStreamReader(uart.getInputStream()));
  ...
}

void loop() {
  String line = reader_.readLine();
  if (line != null) {
    setText(line);
  }
}

Synn Yong Tan

unread,
Jan 10, 2014, 12:35:53 AM1/10/14
to ioio-...@googlegroups.com
Hi, Ytai. Thanks, The code is finally working now. Now I'm trying to add a calculation function by using the uart input. I dont know this is the correct way to do it or not. It can works sometimes but not efficient and sometimes not working.
my code is as following
public void loop() throws ConnectionLostException, InterruptedException {
double value1; 
double result; 

String line;
try {
line = reader_.readLine();
if (line != null) {
   setText(line);
   
   value1 = Double.parseDouble(line);
result = (value1 + 1) * 360 / 8192 ;
String angle = Double.toString(result);
angle_.setText(angle);
 }
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}  
}

Ytai Ben-Tsvi

unread,
Jan 10, 2014, 12:43:30 AM1/10/14
to ioio-...@googlegroups.com
Look at what the setText() method does. You're not allowed to update the Android UI directly from the IOIO thread. Do a similar thing for the angle.
In the future, look at the logcat output produced by your program when something is not working right - it would give you important hints to be able to figure out what's wrong.

Synn Yong Tan

unread,
Jan 10, 2014, 4:21:44 AM1/10/14
to ioio-...@googlegroups.com
Ok and thanks Ytai. 
There is a question i want to ask. 
If my encoder keep on sending the string will it affect the calculation ?
Because now my apps not able to display the result instantly. I have to press back button and exit then re-enter the apps only able to get the result.

Ytai Ben-Tsvi

unread,
Jan 10, 2014, 11:37:34 AM1/10/14
to ioio-...@googlegroups.com
I don't understand the question. Can you send your new code?

Synn Yong Tan

unread,
Jan 10, 2014, 11:42:50 AM1/10/14
to ioio-...@googlegroups.com
My encoder is sending the string non-stop and instant time. So will it affect my calculation code part?
Because after i add the calculation code, i have to exit my apps and then re-enter the app in order to get the reading of the encoder and also result of calculation. It no longer display instantly like before the calculation code is added.
The following is the code.


package ioio.examples.simple;

import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import ioio.lib.api.Uart;
import ioio.lib.api.IOIO;
import ioio.lib.api.exception.ConnectionLostException;
import ioio.lib.util.BaseIOIOLooper;
import ioio.lib.util.IOIOLooper;
import ioio.lib.util.android.IOIOActivity;
import android.os.Bundle;
import android.widget.TextView;

public class IOIOSimpleApp extends IOIOActivity {
private TextView textView_;
private TextView angle_;


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

textView_ = (TextView) findViewById(R.id.TextView);
angle_ = (TextView)findViewById(R.id.angle);

}

class Looper extends BaseIOIOLooper {
private Uart input_;
private BufferedReader reader_;

@Override
public void setup() throws ConnectionLostException {
input_ = ioio_.openUart(6, 7, 19200, Uart.Parity.NONE, Uart.StopBits.ONE);
reader_ = new BufferedReader(new InputStreamReader(input_.getInputStream()));
 


}

@Override
public void loop() throws ConnectionLostException, InterruptedException {
double value1; 
double result; 

String line;
try {
line = reader_.readLine();
if (line != null) {
   setText(line);
   value1 = Double.parseDouble(line);
result = (value1 + 1) * 360 / 8192 ;
String angle = Double.toString(result);
setText1(angle);
 }
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void disconnected() {
}
}

@Override
protected IOIOLooper createIOIOLooper() {
return new Looper();
}
private void setText(final String str) {
runOnUiThread(new Runnable() {
@Override
public void run() {
textView_.setText(str);
}
});
}
private void setText1(final String str) {
runOnUiThread(new Runnable() {
@Override
public void run() {
angle_.setText(str);
}
});
}

}

Ytai Ben-Tsvi

unread,
Jan 11, 2014, 2:17:13 AM1/11/14
to ioio-...@googlegroups.com
I don't see anything obviously wrong with your code, and I'm also not sure I understand exactly in which way it fails. At this point, I would recommend you to try some debugging techniques, e.g.:
  • Add some Log.d(...) statements in your code and examine logcat to figure out what it is doing.
  • Use step-by-step debugging from Eclipse.

Synn Yong Tan

unread,
Jan 11, 2014, 3:59:48 AM1/11/14
to ioio-...@googlegroups.com
Hi, Ytai, thanks for your recommendation, I'll try it.
I think the app is working. Just after i add the calculation part, it cannot display instantly. I have to exit the apps and re-enter the app, then only the app able to display my encoder reading and also calculation result.
My encoder send signal continuously and non-stop and this affected the calculation? Could this possible happen?

Ytai Ben-Tsvi

unread,
Jan 11, 2014, 4:02:39 AM1/11/14
to ioio-...@googlegroups.com
This shouldn't happen. Normally you don't have to exit an app in order to get it to work... :)
From your code I would expect that the text fields would constantly update with recent values.
BTW, what version of IOIOLib are you using?

Synn Yong Tan

unread,
Jan 11, 2014, 8:44:05 AM1/11/14
to ioio-...@googlegroups.com
I see. I'm using IOIO0330.. Do you think this might affected the apps ?

Ytai Ben-Tsvi

unread,
Jan 11, 2014, 11:43:22 AM1/11/14
to ioio-...@googlegroups.com
No, I was just worried you might be using an old version. v3.30 should be fine (although you might want to upgrade at some point).
Let me know if you are able to gather more information on when it actually gets stuck. You can do it by letting it run while connected to a debugger, then, when it gets stuck, pause the IOIO thread and see what it's stuck on.

Synn Yong Tan

unread,
Jan 11, 2014, 11:58:48 AM1/11/14
to ioio-...@googlegroups.com
Ok. thanks for your great help. 
I'll let you know if i able to find it where the problem comes from. 

Synn Yong Tan

unread,
Jan 13, 2014, 2:47:35 AM1/13/14
to ioio-...@googlegroups.com
Hi, Ytai..
I guess i find out where is the problem. I think the conversion of string(line) to double(value1) caused the display problem. It looks like the apps is confuse for displaying the line and conversion from string to double. 
Is this possible?  

Ytai Ben-Tsvi

unread,
Jan 13, 2014, 3:00:46 AM1/13/14
to ioio-...@googlegroups.com
Did you try to run your app with a debugger?

Synn Yong Tan

unread,
Jan 13, 2014, 3:06:21 AM1/13/14
to ioio-...@googlegroups.com
i didn't. I try it with the other way. I tested my app line by line of code. 

Ytai Ben-Tsvi

unread,
Jan 13, 2014, 4:24:39 AM1/13/14
to ioio-...@googlegroups.com
Not sure I understand what you mean. In any case, what did you find?

Synn Yong Tan

unread,
Jan 13, 2014, 5:20:58 AM1/13/14
to ioio-...@googlegroups.com
Here is the code that i tried which can run without any problem. So, my doubt is "   value1 = Double.parseDouble(line); " causing the problem. Yet, i still dont know how i should solve this or is there any other way for me to convert it into double data type.


package ioio.examples.simple;

import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStreamReader;
import ioio.lib.api.Uart;
   result = (8191+1) * 360 / 8192 ;
String angle = String.valueOf(result);

Synn Yong Tan

unread,
Jan 13, 2014, 9:55:55 AM1/13/14
to ioio-...@googlegroups.com
Hi, Ytai, I already solved the problem. Thanks for your great help.

Reply all
Reply to author
Forward
0 new messages