H
H
HelSay2018-12-03 16:12:15
Arduino
HelSay, 2018-12-03 16:12:15

How to communicate between Arduino and Android using App Inventor and Bluetooth HC-06?

Hello, I want to control the robot from my phone using bluetooth. The application is made in App Inventor. How do I send and receive multiple values? App Inventor has a SendBytes function, you need to put a list into it, I create a sheet and put 2 values ​​​​in there, but something is wrong). (the photo still shows all sorts of calculations and so on, it all works as it should). 5c052b5f3cfda017397268.pngAnd here is an arduino program that takes values ​​and displays them on the screen.

byte val[2];
int joyDeg, joyPow;

void setup() {
  Serial.begin(9600);
}

void loop() {
  //Проверяем не пришло ли чего и записываем значения
  
 if (Serial.available() > 0) {
    for (byte i = 0; i < 2; i++) {
      val[i] = Serial.read();
    }
    joyDeg = val[1];
    joyPow = val[0];
 }
 //----------------------------------------------

//Выводим значения в Serial
 if ((millis() % 1000) == 0) {
 Serial.print("Pow: ");
 Serial.println(joyPow);
 Serial.println(joyDeg);
 Serial.println("--------");
 }
 //-----------------------------------------------
}

That's what in Serial'e 5c052ab6946f0119700707.png
1 value comes true, and the 2nd - always 255.
And what if I want to send more values?
Thank you)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kn0ckn0ck, 2018-12-03
@HelSay

Listen, well here a question of data types. Here you do "make a list" and then SendBytes - how do you think it packs this list of some values ​​into a byte vector? The answer is buried here.
Then you read only two bytes always, you think that these are your Pow and Deg. But judging by the cycle, there are some float values, no less. float values ​​how many bytes do they take?
In short, what to do:
1. write a short program that sends understandable values ​​​​of the types that you work with in AppInventor via BT
2. on the Arduino side, throw ALL received bytes into the Serial Monitor and try to understand how AppInventor serializes your values ​​\u200b\u200bin byte vector.
When you understand how this happens, you can write normal code to get exactly your values. Voila!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question