Sending STX, ETX and joystick coordinates to arduino via bluetooth!

358 views
Skip to first unread message

thenewbie

unread,
Jan 22, 2017, 12:46:01 AM1/22/17
to mitappinv...@googlegroups.com
Guys I need help. I posted a similar problem a few months ago, and thanks to all those who spared me time. I need help, now how do I send STX, ETX and joystick coordinates to the arduino? I did some reading but I was not able to get anywhere with it. So I found this ino code on arduino.cc forum and I actually got it to work, of course I used an android app from playstore. But the problem is I need to create my own android app, I need it to control my pan/tilt servos.

I browsed in app inventor forum and I was wondering if that "sendBytes.png" I found somewhere on this forum will work. I attached it. 

Thanks a lot in advance. I owe you one hehe help me out XD Kudos!
blocks.png
joy bt ino.jpg
joy bt.jpg
sendBytes.png

Ghica

unread,
Jan 22, 2017, 9:44:30 AM1/22/17
to MIT App Inventor Forum
What prevented you from trying this out yourself before posting this on the forum?
We do not have your hardware and do not know more of your .ino file, therefore you should be able to find out much better that your forum readers.
Cheers, Ghica

thenewbie

unread,
Jan 23, 2017, 7:57:29 AM1/23/17
to MIT App Inventor Forum
Ghica. is their a way for me to send 2 values at the same time? Like if I want to send x and y coordinates of the joystick at the same time, will that be possible? kindly check out that block of code i attached.
drag.jpg

Ghica

unread,
Jan 23, 2017, 9:37:52 AM1/23/17
to MIT App Inventor Forum
I do not see a reason why you could not send it like this. The question would be if the other side, your Arduino, will receive it in the right way. You have that in hand by writing the proper .ino
Try it! See my question above.
Cheers, Ghica.

thenewbie

unread,
Jan 24, 2017, 9:13:42 AM1/24/17
to MIT App Inventor Forum
I used this and the serial monitor keeps giving me random numbers everytime I move the joystick. 
1.jpg

Ghica

unread,
Jan 24, 2017, 9:24:19 AM1/24/17
to MIT App Inventor Forum
So?
What is wrong? The App Inventor side? Or the Arduino side?
Cheers, Ghica.

thenewbie

unread,
Jan 24, 2017, 11:10:57 PM1/24/17
to MIT App Inventor Forum
Ghica whats wrong with this block?
1.jpg

Ghica

unread,
Jan 25, 2017, 5:18:40 AM1/25/17
to MIT App Inventor Forum
Can be anything. From a red triangle elsewhere in your code to a bug in App Inventor.
Mostly this is something that appears while you are assembling the block. Try refreshing the browser page. Does it go away?
If not, post an .aia and a screenshot of more (all) blocks.
Cheers, Ghica.

thenewbie

unread,
Jan 25, 2017, 9:59:18 AM1/25/17
to MIT App Inventor Forum
restarting app inventor did the job. Still my overall project does not work. Everytime I drag the jostick, the serial monitor is displaying random numbers. Ghica send me links on how to send joystick data and also the arduino code to read and interpret it. I am on a deadend right now.

thenewbie

unread,
Jan 25, 2017, 10:07:40 AM1/25/17
to MIT App Inventor Forum
as of now i am trying to figure out the data sent by the joystick so I can write the arduino code for servo control. 
1.jpg
2.jpg

Ghica

unread,
Jan 25, 2017, 11:43:56 AM1/25/17
to MIT App Inventor Forum
How to debug things:
In addition to sending numbers to the BT device, add some UI elements to your phone screen and display the numbers you are trying to send there.
I have some comments on your code:
- The clock you have is a dangerous thing and I do not see why you would need it.
- Your AfterPicking, in the then part would be better if would set the label1 with green color
- Add a disconnect button.
- having both "when Dragged" and "when TouchUp" may interfere in unexpected ways and you seem to do the same thing for both. Delete one of them.

And now the BT device: install an App that can send data to your device and try to find out what data you should send to make your device move. It may be different from what you think.
Also, you could try to send some data back, to see in the app what happens. Yes, you need a clock then to find out if there is data to recieve.
Cheers, Ghica.

thenewbie

unread,
Jan 26, 2017, 1:15:06 AM1/26/17
to MIT App Inventor Forum
Ghica will the baud rate of the BT board affect the results? If i'm using 9600, and i changed it to 57600, will I get different results?

thenewbie

unread,
Jan 26, 2017, 1:16:09 AM1/26/17
to MIT App Inventor Forum
Thanks! I will now try to do your advice. I'll post updates soon.

thenewbie

unread,
Jan 26, 2017, 1:29:00 AM1/26/17
to MIT App Inventor Forum
Ghica the touchup is meant to ensure that the joystick moves back to the center after dragging. I tried disabling it and yeah, the joystick didnt go back to the center after i drag it.

Ghica

