LaurentDelaon
Member
[SOLVED] teesny 3.2 serial and PWM problem not work
Hi ,
I use pwm an serial no problem
but with adding serial1 pwm stop correctly working go to upper limit directly.
same pb with 5 an 6 pin...
code to reproduce :
thanks
regards
Laurent.
Hi ,
I use pwm an serial no problem
but with adding serial1 pwm stop correctly working go to upper limit directly.
same pb with 5 an 6 pin...
code to reproduce :
Code:
//
// try with in monitor tape (x 85 mean servoX go to 90° to 85° in our case)
//x 90
//x 85
//x 95
//then uncomment lines 40 to 43 redo: x 85 ->now this is not working.
//
//
#include <PWMServo.h>
#define axeX_PWM_PIN 22 // same pb in 5 an 6 pin
#define axeY_PWM_PIN 23
PWMServo myservoX,myservoY;
static const uint16_t PeriodeEchantillonnage=500;//en milli_seconde
//
String inputString = ""; // chaine de caractères pour contenir les données
boolean stringComplete = true; // pour savoir si la chaine est complète
float valeurX=90,valeurY=90;
void setup (){
myservoX.attach(axeX_PWM_PIN);
myservoX.write(90);
myservoY.attach(axeY_PWM_PIN);
myservoY.write(90);
//
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// try with in monitor tape
//x 90
//x 85
//x 95
//then uncomment lines 40 to 43 redo x 85 : this is not working.
//Serial1.begin(115200);//serial set
// while (!Serial1) {
// ; // wait for serial rt to connect. Needed for native USB port only
// }
}
void loop () {
elapsedMillis waiting; // "waiting" starts at zero
int t0=waiting;
//recup commandes clavier
if (stringComplete) {
if (inputString != "") {
Serial.print("Data recues:");
Serial.println(inputString);
}
//extrait entete 'x '
if (inputString.startsWith("x ") ) {
byte position=inputString.indexOf(' ');//pos du car espace
inputString.remove(0,position+1);// efface jusque espace
//
String param1;
// extrait par1
if (inputString.length()>0) {
position=inputString.indexOf(' ');
param1 = inputString.substring(0,position + 1);
inputString.remove(0,position+1);
};
//appliquelacommande
Serial.println(param1);
valeurX=param1.toFloat();
};
//
//extrait entete 'y '
if (inputString.startsWith("y ") ) {
byte position=inputString.indexOf(' ');//pos du car espace
inputString.remove(0,position+1);// efface jusque espace
//
String param1;
// extrait par1
if (inputString.length()>0) {
position=inputString.indexOf(' ');
param1 = inputString.substring(0,position + 1);
inputString.remove(0,position+1);
};
//appliquelacommande
Serial.println(param1);
valeurY=param1.toFloat();
};
};
//
inputString = "";
//
//if (sbpa_initialisee==false) { sbpa_initialisation(1); };
//
//sbpa_traitements(PeriodeEchantillonnage);
//
//lexture serial
//
//
//ecriture uart1
Serial1.print("?\n"); // demande
//// lecture
// elapsedMillis timeOut;
// while(stringComplete==false) {
// Serial.println("wait Serial1 ...");delay(2);
// if(timeOut>10) {
// Serial.println("TimeOUT Serial1 ");
// Serial1.clear();
//
// break;
// }
// };
// sortie
//Serial.print("Sortie: ");Serial.println(sbpa_add_sortie);
myservoX.write(valeurX);
myservoY.write(valeurY);
//
while (waiting < PeriodeEchantillonnage) {
//do nothing};
//Serial.println("tic...");
};
}
void serialEvent() {
//Serial.println("deb ev.") ;
while (Serial.available()) {
// récupérer le prochain octet (byte ou char) et l'enlever
char inChar = (char)Serial.read();
// concaténation des octets reçus
inputString += inChar;
// Serial.println(inputString) ;
// caractère de fin pour notre chaine
//digitalWrite(led, LOW);
if (inChar == '\n') {
stringComplete = true;
//Serial.println("fin ev") ;
}
}
};
/*
1 - Réception des données
SerialEvent est déclenchée quand de nouvelles données sont reçues.
Cette routine tourne entre chaque loop(), donc utiliser un
delay la fait aussi attendre.
*/
void serialEvent1() { //serial1
//Serial.println("deb ev.") ;
elapsedMillis timeOut;
while (Serial1.available()) {
// récupérer le prochain octet (byte ou char) et l'enlever
char inChar = Serial1.read();
inputString += inChar;
// Serial2.println(inChar) ;
if(timeOut>10) {
Serial.println("TimeOUT interruption Serial1");
Serial1.clear();
break;
}
// caractère de fin pour notre chaine
if (inChar == '\n') {
stringComplete = true;
// Serial2.print("Dans interrution.");//
// Serial2.println(inputString) ;
//Serial.println("fin ev") ;
};
};
}; //serialEvent1()
thanks
regards
Laurent.
Last edited: