Hi,
I’m having a problem. I can get my arduino UNO R3 to connect via USB. However, when I touch a button on my android phone, the arduino deconnects from my phone and I get this message from the CMD.
Connecting device at COM3 to blynk-cloud.com:8442...
OpenC0C("\\.\COM3", baud=9600, data=8, parity=no, stop=1) - OK
Connect("blynk-cloud.com", "8442") - OK
InOut() START
DSR is OFF
Received EOF
EVENT_CLOSE
InOut() - STOP
Disconnect() - OK
Connect("blynk-cloud.com", "8442") - OK
InOut() START
DSR is OFF
Here is my code. It seems to be my code the issue. I doesn’t disconnect when using exemples.
// Comment this out to disable prints and save space
// #define BLYNK_PRINT SwSerial
#include <SoftwareSerial.h>
SoftwareSerial SwSerial(10, 11); // RX, TX
#include <BlynkSimpleStream.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "token";
BLYNK_WRITE(V1)
{
calibration=param.asInt();
if (calibration==HIGH) {
calibrer();
}
}
BLYNK_WRITE(V2)
{
int bouton = param.asInt(); // assigning incoming value from pin V1 to a variable
//Bouton pour redémarrer le calcul de la moyenne sans reset et passer par la calibration a nouveau
if (bouton==HIGH) {
totalaverage=0;
numaverage=0;
}
}
void calibrer()
{
digitalWrite(ledPin, HIGH);
debutcalib=millis();
// Laisser le capteur à une différence de pression nulle pendant 5 secondes
while ((fincalib-debutcalib) <= temps_calibration) {
i++;
sensorValue = analogRead(sensorPin);
total=total+sensorValue;
fincalib=millis();
}
calibration=total/i;
// signal the end of the calibration period
digitalWrite(ledPin, LOW);
}
void setup()
{
// Debug console
SwSerial.begin(9600);
pinMode(ledPin, OUTPUT);
// Blynk will work through Serial
// Do not read or write this serial manually in your sketch
Serial.begin(9600);
Blynk.begin(Serial, auth);
calibrer();
}
void loop()
{
Blynk.run();
numaverage++;
readIndex=1;
total=0;
debutlecture=micros();
while ((finlecture-debutlecture) <= 1000000) { //Valeurs moyenné au 1 sec pour le serveur blynk
debut=micros();
//Lecture du sensor
sensorValue = analogRead(sensorPin); //Setup le sensor à 0 pression, une valeur de 0. Si delta_pression<0 alors valeur négative
Delta_pression=(sensorValue-calibration)*maxsensor*2000/1024; //, transformation de la valeur analogue en pression Pa
// Serial.print(Delta_pression);
total=total+Delta_pression;
readIndex++;
finlecture=micros();
}
delay(1000);
// Valeur graphique échantillons numReadings
PressionSmooth=total/readIndex;
Blynk.virtualWrite(V6, Delta_pression);
//Valeur moyenne depuis départ
totalaverage=PressionSmooth+totalaverage;
average=totalaverage/numaverage;
Blynk.virtualWrite(V5,average);
//Fréquence d'échantillonage
frequence=1000000/(finlecture-debut); //Calcul de la fréquence d'échantillonage
vitessemax=frequence*60/5; //Vitesse maximale du moteur en RPM pour une belle lecture
Blynk.virtualWrite(V3,frequence); //Pour une lecture facile sur le plot
}
Thanks for the help!