Post Reply

Parsing serial data over bluetooth - Arduino to Android

OP theBasher91

12th July 2014, 01:54 AM   |  #1  
OP Junior Member
Thanks Meter: 0
 
6 posts
Join Date:Joined: Jan 2014
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.
13th July 2014, 04:04 PM   |  #2  
Junior Member
Flag Wrocław
Thanks Meter: 1
 
14 posts
Join Date:Joined: Jun 2014
Donate to Me
More
Isn't it easy enough to make Integer.parseInt(receivedMessageString); ??
14th July 2014, 01:34 PM   |  #3  
OP Junior Member
Thanks Meter: 0
 
6 posts
Join Date:Joined: Jan 2014
Quote:
Originally Posted by panwrona

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?
14th July 2014, 05:47 PM   |  #4  
Junior Member
Flag Wrocław
Thanks Meter: 1
 
14 posts
Join Date:Joined: Jun 2014
Donate to Me
More
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?
14th July 2014, 06:24 PM   |  #5  
OP Junior Member
Thanks Meter: 0
 
6 posts
Join Date:Joined: Jan 2014
Quote:
Originally Posted by panwrona

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.
14th July 2014, 06:52 PM   |  #6  
Jogny's Avatar
Forum Moderator
Flag Cheshire
Thanks Meter: 8,061
 
8,012 posts
Join Date:Joined: Jul 2011
Donate to Me
More
Maybe a HashMap <String, Integer> could work?

Sent from my HTC One using Tapatalk
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Top Threads in Java for Android App Development by ThreadRank