Hi,
I bought the teensy 3.6 to have better processor speed and now I can control my stepper motor 10 faster.
They are controlled with Processing thanks to Serial.port.
I would like to read on another serial port the Processing data (33 data 30 times per second) but when I do this there is a rumble in my motors and they no longer hold their position.
Stepper motor tremors are less when I set the Serial1.port to 1,000,000 baud.
But with this setting I cannot read the data in the serial monitor. You can read data at 500,000 bauds maximum, but with this setting the motors shake.
With the Arduino Due, I was receiving the data at 115000 baud on the Programming Port and writing the data on the SerialUSB port at 115000 baud and I had no motor shake.
So now, I set the two ports like this:
Serial4.begin (1000000); Serial.begin(1000000); //
Steppers motors don't shake too much but I can't read datas
I put you the program below
Thanks for helping.
I bought the teensy 3.6 to have better processor speed and now I can control my stepper motor 10 faster.
They are controlled with Processing thanks to Serial.port.
I would like to read on another serial port the Processing data (33 data 30 times per second) but when I do this there is a rumble in my motors and they no longer hold their position.
Stepper motor tremors are less when I set the Serial1.port to 1,000,000 baud.
But with this setting I cannot read the data in the serial monitor. You can read data at 500,000 bauds maximum, but with this setting the motors shake.
With the Arduino Due, I was receiving the data at 115000 baud on the Programming Port and writing the data on the SerialUSB port at 115000 baud and I had no motor shake.
So now, I set the two ports like this:
Serial4.begin (1000000); Serial.begin(1000000); //
Steppers motors don't shake too much but I can't read datas
I put you the program below
Thanks for helping.
Code:
#include <AccelStepper.h>
#define SerialUSB Serial4
// Define a stepper and the pins it will use
#define NBMOTEURS 10
#define NBPASPARTOUR 3200 // Set on the driver
#define STEP 1//
// 800--> Mode 1/4 pas MS2 sur ON
// 1600--> Mode 1/8 MS1+ MS2 sur ON
// 3200--> Mode 1/16 MS3 sur ON
// 1600 Arduino Due
// const uint8_t PINDIRECTION[NBMOTEURS] = { 11, 7, 3, 23, 33, 37, 41, 45, 49, 53 };//{ 10, 6, 2, 22, 26};
// const uint8_t PINSPEED[NBMOTEURS]= { 10, 6, 2, 22, 32, 36, 40, 44, 48, 52 }; //{ 11, 7, 3, 23, 27};
// 3200 Teensy
const uint8_t PINDIRECTION[NBMOTEURS] = { 2, 4, 6, 8, 10, 45, 49, 53, 12, 99 };//{ 10, 6, 2, 22, 26};
const uint8_t PINSPEED[NBMOTEURS]= { 3, 5, 7, 9, 11, 44, 48, 52, 13, 98 }; //{ 11, 7, 3, 23, 27};
// Define a stepper and the pins it will use
AccelStepper stepper[ NBMOTEURS] = {
AccelStepper (STEP, PINSPEED[0], PINDIRECTION[0]),
AccelStepper (STEP, PINSPEED[1], PINDIRECTION[1]),
AccelStepper (STEP, PINSPEED[2], PINDIRECTION[2]),
AccelStepper (STEP, PINSPEED[3], PINDIRECTION[3]),
AccelStepper (STEP, PINSPEED[4], PINDIRECTION[4]),
AccelStepper (STEP, PINSPEED[5], PINDIRECTION[5]),
AccelStepper (STEP, PINSPEED[6], PINDIRECTION[6]),
AccelStepper (STEP, PINSPEED[7], PINDIRECTION[7]),
AccelStepper (STEP, PINSPEED[8], PINDIRECTION[8]),
AccelStepper (STEP, PINSPEED[9], PINDIRECTION[9]),
};
// Receive with start- and end-markers combined with parsing
const byte numChars = 200;
char receivedChars[numChars];
char tempChars[numChars]; // temporary array for use when parsing
// variables to hold the parsed data
char messageFromPC[numChars] = {0}; //or 5 doesn't change anything
int integerFromPC0 = 0;
int integerFromPC1 = 0;
int integerFromPC2 = 0;
int integerFromPC3 = 0;
int integerFromPC4 = 0;
int integerFromPC5 = 0;
int integerFromPC6 = 0;
int integerFromPC7 = 0;
int integerFromPC8 = 0;
int integerFromPC9 = 0;
int PC0= 0;
int PC1= 0;
int PC2= 0;
int PC3= 0;
int PC4= 0;
int PC5= 0;
int PC6= 0;
int PC7= 0;
int PC8= 0;
int PC9= 0;
int PCTer0= 0;
int PCTer1= 0;
int PCTer2= 0;
int PCTer3= 0;
int PCTer4= 0;
int PCTer5= 0;
int PCTer6= 0;
int PCTer7= 0;
int PCTer8= 0;
int PCTer9= 0;
int orderTrigger = 0;
int orderCohesion = 0;
int orderCohesionB = 0;
float floatFromPC = 0.0; // not used for the moment
boolean newData = false;
//============
void setup()
{
SerialUSB.begin (1000000); Serial.begin(1000000); //decroche pas, , mais peux pas lire les info.
// SerialUSB.begin (115200); Serial.begin(115200); //ne decroche pas, affiche bien AVEC ARDUINO DUE
//====Test if datas come from the both serial of the Arduino Due or Teensy
Serial4.print ("A "); Serial4.println (-4);
Serial4.print ("B "); Serial4.println (-3);
Serial4.print ("C "); Serial4.println (-2);
Serial4.print ("D "); Serial4.println (-1);
Serial4.print ("E "); Serial4.println (-10);
Serial.print ("A "); Serial.println (4);
Serial.print ("B "); Serial.println (3);
Serial.print ("C "); Serial.println (2);
Serial.print ("D "); Serial.println (1);
Serial.print ("E "); Serial.println (10);
//====Initialise Pin Motor
for(uint8_t i = 0; i < NBMOTEURS; i++) {
pinMode(PINDIRECTION[i], OUTPUT);
digitalWrite(PINDIRECTION[i], OUTPUT);
pinMode(PINSPEED[i], OUTPUT);
digitalWrite(PINSPEED[i], OUTPUT);
/// with 1/16 step == 16*200= 3200 step / round
stepper[i].setMaxSpeed(6400); // sur 1600 ==>step/round 2 tour/s
stepper[i].setAcceleration(2000); // 1 tour/s-2 //
}
PC0=6400; //2 round
PC1=PC2=PC2=PC4=PC5=PC6=PC7=PC8=PC9= PC0;
stepper[9].moveTo(PC0);
stepper[8].moveTo(PC1);
stepper[7].moveTo(PC2);
stepper[6].moveTo(PC3);
stepper[5].moveTo(PC4);
stepper[4].moveTo(PC5);
stepper[3].moveTo(PC6);
stepper[2].moveTo(PC7);
stepper[1].moveTo(PC8);
stepper[0].moveTo(PC9);
}
void loop() {
// recvDataAutre(); // deconne
recvWithStartEndMarkers();
if (newData == true) {
strcpy(tempChars, receivedChars);
// this temporary copy is necessary to protect the original data
// because strtok() used in parseData() replaces the commas with \0
parseData(); // 31 datas marked and separated with a coma.
stepper[9].moveTo(PC0); stepper[8].moveTo(PC1); stepper[7].moveTo(PC2); stepper[6].moveTo(PC3); stepper[5].moveTo(PC4);
stepper[4].moveTo(PC5); stepper[3].moveTo(PC6); stepper[2].moveTo(PC7); stepper[1].moveTo(PC8); stepper[0].moveTo(PC9);
showPosition();
showPhazisScaled();
showTrigBangWithRevolution();
newData = false;
}
stepper[9].run(); stepper[8].run(); stepper[7].run(); stepper[6].run(); stepper[5].run();
stepper[4].run(); stepper[3].run(); stepper[2].run(); stepper[1].run(); stepper[0].run();
}
void recvWithStartEndMarkers() {
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (recvInProgress == true) {
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (rc == startMarker) {
recvInProgress = true;
}
}
}
//============
void parseData() { // split the 31 data into its parts
char * strtokIndx; // this is used by strtok() as an index
strtokIndx = strtok(tempChars,","); // get the first part - the string
integerFromPC0 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
integerFromPC1 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
integerFromPC2 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
integerFromPC3 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
integerFromPC4 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
integerFromPC5 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
integerFromPC6 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
integerFromPC7 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
integerFromPC8 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
integerFromPC9 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
PC0 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
PC1 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
PC2 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
PC3 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
PC4 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
PC5 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
PC6 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
PC7 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
PC8 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
PC9 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
PCTer0 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
PCTer1 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
PCTer2 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
PCTer3 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
PCTer4 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
PCTer5 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
PCTer6 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
PCTer7 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
PCTer8 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
PCTer9 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
orderTrigger = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
orderCohesion = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
orderCohesionB = atoi(strtokIndx); // convert this part to an integer
}
//============
void showPosition() {
Serial4 .print ("K ");Serial4 .println(PC0);
Serial4.print ("K ");Serial4.println(PC0);
Serial4.print ("L ");Serial4.println(PC1);
Serial4.print ("M ");Serial4.println(PC2);
Serial4.print ("N ");Serial4.println(PC3);
Serial4.print ("O ");Serial4.println(PC4);
Serial4.print ("P ");Serial4.println(PC5);
Serial4.print ("Q ");Serial4.println(PC6);
Serial4.print ("R ");Serial4.println(PC7);
Serial4.print ("S ");Serial4.println(PC8);
Serial4.print ("T ");Serial4.println(PC9);
}
void showPhazisScaled() {
Serial4.print ("A "); Serial4.println (integerFromPC0);
Serial4.print ("B "); Serial4.println (integerFromPC1);
Serial4.print ("C "); Serial4.println (integerFromPC2);
Serial4.print ("D "); Serial4.println (integerFromPC3);
Serial4.print ("E "); Serial4.println (integerFromPC4);
Serial4.print ("F "); Serial4.println (integerFromPC5);
Serial4.print ("G "); Serial4.println (integerFromPC6);
Serial4.print ("H "); Serial4.println (integerFromPC7);
Serial4.print ("I "); Serial4.println (integerFromPC8);
Serial4.print ("J "); Serial4.println (integerFromPC9);
}
void showTrigBangWithRevolution() {
Serial4.print ("U ");Serial4.println(PCTer0);
Serial4.print ("V ");Serial4.println(PCTer1);
Serial4.print ("W ");Serial4.println(PCTer2);
Serial4.print ("X ");Serial4.println(PCTer3);
Serial4.print ("Y ");Serial4.println(PCTer4);
Serial4.print ("Z ");Serial4.println(PCTer5);
Serial4.print ("a ");Serial4.println(PCTer6);
Serial4.print ("b ");Serial4.println(PCTer7);
Serial4.print ("c ");Serial4.println(PCTer8);
Serial4.print ("d ");Serial4.println(PCTer9);
Serial4.print ("e ");Serial4.println(orderTrigger);
Serial4.print ("f ");Serial4.println(orderCohesion);
Serial4.print ("g ");Serial4.println(orderCohesionB);
}