Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,783,010 Members 44,548 Now Online
XDA Developers Android and Mobile Development Forum

Parsing serial data over bluetooth - Arduino to Android

Tip us?
 
theBasher91
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 6
Join Date: Jan 2014
Default Parsing serial data over bluetooth - Arduino to Android

Hello,

I have been transmitting values from my Arduino to my Android using the BlueSerial app. It's great so far, however, I'm only able to read values. Ideally, I want to read these values displayed, and convert them to a variable so I can use them for calculations. I have not altered the Blue Serial app, and the code can be found here (I'm unable to post links due to being a new member): github*com/plastygrove/BlueSerial

As I said, I would like to convert the strings to something useful in order to do calculations. Can anyone provide some guidance?

Thanks.
 
panwrona
Old
#2  
Junior Member
Thanks Meter 1
Posts: 9
Join Date: Jun 2014
Location: Wrocław

 
DONATE TO ME
Isn't it easy enough to make Integer.parseInt(receivedMessageString); ??
 
theBasher91
Old
#3  
Junior Member - OP
Thanks Meter 0
Posts: 6
Join Date: Jan 2014
Quote:
Originally Posted by panwrona View Post
Isn't it easy enough to make Integer.parseInt(receivedMessageString); ??
Yeah! Actually, I managed to use that and got it working. But now I want to transmit multiple values and store them as a variable. How can I go about doing that? Over serial, I can transmit them any way (whichever way is easiest), such as:

HTML Code:
Voltage = 25
Current = 10
Speed = 5
Or without text if necessary like:

HTML Code:
25
10
5
Or on a line separated by commas, such as:

HTML Code:
25,10,5
How can I make my android app "know" that there are three separate values being sent, and store each of these into a variable?
 
panwrona
Old
#4  
Junior Member
Thanks Meter 1
Posts: 9
Join Date: Jun 2014
Location: Wrocław

 
DONATE TO ME
Maybe send string values like 'speed: 25', then extract integer from string and turn into value? That's just first idea that came to my mind. What kind of device are you reading from?
 
theBasher91
Old
#5  
Junior Member - OP
Thanks Meter 0
Posts: 6
Join Date: Jan 2014
Quote:
Originally Posted by panwrona View Post
Maybe send string values like 'speed: 25', then extract integer from string and turn into value? That's just first idea that came to my mind. What kind of device are you reading from?
That's actually what I managed to do. I used integer.parseint() for the one value. However, wouldn't this change when I'm sending more than one value? I'm trying to figure out how I can individually read each of the three values and store them. The integer.parseint() is working for the one so far though, so that's a start.

I'm sending data from my Arduino Mega to a self-made Android App via bluetooth. The data sends perfectly. And using integer.parseint(), I was able to even do calculations with the incoming number. But when I try to transmit several values, it gets tricky.
 
Jonny
Old
#6  
Jonny's Avatar
Forum Moderator
Thanks Meter 7,960
Posts: 7,935
Join Date: Jul 2011
Location: Cheshire

 
DONATE TO ME
Maybe a HashMap <String, Integer> could work?

Sent from my HTC One using Tapatalk
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes