Ayuda por favor Error con arduino y bluetooth

Hola estoy tratando de enviar dos datos de dos sensores desde un arduino a un teléfono por bluetooth pero me da el siguiente error alguien me puede decir como solucionarlo por favor para que no me muestre ese error en el teléfono.

Hi, I'm trying to send two data from two sensors from an arduino to a phone via bluetooth, but it gives me the following error: Can someone please tell me how to fix it so that it doesn't show me that error on the phone.

Test the received data number of items is as required before making a List from it.
Things to improve:

  1. Use numberOfBytes "-1" For Example:

  2. Ensure the period of time between data sends is sensible - it should be as slow as can be accepted. The Arduino Sketch Loop Time should be at least 20% longer than the App Timer.

  3. DataSetDelimiter

1 Like

Gracias ChrisWard segui tu consejo y se soluciono el problema pero ahora me surge un nuevo el cual es que la actualizacion de los datos es muy lenta tarda varios segundos en actualizarse en la aplicacion del telefono, adjunto mi codigo de arduino y la aplicacion para mas detalles.
si me puedes ayudar a que los datos se actualizaran cada segundo o cada 800 milisegundos te lo agradeceria.

No soy muy experto en el desarrollo de aplicaciones en appinventor pero si tengo conocimiento en programacion.

Gracias


Did you set the AI2 BlueTooth Client Delimiter to 10?

BlockquoteThanks ChrisWard I followed your advice and the problem was solved but now a new one arises which is that the update of the data is very slow it takes several seconds to update in the phone application, I attach my arduino code and the application for more details .
If you can help me to update the data every second or every 800 milliseconds, I would appreciate it.

I am not very expert in developing applications in appinventor but I do have programming knowledge.

Hello Zhacker

Nothing terribly wrong with your Ardunio Sketch, but it needs a little more control and 'Delay()' should not be used since everything is stopped.

Sketch

  1. Before sprintf, test that both variables are holding values.
  2. You are using doubles but bot limiting the decimal places, so the data packet size varies unnecessarily.
  3. There can be a difference between practice and theory.. In theory, you can send your values 'in one go' via Serial.println(), but in practice it's more reliable to send the end-of-line separately. Sprintf makes the code neat, but it appends a null character that is unwanted in your case.

App
The App process time must be faster than the Arduino send time, otherwise it will not have finished processing a data set before another arrives. It's necessary to first decide how often the data is truly needed.I have seen numerous projects where the timing was in or around 1 second per data set, yet having talked through the project with the developer, once every 10 minutes was more than adequate! Your 800 milliseconds is do-able, but don't do it if it's not necessary. Start with a longer time and tweak-down to target. The App Inventor timer interval needs to be about 20% faster than the Arduino Sending. Now, your data is being displayed immediately in the App - the human eye is uncomfortable watching values change so quickly :slight_smile:
An example Sketch:

//ArduinoToApp.ino 29/10/2019 21:56:22

//Fake data stream to test App

// include the library code:
#include <SoftwareSerial.h>

//vars
unsigned int igUpdateTime;

void setup()
{
Serial.begin(9600);
igUpdateTime = millis();
}

void loop()
{
if(millis() - igUpdateTime > 2000) //Loop approx every 2 seconds
{
igUpdateTime = millis();

                     if (btSerial.connected())
                     {
                               //Bluetooth to App
                               Serial.print("Hello");
                               Serial.print("|");
                               Serial.print("World");
                               Serial.print("|");
                               Serial.println();        //This last line tells App "End of Data" = Ascii LineFeed Char Number 10
                     }
           }

}

I prefer to delimit values with a bar "|" as it's very unlikely to ever appear in the data itself, which can be an issue when using commas ",".

Edit: Limit decimal places:
Serial.print(temperatura,2)
Serial.print(Nivel,2)

ArduinoToApp.txt
|attachment
(1.1 KB)

1 Like

Gracias, eh estado probando códigos y modificando parámetros haste que solucione el problema de la velocidad y el error en la aplicación de el teléfono.
Ya no tengo ninguna falla gracias por la ayuda

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.