Skip to first unread message

João Hebling

unread,
Nov 21, 2018, 4:03:40 PM11/21/18
to MIT App Inventor Forum
Hi, it's my first aplication with App Inventor. I have some issues with my app, I was developing an app for read humidity and temperature with DHT22 integrated an Arduino and I want to show the data in the app. 
My problem is when I connect to the Bluetooth, the app brake and don't receive the data from Arduino or in some cases receives in half. 
If someone can help, I would be grateful! Sorry my bad english, I prefer don´t use Google Translate because of ba\d translations.
Message has been deleted

João Hebling

unread,
Nov 21, 2018, 4:05:56 PM11/21/18
to MIT App Inventor Forum
DHTtesterbluetooth.ino

João Hebling

unread,
Nov 21, 2018, 4:06:13 PM11/21/18
to MIT App Inventor Forum
App.aia

Abraham Getzler

unread,
Nov 21, 2018, 4:49:17 PM11/21/18
to MIT App Inventor Forum
In your Dados screen, you are using a while loop to check for BlueTooth input.

That is a mistake.

The proper way to do that is to use the Clock, set to repeating
faster than the data is being received.

Set the Clock to repeat, and move the inside of that while loop into a new Clock1.Timer event.

ABG
Dados.png

Abraham Getzler

unread,
Nov 21, 2018, 4:50:12 PM11/21/18
to MIT App Inventor Forum
Also check the blueTooth and Arduino section of FAq
for samples.

ABG

Abraham Getzler

unread,
Nov 21, 2018, 4:51:13 PM11/21/18
to MIT App Inventor Forum
I forgot to add the standard warning about BlueTooth and Screens:

Switching Screens breaks the BlueTooth connection.

ABG

Juan Antonio

unread,
Nov 21, 2018, 5:02:45 PM11/21/18
to MIT App Inventor Forum
Try other baud rate 
Serial.begin(9600);

 delay(10000); it is a long time, try delay(100);

To humidity in AppInventor you send U but in Arduino code is H

João Hebling

unread,
Nov 22, 2018, 8:46:32 AM11/22/18
to MIT App Inventor Forum
Thank you! It's working right! Now just change some visual things...

João Hebling

unread,
Nov 22, 2018, 8:50:41 AM11/22/18
to MIT App Inventor Forum
Thank you! Only realized now that I put the code with some errors, at that time was trying to change the code to try to make the app work and I upload with some errors. The delay time I was because I was trying to fix the errors
Message has been deleted

João Hebling

unread,
Nov 22, 2018, 8:53:08 AM11/22/18
to MIT App Inventor Forum
DHT22Bluetooth.aia

Juan Antonio

unread,
Nov 24, 2018, 6:13:45 AM11/24/18
to mitappinv...@googlegroups.com
This is other example without Clock:

- When Click Button "Obtain Temperature", sends text "T" and gets temperature in Label2.
- When Click Button "Obtain Humidity", sends text "H" and gets humidity in Label3.

bluetooth_humedad2.png

bluetooth_humedad3.png

bluetooth_basico4D.png

// Juan Antonio Villalpando
// kio4.com

#include <Wire.h> 
#include <LiquidCrystal_I2C.h> 
 LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
// LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

#include "DHT.h" 
#define DHTPIN 2 
#define DHTTYPE DHT11 
DHT dht(DHTPIN, DHTTYPE);
char caracter;

void setup() {
lcd.begin(16,2);// Columnas y filas de LCD 
Serial.begin(9600);
dht.begin();
}

void loop(){
float humedad = dht.readHumidity();
float temperatura = dht.readTemperature();
lcd.clear(); // Borra pantalla
lcd.setCursor(0,0); // Inicio del cursor
lcd.print("Temper. = ");
lcd.print(temperatura);
lcd.setCursor(0,1); // Siguiente renglón.
lcd.print("Humedad = ");
lcd.print(humedad);
delay(300); 

// Bluetooth
if(Serial.available()) {
  caracter = Serial.read();

    if(caracter == 'T')
    { 
        int temper = (int) (temperatura);
        Serial.print(temper);
        Serial.print("\n"); // Fin de línea. Importante.
      
    }
    if(caracter == 'H')
    { 
        int humed = (int) (humedad);
        Serial.print(humed);
        Serial.print("\n"); // Fin de línea. Importante.
    }
        caracter == ' ';
    }
}




- Regards,
Juan Antonio Villalpando.

p9B1_bluetooth_humedad.aia
BlueToothClientDesigner.PNG

Ghica

unread,
Nov 24, 2018, 12:44:21 PM11/24/18
to MIT App Inventor Forum
That is a clever solution without a clock!
Something for the FAQ?

Cheers, Ghica

Abraham Getzler

unread,
Nov 24, 2018, 6:12:04 PM11/24/18
to MIT App Inventor Forum
That is a clever solution without a clock!
Something for the FAQ?

Definitely!
 
(added to BlueTooth < 4 and Arduino section of FAQ)
and inserted the critical Designer BlueTooth component Delimiter setting.

ABG
Reply all
Reply to author
Forward
0 new messages