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

Thread: CRLF/Enter Command

  1. #1
    Junior Member
    Join Date
    Mar 2021
    Posts
    6

    CRLF/Enter Command

    Hello All. I would like to ask the brain trust here a question concerning the feasibility of a possible fix to a problem I'm
    having with a project. First off, I know basically nothing about the Teensy and program development, and I'm working with proprietary
    software. I have built a Robust Packet modem that after boot up, when it receives valid NMEA GPS data, it transmits a position reports at predetermined
    intervals. The problem I'm having is, it will not start beaconing unless I connect to the Teensy(4.1) with a terminal program, and kick it in the head with a CRLF/Enter command. after that, it functions correctly. Would it be possible to integrate another teensy programmed to provide the main teensy a CRLF/Enter x seconds after power is applied? My goal is to take the computer out of the loop. Thanks in advance.
    Ron

  2. #2
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    4,011
    Many times this is because you have code in Setup that does:

    Code:
    void setup ()
    {
      // wait for things to stabilize
      while (!Serial)
        ;
    
      // other stuff
    }
    Change this code to include a timeout such as:

    Code:
    void setup ()
    {
      // Wait at most 3 seconds for things to stabilize
      while (!Serial && (millis () < 3000)
        ;
    
      // other stuff
    }

  3. #3
    Junior Member
    Join Date
    Mar 2021
    Posts
    6
    Thanks MichaelMeissner for the quick response, but unfortunately, I don't have access to the original code. Wish I did though. Thanks again.
    Ron

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,956
    Quote Originally Posted by Guardrail View Post
    Would it be possible to integrate another teensy programmed to provide the main teensy a CRLF/Enter x seconds after power is applied?
    Yes, this should be possible. You'll need another Teensy with USB host. Teensy 3.6 and 4.1 have USB host on an easy-to-use 5 pins where you can solder pins which mate with this cable.

    https://www.pjrc.com/store/cable_usb_host_t36.html

    Teensy 4.0 also has USB host, but only as 2 tiny pads on the bottom side.

    To accomplish this, you would use the USBHost_t36 library. You'll need to create 1 instead of the serial "bigbuffer" driver, since 480 Mbit/sec communication used by Teensy 4.1 in device mode requires the large buffers.

    Your code in loop() should be fairly simple. You'll just use the boolean test on the driver instance to detect when Teensy has connected to the host port. Then maybe a short delay, open the device and send the 2 bytes, and wait for the boolean test to show when the device is unplugged.

  5. #5
    Junior Member
    Join Date
    Mar 2021
    Posts
    6
    Thanks Paul. Now it looks like I have some work to do. Thanks again.

  6. #6
    Junior Member
    Join Date
    Mar 2021
    Posts
    6
    Before I abandon this project due to lack of knowledge, I figured I'd try one more post. I attempted to follow Paul's advice(within my capability) with the USBHost_t36 library,
    and USB host cable. I compiled the USBHost_t36.H file with the following:
    void loop() {
    // put your main code here, to run repeatedly:

    delay(10000);
    usb_serial_putchar('\r');
    delay(100);
    usb_serial_putchar('\n');
    while (true);
    }
    It sends the desired carriage return and line feed to my terminal program(Putty) via the micro usb port, but no luck on the host cable. I assume its a serial port address issue. I also tried:
    void setup() {
    // put your setup code here, to run once:
    Serial.begin(9600);
    while (!Serial && (millis () < 3000))
    ;

    }

    void loop() {
    // put your main code here, to run repeatedly:
    delay(10000);
    Serial.write(0x0B);
    delay(500);
    Serial.write(0x0A);
    delay(500);
    Serial.write("\r");
    delay(500);
    Serial.write("\n");
    delay(500);
    Serial.write("\015");
    delay(500);
    Serial.write("\012");
    while (true);
    }
    This will send the three carriage returns and line feeds to my terminal program. Assuming that since the one Teensy could send the desired data to my terminal program via the micro usb port, It could send it to the teensy running the modem program via it's Micro usb port. This doesn't work, and I don't know if its a formatting/protocol issue(not emulating Putty's serial protocol), or if its just no possible to communicate via micro usb ports. Thanks

  7. #7
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,568
    It probably won't make a difference but this
    Code:
    Serial.write(0x0B);
    should be
    Code:
    Serial.write(0x0D);
    Pete

  8. #8
    Senior Member
    Join Date
    Jul 2020
    Posts
    900
    0x0B is cntrl-K, aka vertical tab, which is likely to confuse most software I reckon!

  9. #9
    Junior Member
    Join Date
    Mar 2021
    Posts
    6
    Thanks Pete, but I tried those also.

  10. #10
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,568
    I tested usb host serial on a T4.1 connected to a T3.6.
    First, load this receiving program into the T3.6.
    Code:
    // Works on a T3.6 which receives CR/LF from the
    // USB host port on a T4.1
    // The LED blinks to indicate reception of
    // the two characters
    void setup(void)
    {
      Serial.begin(9600);
      while(!Serial && (millis() < 5000));
      pinMode(LED_BUILTIN,OUTPUT);
    }
    
    void loop(void)
    {
      if(Serial.available() >= 1) {
        char c = Serial.read();
        if(c == '\n') {
          digitalWrite(LED_BUILTIN,1);
        }
        if(c == '\r') {
          digitalWrite(LED_BUILTIN,0);
        }
      }
    }
    Then connect the T3.6 to the T4.1 host and load this sending code into the T4.1
    Code:
    // This works on a T4.1 sending CR/LF to a T3.6
    // via the USB host port on the T4.1
    // The LED blinks to indicate transmisison of
    // the two characters
    
    #include <USBHost_t36.h>
    USBHost myusb;
    USBSerial userial(myusb);
    
    void setup(void)
    {
      delay(10000);
      Serial.begin(9600);
      myusb.begin();
      pinMode(LED_BUILTIN, OUTPUT);
    }
    
    void loop(void)
    {
      myusb.Task();
      
      delay(1000);
      digitalWrite(LED_BUILTIN, LOW);
      userial.write('\r');
      
      delay(200);
      digitalWrite(LED_BUILTIN, HIGH);
      userial.write('\n');
    }
    The T4.1 flashes its LED when CR/LF is sent and the T3.6 should flash its LED when it receives CR/LF.

    Pete

  11. #11
    Junior Member
    Join Date
    Mar 2021
    Posts
    6
    Thanks Pete, I’ll give this a try.

Posting Permissions

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