Bluetooth HC-06. Arduino. Send. Receive. Send text file. Multitouch. Image

24.- Press a button continuously and send a character.

In this topic @Povilas_Kasparas, @Taifun and @ABG discuss how to send a character continuously while pressing a button.

char caracter;

 void setup(){  
  Serial.begin(9600);  
 } 
  
 void loop() { 
 if(Serial.available()) {
  caracter = Serial.read();
  Serial.println(caracter);
  }
}
1 Like

Thank you a lot saved me :slight_smile:

25.- Simulation of an arithmia.

p9BC_Bluetooth_ECGi.aia (12.4 KB)

Arduino sends a random level (90...100), with a random delay (400...1600)
appinventor_ECG

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

void loop(){
      int nivel = random(90,100);
      int ritmo = random(400,1600);
      delay(ritmo);
      String mensaje = (String) nivel + "," + (String) ritmo;
      Serial.println(mensaje);
}

App Receives Text (98,977), gets the level (98) and draws it on a Canvas.

For a more realistic process, use the module AD8232

Here in Spanish:
http://kio4.com/appinventor/9BC_bluetooth_corazon.htm

26.- App sends text. readStringUntil. readString.

p9A1_bluetooth_textoi.aia (2.2 KB)

bluetooth_enviartexto1

1.- readStringUntil

char end_char = '\n';
String texto;

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

void loop() { 
  if(Serial.available()) {
    texto = Serial.readStringUntil(end_char);
    Serial.println(texto);
  }
}

ooooooooooooooOOOOOoooooooooooooo

2.- readString

String texto;

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

void loop() { 
  if(Serial.available()) {
    texto = Serial.readString();
    Serial.println(texto);
  }
}

26B.- Example with readString. Return.
[Module Bluetooth in pin 2 and 3 of Arduino]

p9A1_bluetooth_textoi_2.aia (3.0 KB)

#include <SoftwareSerial.h>
SoftwareSerial Bluetooth(2,3);
String texto;

void setup() { 
Serial.begin(9600);
Bluetooth.begin(9600);
Bluetooth.setTimeout(100);
}

void loop() { 
  if(Bluetooth.available()) {
    // texto = Bluetooth.readStringUntil('\n');
    texto = Bluetooth.readString();
    Serial.println(texto);
    Bluetooth.println(texto);
  }
}

27.- App sends two values ​​separated by commas. Arduino adds them up and returns the sum.

p40i_bluetooth_deslizador.aia (3.5 KB)

bluetooth_deslizador12

  • App sends two comma separated values ​​created by two Sliders.

70.3,60.4

  • Arduino receives those values, separates them by comma, and adds them up.
    Using Serial.println(addition) returns the sum

130.70

String texto;
String a ;
String b;
float suma = 0.0;

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

void loop() { 
  if(Serial.available()) {
    // texto = Serial.readString();
    // Serial.println(texto);
    a =  Serial.readStringUntil(',');
    b =  Serial.readStringUntil('\n');
    suma = a.toFloat() + b.toFloat();
   // Serial.println(a);
   // Serial.println(b);
    Serial.println(suma);
  }
} 
1 Like

28. Bluetooth in Screen1 and Screen2.

p9H4i_pantalla_real_BT.aia (8.7 KB)

When we change from Screen1 to Screen2, we lose the Bluetooth connection.
The proper method to avoid this is to use "virtual screens" with VerticalArrangement as we saw in the post: #12

Now let's see how we can go from Screen1 to Screen2 using the disconnection and connection in the new Screen.

To go from one Screen to another, we disconnect the current connection, when we start the visible Screen we reconnect.

I've put a little delay (for each 1 ... 10000) to make the connection easier.

The app is similar to the previous example, two Sliders send two numbers to the Arduino, it adds them and returns the sum to the app.

Screen1

Screen2

Arduino code.

  • The same from the previous post.
1 Like

Excellent collection of tutorials!!
Could you please post how to use textboxes in example 27, instead of using 2 sliders?
For example, how do we enter two decimal numbers in two separate textboxes and that would be sent to the Arduino? But only one or both textboxes can be used at any time to change the corresponding values of the variables in Arduino, with a single "Send" button in app for both textboxes.
Thank you for all your amazing work!

1 Like

29.- Send text from two TextBox.

p9A0i_bluetooth_TextBox2.aia (3.6 KB)

1 Like

Hi, your tutorials are very useful. I was able to finish a lot of projects thanks to this!

Now I'm stuck with my current project. I'm trying to analogRead from my ESP32, send that data via Bluetooth, and graph that signal in mitAppInventor. I need a sample frequency of around 500 samples per second. Is this possible with ESP32?

I checked your real time graph example, but I don't think it meets my time requirements. Maybe I should save the data to a .csv and then graph from there?

Once again, thank you so much for all your tutorials. They are super helpful!

I don't think App Inventor can take that data rate and draw it in real time.

ESP32 works with Bluetooth classic (uses the Bluetooth client component) and BLE (uses the BLE extension).

Try sending a Base 64 image and see how long it takes.


u have used -1 every where in this project what it means

http://ai2.appinventor.mit.edu.ezproxy.canberra.edu.au/reference/components/connectivity.html#BluetoothClient

ReceiveText(numberOfBytes)
Reads a number of bytes from the input stream and converts them to text.
If numberOfBytes is negative, read until a delimiter byte value is read.

In Design. Properties BluetoothClient. DelimiterByte = 10
ASCII 10 is \n, New Line, NL.

In Arduino:
Serial.println("Hello");
ln sends \n
(really \r\n)

So Arduino sends Hello\n
Bluetooth receive Hello\n
\n here means end message because DelimiterByte is 10 and numberOfBytes is -1.

Thank you.
Yeah, I think I'll try to buffer that data in the ESP32, and then send it to the app and make a graph with that.
It definitely can't handle the "real time" part.

Hey Juan, thanks for this potentiometer app. I am trying to modify it such that the Y axis should vary between -90 to 90 and the variable will fluctuate between +ve and -ve along the X-axis. This would be similar to your p91C_grafico_amortiguacion app. But how to do this? I am kinda lost with the complexity of the graphing app. Also, how to add labels to the axes?

I don't know which example of potentiometers you mean, if you mean
9.- A potentiometer in Arduino sends values ​​to the App. Dynamic graph. Shift left.
you can change the value of y, but the value of x is time, you cannot change it between + ve and -ve.
To change the value of y between +90 and -90, change the following label.

if you mean the example:
7.- App gets the value of two potentiometers.
It would not be a dynamic left shift chart, it would be a static chart.

I think it's better if i post this question in a new topic. I would rather avoid cluttering this thread.

Hi, I have posted here too some Tutorials about AppInventor and Arduino, maybe can help you. There are analog and digital values

Have you ever been able to get this to work with apple ISO?

Sorry, in Apple ISO I have not tested it.

I have read somewhere else that Bluetooth is not supported yet in Appinventor :confused