Teensy 3.2 not receiving RX data

Status
Not open for further replies.
I wrote a sketch to receive serial data, parse it and send then send control signals to a stepper.

The data is 12 pairs of numbers, steps and delay, comma separated and each group enclosed in "<>".
It receive

It worked perfect on the Uno.

With the teensy I had to apply 3.3 volts to bottom 3.3V pin by the button to get it to work

When I enter data from the keyboard it works fine and operates properly.

It is not showing the received RX data on the serial monitor nor sending any signals to the setepper when data is sent to RX TX pins

What am I doing wrong?


I noticed on the Serial example that #define HWSERIAL Serial1 ws used. I thought this was to create a virtual port.

Does the teensy default to serial port 1 like the UNO?

Do I need to enable TX RX pins 0,1 to receive data?


Attached is the code.

Why did I have to apply 3.3 v to the bottom 3.3V pin when I have 3.6 volts to Vin?

Thank you in advance
 

Attachments

  • Teensy_Rcv_Move.ino
    3.8 KB · Views: 148
On the UNO the USB serial data and the USART are on the same pins 0,1...

The Teensy 3.2 is more similar to lets say an Arduino Leonardo, that is the USB Serial is done by hardware of the main processor and is different than the Usarts.

So on the Teensy 3.2, the Serial object corresponds to the USB input and output.
Serial1 is the first Usart and when you do a Serial1.begin(...), by default it will use pins 0 and 1 for the IO pins.
And the Teensy 3.2 has two additional USARTS. Serial2 by default uses pins 9 and 10 and Serial3 uses pins 7 and 8.
 
On Arduino, Serial maps to Hardware Serial on Pins 0 and 1 AND in parallel to USB Serial.

On Teensy, these are distinct: "Serial" is ONLY USB and thus a virtual port. If you want to use the serial port on pins 0 and 1, it's "Serial1", a true hardware port.

Thus, in void recvWithStartEndMarkers() replace all Serial by Serial1, then in setup(), change Serial.begin(500000) to Serial.begin(57600) for the Serial monitor of the Arduino IDE and add Serial1.begin(500000) to activate the hardware serial port on pins 0 and 1. In the loop() change while (Serial.available() > 0) { to while (Serial1.available() > 0) {

This will allow you to control the stepper via Serial1 on pins 0 and 1 but it will not longer allow to send commands over USB serial since these are distinct (see above). In order to accept commands from both, you'd have to extend your code.
 
It works fine as long as the USB is connected and TX RX . Serial1 is receiving data fine. When I unplug the USB even though I have power nothing happens

I also noticed the teensy board was very hot with only 5 volts to Vin
 
Last edited:
I see at least 3 problems here.

1: As already mentioned, you need to use Serial1 if you want to receive data on pin 0 (RX1). On Teensy, "Serial" is only for USB and "Serial1" is used for RX1/TX1.

2: The beginning of your setup function has this:

Code:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

Obviously you need to delete this code, if you want Teensy to work without your PC connected.

3: Something is probably *very* wrong with your hardware connection if the Teensy is getting really hot.
 
I did delete all references to Serial and only used Serial1. It works fine with the USB connected but fails to do anything when it is removed. I had 5v to Vin and 3.3 V to the 3.3V pin. Ground to ground, TX and RX pins 0 and 1, then the 3 pins for output.

If it is connected to power, I am not sure why it fails to run.

I bought 12 of these for a project and now regret it. I was considering size. I should have stuck with UNOs as they work flawlessly.

Anyone want 12 teensy 3.2 modules. (From PJRC, 10 still unopened) I'll let them go cheap!
 
It works fine with the USB connected but fails to do anything when it is removed.

You almost certainly have another mistake somewhere, but nobody can help if you don't show us the actual code. The only code we can see is the program you originally shared, before it had Serial1 anywhere.

How you've wired things may also matter, especially if the board is getting hot. Again, noone can help if you keep us in the dark, if you don't show what you've actually done.
 
You almost certainly have another mistake somewhere, but nobody can help if you don't show us the actual code.

Here is the schematic. Very simple. With the USB disconnected it does not work. Without the 3.3vdc it does not send step signals

teensy_bb copy.jpg

Here is the code:


/*

Reads a serial input string until it sees a newline.
Parses the string to get the correct data, then converts the string
to number and moves stepper the number of steps


created 02 Jan 2018
by Mark Noll

*/

// settings for max speed
// will vary according to dist traveled
#define STEP_PIN 23
#define DIRECTION_PIN 22
#define DONE_PIN 21

const byte numChars = 250;
const int nMotor = 12; //which motor (data segment to read)

int nSteps;
int nDelay;

// variables to hold the parsed data

boolean newData = false;
char receivedChars[numChars];
char tempChars[numChars]; // temporary array for use when parsing

//============

void recvWithStartEndMarkers() {
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';

char rc;

while (Serial1.available() > 0 && newData == false) {
rc = Serial1.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 data into its parts

char * strtokIndx; // this is used by strtok() as an index

strtokIndx = strtok(tempChars, ","); // get the first part - the string
nSteps = atoi(strtokIndx); // convert this part to an integer

strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
nDelay = atoi(strtokIndx); // convert this part to an integer


for (int i = 2; i <= 12 ; i++) {

strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
if (i == nMotor) {
nSteps = atoi(strtokIndx); // convert this part to an integer
}
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
if (i == nMotor) {
nDelay = atoi(strtokIndx); // convert this part to an integer
}
}

}

//============


void setup() {
pinMode(DIRECTION_PIN, OUTPUT);
pinMode(STEP_PIN, OUTPUT);
pinMode(DONE_PIN, OUTPUT);



// Open serial communications and wait for port to open:
Serial1.begin(500000);

while (!Serial1) {
; // wait for serial port to connect. Needed for native USB port only
}

}

void loop() {
int y;

// Read serial input:

while (Serial1.available() > 0) {
digitalWrite(DONE_PIN, LOW);
// get the data
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();
//showParsedData();
newData = false;

// moving so set pin HIGH
digitalWrite(DONE_PIN, HIGH);
// send signal to servo

// dertermine direction
if (nSteps <= 0) {
digitalWrite(DIRECTION_PIN, HIGH);
}
else if (nSteps > 0) {
digitalWrite(DIRECTION_PIN, LOW);
}
// get number of steps
y = abs(nSteps);
//set coordiated delay so all moves take same time, 1 frame


for (int i = 1; i <= y; i++)
{
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(nDelay);
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(nDelay);
}


// done moving so set pin LOW
digitalWrite(DONE_PIN, LOW);


//delay(60);
}


}
}
 
Last edited:
What do you think should happen when the following code is executed without USB (and USB Serial) connected?

Code:
// Open serial communications and wait for port to open:
Serial.begin(500000);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}

Put a timeout in the "while (!Serial) wait loop for when you're running without an USB connection.
 
What do you think should happen when the following code is executed without USB (and USB Serial) connected?

The edited file is Serial1.begin(500000);
while (!Serial1) {
; // wait for serial port to connect. Needed for native USB port only
}

the input to RX is the TX output from an Arduino Mega2560

I thought that once a connection was made it would detect it and then go to the loop and wait for data as it did with the USB connected.

This works fine as it is, WITH the USB connected (even with no call to Serial, just Serial1) and receiving data from RX pin. Once I remove the USB it does nothing.
 
So you edited the posted code after I pointed out the endless loop on "while (!Serial) ????

Okay, I guess I can't help here.
 
This works fine as it is, WITH the USB connected (even with no call to Serial, just Serial1) and receiving data from RX pin. Once I remove the USB it does nothing.

Obviously something is wrong. I don't see anything really wrong in your code, but that doesn't necessarily mean there isn't some subtle issue.

The very first thing to try is adding a non-delay LED blink to your program. Here's a complete copy of your program, with a LED blink added at the end of loop().

Code:
/*

  Reads a serial input string until it sees a newline.
  Parses the string to get the correct data, then converts the string
  to number and moves stepper the number of steps


  created 02 Jan 2018
  by Mark Noll

*/

// settings for max speed
// will vary according to dist traveled
#define STEP_PIN 23
#define DIRECTION_PIN 22
#define DONE_PIN 21

const byte numChars = 250;
const int nMotor = 12; //which motor (data segment to read)

int nSteps;
int nDelay;

// variables to hold the parsed data

boolean newData = false;
char receivedChars[numChars];
char tempChars[numChars]; // temporary array for use when parsing

//============

void recvWithStartEndMarkers() {
  static boolean recvInProgress = false;
  static byte ndx = 0;
  char startMarker = '<';
  char endMarker = '>';

  char rc;

  while (Serial1.available() > 0 && newData == false) {
    rc = Serial1.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 data into its parts

  char * strtokIndx; // this is used by strtok() as an index

  strtokIndx = strtok(tempChars, ","); // get the first part - the string
  nSteps = atoi(strtokIndx); // convert this part to an integer

  strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
  nDelay = atoi(strtokIndx); // convert this part to an integer


  for (int i = 2; i <= 12 ; i++) {

    strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
    if (i == nMotor) {
      nSteps = atoi(strtokIndx); // convert this part to an integer
    }
    strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
    if (i == nMotor) {
      nDelay = atoi(strtokIndx); // convert this part to an integer
    }
  }

}

//============


void setup() {
  pinMode(DIRECTION_PIN, OUTPUT);
  pinMode(STEP_PIN, OUTPUT);
  pinMode(DONE_PIN, OUTPUT);

  // Open serial communications and wait for port to open:
  Serial1.begin(500000);

  while (!Serial1) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
}


void loop() {
  int y;

  // Read serial input:

  while (Serial1.available() > 0) {
    digitalWrite(DONE_PIN, LOW);
    // get the data
    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();
      //showParsedData();
      newData = false;

      // moving so set pin HIGH
      digitalWrite(DONE_PIN, HIGH);
      // send signal to servo

      // dertermine direction
      if (nSteps <= 0) {
        digitalWrite(DIRECTION_PIN, HIGH);
      }
      else if (nSteps > 0) {
        digitalWrite(DIRECTION_PIN, LOW);
      }
      // get number of steps
      y = abs(nSteps);
      //set coordiated delay so all moves take same time, 1 frame

      for (int i = 1; i <= y; i++)
      {
        digitalWrite(STEP_PIN, HIGH);
        delayMicroseconds(nDelay);
        digitalWrite(STEP_PIN, LOW);
        delayMicroseconds(nDelay);
      }

      // done moving so set pin LOW
      digitalWrite(DONE_PIN, LOW);

      //delay(60);
    }
  }

  // blink the LED, to tell if the program is running
  static elapsedMillis msec;
  static int ledstate=LOW;
  if (msec > 500) {
    msec = 0;
    pinMode(13, HIGH);
    digitalWrite(13, ledstate);
    ledstate = (ledstate == LOW) ? HIGH : LOW;
  }
}

As I quick sanity check, I ran this complete code here on a Teensy 3.2. The LED blinks.

Then I unplugged the USB and used 3.3V power to run the Teensy 3.2. It is blinking, right here on my desk.

DSC_0970_web.jpg

Start with this code, to at least see if Teensy 3.2 is even running your program at all when not powered by the USB cable.

If it is, perhaps move the LED digitalWrite into the if check for Serial1 data available, so the LED lights when *any* by is received on the RX1 pin.

I'm pretty sure if you do these simple troubleshooting steps, you'll probably find out something isn't getting power (or perhaps the ground wire) or running the way it should be when the cable isn't connected.
 
Obviously something is wrong. I don't see anything really wrong in your code, but that doesn't necessarily mean there isn't some subtle ...

I edited the code a bit to add Serial so I could see if the data is being received and it is. It is just not sending sending the signals to the driver

Code:
/*

  Reads a serial input string until it sees a newline.
  Parses the string to get the correct data, then converts the string
  to number and moves stepper the number of steps


  created 02 Jan 2018
  by Mark Noll

*/

// settings for max speed
// will vary according to dist traveled
#define STEP_PIN 23
#define DIRECTION_PIN 22
#define DONE_PIN 21

const byte numChars = 250;
const int nMotor = 12; //which motor (data segment to read)

int nSteps;
int nDelay;

// variables to hold the parsed data

boolean newData = false;
char receivedChars[numChars];
char tempChars[numChars]; // temporary array for use when parsing

//============

void recvWithStartEndMarkers() {
  static boolean recvInProgress = false;
  static byte ndx = 0;
  char startMarker = '<';
  char endMarker = '>';

  char rc;

  while (Serial1.available() > 0 && newData == false) {
    rc = Serial1.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 data into its parts

  char * strtokIndx; // this is used by strtok() as an index
 Serial.println(tempChars);
  strtokIndx = strtok(tempChars, ","); // get the first part - the string
  nSteps = atoi(strtokIndx); // convert this part to an integer

  strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
  nDelay = atoi(strtokIndx); // convert this part to an integer


  for (int i = 2; i <= 12 ; i++) {

    strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
    if (i == nMotor) {
      nSteps = atoi(strtokIndx); // convert this part to an integer
    }
    strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
    if (i == nMotor) {
      nDelay = atoi(strtokIndx); // convert this part to an integer
    }
  }

}

//============


void setup() {
  pinMode(DIRECTION_PIN, OUTPUT);
  pinMode(STEP_PIN, OUTPUT);
  pinMode(DONE_PIN, OUTPUT);


// Open serial communications and wait for port to open:
  Serial1.begin(500000);
  while (!Serial1) {
    ; // wait for serial port to connect. Needed for native USB port only
  }



// Open serial communications and wait for port to open:
  Serial.begin(500000);

  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
}


void loop() {
  int y;

  // Read serial input:

  while (Serial1.available() > 0) {
    digitalWrite(DONE_PIN, LOW);
    // get the data
    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();
      //showParsedData();
      newData = false;

      // moving so set pin HIGH
      digitalWrite(DONE_PIN, HIGH);
      // send signal to servo

      // dertermine direction
      if (nSteps <= 0) {
        digitalWrite(DIRECTION_PIN, HIGH);
      }
      else if (nSteps > 0) {
        digitalWrite(DIRECTION_PIN, LOW);
      }
      // get number of steps
      y = abs(nSteps);
      //set coordiated delay so all moves take same time, 1 frame

      for (int i = 1; i <= y; i++)
      {
        digitalWrite(STEP_PIN, HIGH);
        delayMicroseconds(nDelay);
        digitalWrite(STEP_PIN, LOW);
        delayMicroseconds(nDelay);
      }

      // done moving so set pin LOW
      digitalWrite(DONE_PIN, LOW);

      //delay(60);
    }
  }

  
}
 
I checked all the signals and they were working fine. It must be that the voltage out is too low for the Stepper Drivers I am using. DM320Ts
Capture.JPG

at 3.3v it is probably not enough

The Arduino Uno output is 5v so it is enough

When I did get it working and it overheated, I think my voltage in was too high. and enough to drive the stepper driver, but it fried the one board.

Thanks again for all your help

If you know of anyone in need of 12 Teensy 3.2 modules, let me know

Mark
 
"I also noticed the teensy board was very hot with only 5 volts to Vin"

Nope, do not want to touch these units.

And does anyone want my four T3.2s that had 1200Vdc on the USB port? Only happened once...
 
"I also noticed the teensy board was very hot with only 5 volts to Vin"

Nope, do not want to touch these units.

And does anyone want my four T3.2s that had 1200Vdc on the USB port? Only happened once...

Troll much??

One got hot and is in the waste bin. the 10 I am gettin grid of are still unopened and being returned to PJRC. You need a hobby as your need to troll posts and be a douchebag is not working


People like you are the reason I hate forums.

Get a life
 
You need a hobby as your need to troll posts and be a douchebag is not working


People like you are the reason I hate forums.

Get a life

These forums are mainly "users help users" forums, although Paul drops in and helps where and when and as much as he can. "Users" here can be lurkers, apprentices, hobbyists, or professionals. Which makes that some friendly joking or kidding is rather normal social behavior and should IMHO not be penalized by such hard words.
 
It's not often we get someone who asks for help, but obviously has a defeatist attitude and obviously does not want to even try to resolve problems.

That sort of attitude really is frustrating for the people who have tried to help. We generally don't get much bad behavior on this forum. In this case, I believe a little sarcastic humor is pretty natural.

@artistinfla - You might have a better experience on forums if you would earnestly try to follow the help people offer. When you will not share details, when you give the wrong code, when you don't follow instructions, and when you repeatedly blame perfectly good products for what is obviously a mistakes and a lack of effort on your part, of course you're going to be unhappy. The problem isn't this forum, and it isn't the electronics.
 
It's not often we get someone who asks for help, but obviously has a defeatist attitude and obviously does not want to even try to resolve problems.

You actually did help me to find the problem.

You took the time to run m code and offered valuable input

I posted my findings. and I think I thanked you

BJB, whoever that is, attempt at humor, if that is what it was, was lost on me.
 
It's not often we get someone who asks for help, but obviously has a defeatist attitude and obviously does not want to even try to resolve problems.

I just wewnt back and sure enough I did thank you after I found that the 3.3v was not enough to drive the stepper drivers. Your input and guidance made that possssible. I did not blame anyone ot the equipment. I chose the wrong equipment and admitted I must have had too high a voltage that fried the one board.

My only problem was the comment from BJB. I was trying to recoup the investment I had in the brand new boards nad he was souring that by trying to insinuate I burned them all up.

Again, thank you for your help.
Mark
 
I checked all the signals and they were working fine. It must be that the voltage out is too low for the Stepper Drivers I am using. DM320Ts at 3.3v it is probably not enough

The Arduino Uno output is 5v so it is enough

artistinfla,

You might consider using a level shifter to bump your 3.3V signals from the Teensy to 5V.

Two great examples are the 74HVT245 or the SN74VLC8T245.
 
You might consider using a level shifter to bump your 3.3V signals from the Teensy to 5V.

If the stepper driver looks like this:

DM320T.png

then it should work perfectly fine if "OPTO" connects to 5V and Teensy uses pinMode INPUT to turn the signal off, and pinMode OUTPUT and digitialWrite LOW to turn the signal on.

Details matter. That's why it's important to say precisely which hardware is really being used, and how it's actually connected. Usually a photo is needed. A Fritzing drawing that merely labels wires with names isn't necessarily how the wires are really connected, much less any info about what real hardware is actually used.
 
Status
Not open for further replies.
Back
Top