unread,
Jan 26, 2017, 4:03:17 AM1/26/17
to MIT App Inventor Forum
Joystick: fine, but do you need to send these values to the BT device too?
Baudrate: this depends on what your device can handle. And, because you are waiting a second in each loop iteration, it does not make sense.
Which brings me back to App Inventor: thinking about it, yes, you need a clock and you should only send data to your BT device to every clock tick. Also, the time interval should be higher that the delay in you loop on the BT device. Why? Because your device will not be able to keep up with all the messages and choke.
(Do not even think of building a delay in APp Inventor, that will crash your app. Why? Search the forum)
Now, before you are making too many changes:
Make sure the values you send are right and make sure that your device operates in the right way, because I doubt that too. Why? Because as far as I can see in your last .ino snippet you never send anything to the servo.
Cheers, Ghica.

thenewbie

unread,
Jan 26, 2017, 4:43:12 AM1/26/17
to MIT App Inventor Forum
Ghica, my last ino snippet were only meant for me to identify what data i am sending to the BT board. If I can get these data right, then I would use a different ino code for servo control.
I'll attach the ino code i intend to use for servo control and see if it makes sense.
Should i change the delay on the arduino side? will 20mS do? I want to keep it as low as possible so that servo movement wouldn't have any noticeable delays. hehe 
Kudos!
1.jpg

thenewbie

unread,
Jan 26, 2017, 4:44:46 AM1/26/17
to MIT App Inventor Forum
i still have to change the min and max value for the mapping

Kudos!

Ghica

unread,
Jan 26, 2017, 5:20:03 AM1/26/17
to MIT App Inventor Forum
Do you think that the servo will be able to react that fast? Start with a slow value, make it work and then try to make it faster.
Also, if you change too many things at the same time, you have no clue whether you introduced or solved the next bug.
Cheers, Ghica.

thenewbie

unread,
Jan 26, 2017, 8:31:09 AM1/26/17
to MIT App Inventor Forum
I will do that. Ghica what will happen if a send a 1 byte value using the .Send2ByteNumber? should the result remain the same? in my case it's not the same.

thenewbie

unread,
Jan 26, 2017, 8:49:55 AM1/26/17
to MIT App Inventor Forum
Ghica I have further questions.

1. I read somewhere (i forgot what particular site that was)  that using SoftwareSerial library with Servo library won't go well. Is that true?
2. Since I am only sending values to the HC-05, I don't need to use the Rx pin of the BT module, do I?

Ghica

unread,
Jan 26, 2017, 1:29:53 PM1/26/17
to MIT App Inventor Forum
Send1byte: probably not the same, as you found out (I never tried)
1. I do not know
2. I do not know.

What I do know is that I have a Sparki robot, that probably has its own libraries. I send only strings to it (via HC-05). I find that much easier than worrying about how long my bytes should be. And all my apps work really fine.
Cheers, Ghica.

thenewbie

unread,
Jan 26, 2017, 7:47:05 PM1/26/17
to MIT App Inventor Forum
using .Send2ByteNumber should have no effect if you're trying to send 1 byte values. About your Sparki robot, you have videos about it? 

Ghica

unread,
Jan 27, 2017, 7:18:34 AM1/27/17
to MIT App Inventor Forum
If you think that it is a bug, then please prepare a small example that shows it. Then someone can fix it.

I only have a small video that shows controlling the Sparki, but it has more to do with the little BLE board controlling it.
But I do have a tutorial about the software I wrote, both the App Inventor app and the .ino file. Go here: http://www.squaringthecircles.com/ai2/
And click on the Sparki picture. Links to the software and tutorial whill show up.
Cheers, Ghica.

thenewbie

unread,
Jan 28, 2017, 3:18:13 AM1/28/17
to MIT App Inventor Forum
Ghica. I am now finally able to control the servo with the apk. The problem is, I can only do panning. Check out my aia and ino codes.
Joystick BT.aia
panning.ino

Ghica

unread,
Jan 28, 2017, 10:59:06 AM1/28/17
to MIT App Inventor Forum
Looking at your .aia, you did not follow any of my advice, therefore, what is the use of giving it?
Looking at your .ino, you are requiring two characters to be available, but you read only one?
Did you try to use the Serial terminal to check out if your Arduino does what you expect it to do??
Cheers, Ghica.

Ghica

unread,
Jan 28, 2017, 11:00:33 AM1/28/17
to MIT App Inventor Forum
And, what is panning and what else should your servo do?
What are its commands to do so?
Cheers, Ghica.

thenewbie

unread,
Jan 29, 2017, 1:58:33 AM1/29/17
to MIT App Inventor Forum
the app is working now! :) 

Ghica

unread,
Jan 29, 2017, 5:14:41 AM1/29/17
to MIT App Inventor Forum
Fine. Can you tell us what the trick was to get it working?
This may help other in the future.
Cheers, Ghica
Reply all
Reply to author
Forward
0 new messages