Skip to first unread message

Mohd Yazid Mohd Anas Khan

unread,
Sep 9, 2014, 10:04:16 AM9/9/14
to mitappinv...@googlegroups.com

hello guys!

I hope you can help me with this. I'm working on a project involving arduino and android app. this app is just to display real-time data from the arduino. although the project is about speedometer, i want to understand the basic of data transfer from arduino to android. thus, here is my problem. 

i have 2 data that need to be displayed. "Speed" and "Distance". So i've created a simple arduino code to represent those variables.



i'm assuming that my arduino code is correct. so i'm trying to send a CSV formatted text to android app. my app is as shown below together with code block.





the app seems to be able to accept the speed and distance from the arduino values BUT it keeps on displaying an error "cannot parse text argument to "list from csv row" as CSV-formatted row" & "csv text cannot be parsed as a row". if i tap the screen to ignore the error message, it will continue to display the next incoming data but the error message will keep on appearing over and over again.  

Can you help me with this? thanks in advance/

Taifun

unread,
Sep 9, 2014, 2:17:41 PM9/9/14
to mitappinv...@googlegroups.com
I would use the list from csv table block then without replacing \n by space in your blocks
set global items_data to list from csv table mydata
also try to debug your blocks using "Do it" to find out, how mydata looks like
Taifun

Mohd Yazid Mohd Anas Khan

unread,
Sep 10, 2014, 2:37:03 PM9/10/14
to mitappinv...@googlegroups.com
i've tried using the method that u've suggested and it could display my data without any error messages. BUT the problem is it keeps on blinking as it tries to display new data. do u know why it blinks? 

but then i was a bit curious about my serial print from arduino because it contains some "gibberish characters" mixing with my real data. it turns out that my arduino code was wrong. 
so i've looked for solution and I've created a new code as shown below. the following produces a clean data output in serial monitor (without any gibberish).



unfortunately, the android app couldn't display anything, the only output on my screen is Speed=(?) 

do u know what's the problem? is it caused by my arduino code ? or android code? why can't my android app retrieve the CSV output from arduino? i'm using [  set global items_data to list from csv table mydata ]
----------------------------------------------------------------------------------
int speeds=0;   
int distance=0;
int timer=0;
int wspeed,wtimer,wdistance;
byte loTimer,hiTimer,loSpeed,hiSpeed,loDistance,hiDistance;

void setup()
{
  Serial.begin(9600);
}
void loop()
{
 speeds=speeds+2; 
 distance=distance+5;
 timer=timer+1;
 
 hiSpeed = highByte(speeds);
 loSpeed = lowByte(speeds);
 
 hiDistance = highByte(distance);
 loDistance = lowByte(distance);
 
 hiTimer = highByte(timer);
 loTimer = lowByte(timer);

wspeed=(hiSpeed, loSpeed);
wdistance=(hiDistance, loDistance);
wtimer=(hiTimer, loTimer);

  Serial.print(wspeed);
  Serial.println(",");
  Serial.print(wdistance);
  Serial.println(",");
  Serial.print(wtimer);
  
  Serial.print("\n");
  delay(1000);
}
----------------------------------------------------------------------------------

Abraham Getzler

unread,
Sep 10, 2014, 9:09:37 PM9/10/14
to mitappinv...@googlegroups.com
Serial.println(","); inserts a \n after the comma.

You don't want that.

You want output of three numbers separated by commas per line, right?

Change both Serial.println(",")  to Serial.print(",")  in your code.
(Drop the ln from println).

ABG

Mohd Yazid Mohd Anas Khan

unread,
Sep 11, 2014, 2:20:55 PM9/11/14
to mitappinv...@googlegroups.com

Abraham Getzler

unread,
Sep 11, 2014, 3:38:36 PM9/11/14
to mitappinv...@googlegroups.com
I'm going to have depend on you or some other Arduino fan for language help here.
I haven't used an Arduino, and have barely scratched the surface of C.

I can, however list a few ways to go wrong here, so you can know what to check ..

Your terminal output list looks reasonable in its format,
but I wonder if it really reflects the intended data values originating
on the Arduino.  All the numbers are less than 256, yet your
Arduino program is dealing with two-byte numbers.  Are all the high bytes zero?

Should your data contain negative values?
I don't see any.

What is the statement on the Arduino side for converting
internal number formats (byte, int, etc.) to external ASCII text?
(Really, I'm ignorant here.  Something like sprintf()?)

Could you show us the blocks you use to pull your data from Arduino?
Specifically, are you pulling bytes, or pulling text?

Text is easier to debug, and feeds into csv conversion naturally.
Bytes might arrive in the wrong order for reassembly into integers,
because of high-endian versus low-endian architectures.

ABG






Mohd Yazid Mohd Anas Khan

unread,
Sep 13, 2014, 4:49:42 AM9/13/14
to mitappinv...@googlegroups.com
the app is now working as expected! thanks to you guys Taifun & ABG for helping me all this while. i've found the problem in my android code block after referring to other people's project. only one block was the cause of all the problems that i've had. i'm not really sure the reason behind this block perhaps you guys know more about it. to ABG, i didn't even know whether i was transferring "byte" or "text" but it seems like i'm actually transferring CSV-formatted text from arduino. i didn't do any conversion from (int/float/byte) to ASCII-code on Arduino side. Just have a look at my final codes below. 


in the arduino code above, what i'm doing is just outputting all my calculated variables by using Serial.print commands and thats it. no high byte and low byte thingy. so this means that I'm actually transferring texts right?

so here is my android code block.

as you can see, the one that i've circled is what making this app functioning properly. before this, it was "number -1" block. i'm not really sure what was the purpose of -1 (from what i've read, -1 related with something called Delimiter). 

i would be thankful if you can help me to improve my app from this point so that it can become a more functional speedometer. there is one thing i need to improve. as this app will be used as speedometer display, i will have to transfer my data at a fast interval. how do i set the data rate interval for this app? for now the app is updating itself every 1 second. can i change the interval to a much shorter interval?

thanks in advance! 


Enis

unread,
Sep 13, 2014, 9:39:52 AM9/13/14
to mitappinv...@googlegroups.com
I see you're using Classic... Frankly, you should be using AI2 instead as AI Classic will go away soon.  See this thread:

https://groups.google.com/d/msg/mitappinventortest/9PkTeaRmmm0/6ZAeAbGz8XwJ

You'll end up finishing your app just in time for Classic to go away.  I really suggest you start developing this with AI2.
Reply all
Reply to author
Forward
0 new messages