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);
}
});
}
}
On Thu, Jan 9, 2014 at 5:55 PM, Ytai Ben-Tsvi <[email protected]> wrote:
> 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.
> On Jan 9, 2014 1:50 AM, "Synn Yong Tan" <[email protected]> wrote:
>
>> 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 ?
>>
>>
>> On Thu, Jan 9, 2014 at 4:46 PM, Ytai Ben-Tsvi <[email protected]> wrote:
>>
>>> 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.
>>>
>>>
>>> On Wed, Jan 8, 2014 at 11:30 PM, Synn Yong Tan <[email protected]> wrote:
>>>
>>>> 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.
>>>>
>>>>
>>>> On Friday, January 3, 2014 1:31:47 PM UTC+8, Ytai wrote:
>>>>
>>>>> 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.
>>>>>
>>>>>
>>>>> On Thu, Jan 2, 2014 at 7:09 AM, Synn Yong Tan <[email protected]>wrote:
>>>>>
>>>>>> 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
>>>>>> ?
>>>>>>
>>>>>>
>>>>>> On Thu, Dec 19, 2013 at 9:44 PM, Synn Yong Tan <[email protected]>wrote:
>>>>>>
>>>>>>> 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.
>>>>>>>
>>>>>>>
>>>>>>> On Thu, Dec 19, 2013 at 12:11 AM, Ytai Ben-Tsvi <[email protected]>wrote:
>>>>>>>
>>>>>>>> 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.
>>>>>>>>
>>>>>>>>
>>>>>>>> On Wed, Dec 18, 2013 at 5:21 AM, Synn Yong Tan <[email protected]>wrote:
>>>>>>>>
>>>>>>>>> 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 ?
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Wed, Dec 18, 2013 at 9:12 AM, Ytai Ben-Tsvi
>>>>>>>>> <[email protected]>wrote:
>>>>>>>>>
>>>>>>>>>> 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.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Tue, Dec 17, 2013 at 9:05 AM, Synn Yong Tan
>>>>>>>>>> <[email protected]>wrote:
>>>>>>>>>>
>>>>>>>>>>> I want to get feedback of an absolute encoder through the uart.
>>>>>>>>>>> Means I separate the inputstream and the led to two thread?
>>>>>>>>>>> On 18 Dec 2013 00:57, "Ytai Ben-Tsvi" <[email protected]> wrote:
>>>>>>>>>>>
>>>>>>>>>>>> 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?
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> On Tue, Dec 17, 2013 at 8:47 AM, Synn Yong Tan <
>>>>>>>>>>>> [email protected]> wrote:
>>>>>>>>>>>>
>>>>>>>>>>>>> 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.
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> On Wed, Dec 18, 2013 at 12:41 AM, Ytai Ben-Tsvi <
>>>>>>>>>>>>> [email protected]> wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>>> Your code is stuck waiting on the UART. Did you get the
>>>>>>>>>>>>>> example code working?
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> On Tue, Dec 17, 2013 at 5:15 AM, Synn Yong Tan <
>>>>>>>>>>>>>> [email protected]> wrote:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> 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.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> On Tue, Dec 17, 2013 at 9:07 PM, Matanel <
>>>>>>>>>>>>>>> [email protected]> wrote:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Did you download 3.3v firmware of IOIOLibs??
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> בתאריך יום שני, 16 בדצמבר 2013 14:39:58 UTC+2, מאת Synn
>>>>>>>>>>>>>>>> Yong Tan:
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> 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.
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> --
>>>>>>>>>>>>>>>> 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 [email protected].
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> To post to this group, send email to
>>>>>>>>>>>>>>>> [email protected].
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Visit this group at http://groups.google.com/
>>>>>>>>>>>>>>>> group/ioio-users.
>>>>>>>>>>>>>>>> For more options, visit https://groups.google.com/
>>>>>>>>>>>>>>>> groups/opt_out.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> --
>>>>>>>>>>>>>>> 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 [email protected].
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> To post to this group, send email to
>>>>>>>>>>>>>>> [email protected].
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Visit this group at http://groups.google.com/
>>>>>>>>>>>>>>> group/ioio-users.
>>>>>>>>>>>>>>> For more options, visit https://groups.google.com/
>>>>>>>>>>>>>>> groups/opt_out.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> --
>>>>>>>>>>>>>> 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 [email protected].
>>>>>>>>>>>>>> To post to this group, send email to
>>>>>>>>>>>>>> [email protected].
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Visit this group at http://groups.google.com/group/ioio-users
>>>>>>>>>>>>>> .
>>>>>>>>>>>>>> For more options, visit https://groups.google.com/
>>>>>>>>>>>>>> groups/opt_out.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> --
>>>>>>>>>>>>> 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 [email protected].
>>>>>>>>>>>>> To post to this group, send email to [email protected]
>>>>>>>>>>>>> .
>>>>>>>>>>>>>
>>>>>>>>>>>>> Visit this group at http://groups.google.com/group/ioio-users.
>>>>>>>>>>>>> For more options, visit https://groups.google.com/
>>>>>>>>>>>>> groups/opt_out.
>>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> --
>>>>>>>>>>>> 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 [email protected].
>>>>>>>>>>>> To post to this group, send email to [email protected].
>>>>>>>>>>>>
>>>>>>>>>>>> Visit this group at http://groups.google.com/group/ioio-users.
>>>>>>>>>>>> For more options, visit https://groups.google.com/
>>>>>>>>>>>> groups/opt_out.
>>>>>>>>>>>>
>>>>>>>>>>> --
>>>>>>>>>>> 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 [email protected].
>>>>>>>>>>> To post to this group, send email to [email protected].
>>>>>>>>>>>
>>>>>>>>>>> Visit this group at http://groups.google.com/group/ioio-users.
>>>>>>>>>>> For more options, visit https://groups.google.com/groups/opt_out
>>>>>>>>>>> .
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>> 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 [email protected].
>>>>>>>>>> To post to this group, send email to [email protected].
>>>>>>>>>>
>>>>>>>>>> Visit this group at http://groups.google.com/group/ioio-users.
>>>>>>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> 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 [email protected].
>>>>>>>>> To post to this group, send email to [email protected].
>>>>>>>>>
>>>>>>>>> Visit this group at http://groups.google.com/group/ioio-users.
>>>>>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> 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 [email protected].
>>>>>>>> To post to this group, send email to [email protected].
>>>>>>>>
>>>>>>>> Visit this group at http://groups.google.com/group/ioio-users.
>>>>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>> --
>>>>>> 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 [email protected].
>>>>>> To post to this group, send email to [email protected].
>>>>>>
>>>>>> Visit this group at http://groups.google.com/group/ioio-users.
>>>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>>>
>>>>>
>>>>> --
>>>> 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 [email protected].
>>>>
>>>> To post to this group, send email to [email protected].
>>>> Visit this group at http://groups.google.com/group/ioio-users.
>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>
>>>
>>> --
>>> 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
>>> [email protected].
>>> To post to this group, send email to [email protected].
>>> Visit this group at http://groups.google.com/group/ioio-users.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>
>>
>> --
>> 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 [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/ioio-users.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
> --
> 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
> [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/ioio-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/groups/opt_out.