Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Joystick bluetooth Commander

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
maxneo

Bascom Member



Joined: 07 Sep 2010
Posts: 35

PostPosted: Wed Jun 17, 2015 12:50 pm    Post subject: Joystick bluetooth Commander Reply with quote

Hi
I try to use an Android app to run a robot "Joystick bluetooth Commander"
but do not know how I should decoda input data flow.Android app
sends ASCII characters'

The data frame is send via BlueTooth to the arduino board and decoded.
'2' is Ascii 32 hex (decimal 50)
'0' is Ascii 30 hex (decimal 4Cool
Data frame: <0x02 0x32 0x30 0x30 0x32 0x30 0x30 0x03>
Data is sent as ascii shall I handle it as a close and use the ASC ()

data flow in my terminal Hex

02 31 36 38 31 39 32 03 02 31 36 38 31 39 32 03
02 31 36 38 31 39 32 03 02 31 36 38 31 39 32 03
02 31 36 38 31 39 32 03 02 31 36 38 31 39 32 03

exampel for ardunio
void getJoystickState(byte data[8]) {
int joyX = (data[1]-4Cool*100 + (data[2]-4Cool*10 + (data[3]-4Cool; // obtain an Int from the ASCII representation
int joyY = (data[4]-4Cool*100 + (data[5]-4Cool*10 + (data[6]-4Cool;
joyX = joyX - 200; // Offset to avoid
joyY = joyY - 200; // transmitting negative numbers


link to Joystick bluetooth Commander
https://play.google.com/store/apps/details?id=org.projectproto.btjoystick&feature=search_result
Does anyone have any suggestions?
many greetings Maxneo

(BASCOM-AVR version : 2.0.7.8 )
Back to top
View user's profile
maxneo

Bascom Member



Joined: 07 Sep 2010
Posts: 35

PostPosted: Wed Jun 17, 2015 12:52 pm    Post subject: Jag försöker igen utan smilys Reply with quote

Hi
I try to use an Android app to run a robot "Joystick bluetooth Commander"
but do not know how I should decoda input data flow.Android app
sends ASCII characters'

The data frame is send via BlueTooth to the arduino board and decoded.
'2' is Ascii 32 hex (decimal 50)
'0' is Ascii 30 hex (decimal 48)
Data frame: <0x02 0x32 0x30 0x30 0x32 0x30 0x30 0x03>
Data is sent as ascii shall I handle it as a close and use the ASC ()

data flow in my terminal

02 31 36 38 31 39 32 03 02 31 36 38 31 39 32 03
02 31 36 38 31 39 32 03 02 31 36 38 31 39 32 03
02 31 36 38 31 39 32 03 02 31 36 38 31 39 32 03

exampel for ardunio
void getJoystickState(byte data[8]) {
int joyX = (data[1]-48)*100 + (data[2]-48)*10 + (data[3]-48); // obtain an Int from the ASCII representation
int joyY = (data[4]-48)*100 + (data[5]-48)*10 + (data[6]-48);
joyX = joyX - 200; // Offset to avoid
joyY = joyY - 200; // transmitting negative numbers


link to Joystick bluetooth Commander
https://play.google.com/store/apps/details?id=org.projectproto.btjoystick&feature=search_result
Does anyone have any suggestions?
many greetings Maxneo
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 4974
Location: Holland

blank.gif
PostPosted: Wed Jun 17, 2015 1:18 pm    Post subject: Reply with quote

there are multiple ways to do it. you get : 02 31 36 38 31 39 32 03 02 31 36 38 31 39 32 03
which means 02 is the start of the frame and this is what you need to watch for.
the 03 seems to mark the end of a frame. I think you also get CR + LF ?
That would make it simple. Just use INPUT and store the data into a line. Then extract the data using mid()

Code:
dim s as string * 50, dgt2 as String*2
s= "02 31 36 38 31 39 32 03 02 31 36 38 31 39 32 03"
dim dgt as string * 3,j as Byte,b as Byte

for j=4 to 10 step 3 'get 32 36 38
  dgt2=mid(s,J,2) 'get 2 digits
  b=hexval(dgt2) -48
  dgt=dgt + str(b)
next
dim value1 as Integer
value1=val(dgt)
 


you can also check out split()

_________________
Mark
Back to top
View user's profile Visit poster's website
maxneo

Bascom Member



Joined: 07 Sep 2010
Posts: 35

PostPosted: Wed Jun 17, 2015 1:53 pm    Post subject: Android Reply with quote

Thanks for the reply Mark, I have tried to use the hex (), Val (), Chr () and it has not been good. It says in the text that should (data [X] -4Cool * 100 -48 is well because it is ASCII can not load byte for byte and decod directly? No, now I will test your proposal many thanks Maxneo
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum