Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Teensy USBtoSerial Question

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    8

    Teensy USBtoSerial Question

    Using a Teensy2 and the USBtoSerial sketch, I am trying to talk to a ProMini. I expect to have the Teensy2 just act as a USB to serial interface after I program it. But it doesn't. Proof of this is when I try to Get Board Info after I have chosen the ProMini in the Arduino environment. The info that comes back is for the Teensy. Further, the port shows up as a Teensy, not just as a USB port (this last may or may not be a problem.) If I try to load Blink to the ProMini, I get a synchronization error from AVRDude.

    Lots of searching has not turned up a solution or any solid clues to a solution.

    What am I doing wrong here? Seems like it should be simple. I don't really have a good idea of what to try.

    Thanks for any help.

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,034
    More familiar with the ARM than AVR Teensy - but that mostly seems as expected. The Teensy2 is the device on USB and will be recognized as such. The program may be exchanging USB and UART Serial data but as connected it is a USB Teensy just running a sketch to the IDE.

    A Teensy_3 can do this to program an ESP8266 using UART Serial - and the IDE only sees the Teensy and just passes data out USB.

    Assuming the ProMini is programmed similarly the Teensy can act as a conduit for the process - but will still be a Teensy to the computer and the IDE

  3. #3
    Member
    Join Date
    Nov 2015
    Location
    Germany
    Posts
    24
    Hello,

    sorry to use/highjack this thread, but another thread about the almost same problem is not needed i think.

    I have a teensy 3.2. I have another device connected to the Serial2.
    Communication is perfekt.
    To update the other device it can be connected to PC with a uart usb interface.
    I want to update the external device through the teensy 3.2 which means: USB->Serial2 forwarding.
    The update will start if i just passthrough all USB(Serial)<-->Serial2 data.

    But in the end the external devices says data-error which means something went wrong by the passthrough.

    What can be my problem?

    I tested a lot of codes, just simple check if Serial available forward to Serial2 and if Serial2 available write to Serial.

    Or this one:

    Code:
    #include <Arduino.h>
    
    /* USB to Serial - Teensy becomes a USB to Serial converter
       http://dorkbotpdx.org/blog/paul/teensy_as_benito_at_57600_baud
       You must select Serial from the "Tools > USB Type" menu
       This example code is in the public domain.
    */
    
    // set this to the hardware serial port you wish to use
    #define HWSERIAL Serial2
    
    unsigned long baud = 115200;
    const int reset_pin = 4;
    const int led_pin = 13;  // 13 = Teensy 3.X & LC
                             // 11 = Teensy 2.0
                             //  6 = Teensy++ 2.0
    void setup()
    {
      pinMode(led_pin, OUTPUT);
      digitalWrite(led_pin, LOW);
      digitalWrite(reset_pin, HIGH);
      pinMode(reset_pin, OUTPUT);
      Serial.begin(baud);	// USB, communication to PC or Mac
      HWSERIAL.begin(baud);	// communication to hardware serial
    
    }
    
    long led_on_time=0;
    byte buffer[80];
    unsigned char prev_dtr = 0;
    
    void loop()
    {
    
      unsigned char dtr;
      int rd, wr, n;
    
      // check if any data has arrived on the USB virtual serial port
      rd = Serial.available();
      if (rd > 0) {
        // check if the hardware serial port is ready to transmit
        wr = HWSERIAL.availableForWrite();
        if (wr > 0) {
          // compute how much data to move, the smallest
          // of rd, wr and the buffer size
          if (rd > wr) rd = wr;
          if (rd > 80) rd = 80;
          // read data from the USB port
          n = Serial.readBytes((char *)buffer, rd);
          // write it to the hardware serial port
          HWSERIAL.write(buffer, n);
          // turn on the LED to indicate activity
          digitalWrite(led_pin, HIGH);
          led_on_time = millis();
        }
      }
    
      // check if any data has arrived on the hardware serial port
      rd = HWSERIAL.available();
      if (rd > 0) {
        // check if the USB virtual serial port is ready to transmit
        wr = Serial.availableForWrite();
        if (wr > 0) {
          // compute how much data to move, the smallest
          // of rd, wr and the buffer size
          if (rd > wr) rd = wr;
          if (rd > 80) rd = 80;
          // read data from the hardware serial port
          n = HWSERIAL.readBytes((char *)buffer, rd);
          // write it to the USB port
          Serial.write(buffer, n);
          // turn on the LED to indicate activity
          digitalWrite(led_pin, HIGH);
          led_on_time = millis();
        }
      }
    
      // check if the USB virtual serial port has raised DTR
      dtr = Serial.dtr();
      if (dtr && !prev_dtr) {
        digitalWrite(reset_pin, LOW);
        delayMicroseconds(250);
        digitalWrite(reset_pin, HIGH);
      }
      prev_dtr = dtr;
    
      // if the LED has been left on without more activity, turn it off
      if (millis() - led_on_time > 3) {
        digitalWrite(led_pin, LOW);
      }
      // check if the USB virtual serial wants a new baud rate
      if (Serial.baud() != baud) {
        baud = Serial.baud();
        if (baud == 57600) {
          // This ugly hack is necessary for talking
          // to the arduino bootloader, which actually
          // communicates at 58824 baud (+2.1% error).
          // Teensyduino will configure the UART for
          // the closest baud rate, which is 57143
          // baud (-0.8% error).  Serial communication
          // can tolerate about 2.5% error, so the
          // combined error is too large.  Simply
          // setting the baud rate to the same as
          // arduino's actual baud rate works.
          HWSERIAL.begin(58824);
        } else {
          HWSERIAL.begin(baud);
        }
      }
    
    }
    The Result is always Data-Error, which means some bytes are not transfered correctly.

    Maybe someone of you experienced programmer has an idea.

    Thanks,
    Thomas

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •