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

Thread: Serial USB communication weird boxes

  1. #1
    Junior Member
    Join Date
    Dec 2017
    Posts
    12

    Serial USB communication weird boxes

    Okay so I am attempting to run AcellStepper on my teensy 3.5 so that I can get higher speeds with increasing microstepping.
    Code:
    const int stepsPerRevolution = 200*16;  // change this to fit the number of steps per revolution
    #include <AccelStepper.h>
    // Define a stepper and the pins it will use
    AccelStepper stepper(AccelStepper::DRIVER, 9, 8);
    
    //number of steps to each position from 0
    //long pos1 = 11810L*8;
    //long maxspeed = 3937L*8;
    //long accel = 4000L*8;
    
    long pos1 = 23620;
    long maxspeed = 7874;
    long accel = 8000;
    
    
    int pos2 = 0;
    int pos3 = 9600;
    int pos4 = 12800;
    int pos5 = 16000;
    int pos6 = 19200;
    
    void setup() {
      Serial.begin(9600);
      
    }
    
    void loop() {
    stepper.setMaxSpeed(maxspeed);
      stepper.setAcceleration(accel);
    char c;
      if(Serial.available()) {
        
        c = Serial.read();
           
        if (c == '1') {  // position 1
    
    stepper.moveTo(pos1);
          }
         
        
        if (c == '2') {   
    
    stepper.moveTo(pos2);
        }
        if (c == '3'){
    
    stepper.moveTo(pos3);
        }
        if (c == '4'){
    
    stepper.moveTo(pos4);
        }
        if (c == '5'){
    
    stepper.moveTo(pos5);
        }
        if (c == '6'){
    
    stepper.moveTo(pos6);
        
       }
     
      }
    
    stepper.run();
      
    }
    In short if I send "1" into the serial my motor should move x amount of steps.
    I am running into a problem whenever I try to send serial commands, after I send a command into the serial it waits a few seconds and spits out a few boxes. There shouldn't be any serial prints just reads so I am confused why it does this. Any thoughts?
    Click image for larger version. 

Name:	Capture.JPG 
Views:	25 
Size:	65.4 KB 
ID:	12291

  2. #2
    Junior Member
    Join Date
    Dec 2017
    Posts
    12
    To clarify I have been able to run this code on an arduino with no error, the command is sent correctly without anything being printed into the terminal.

    If I run just a print to serial:
    Code:
    void setup() {
      Serial.begin(9600);
      while(!Serial);
    }
    
    void loop() {
    Serial.print("hi");
    delay(1000);  
    }
    Nothing posts on the terminal.
    I also frequently have an issue where I have to manually hit the "programming mode" button on the teensy. This seems to be a hit or miss thing though, other times I can just upload from the computer and it automatically enters programming mode. I am not sure if this is indicative of something.
    Last edited by tyscof; 12-15-2017 at 08:47 PM.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    17,022
    I'm running it here on a Teensy 3.5. This is what I see...

    Click image for larger version. 

Name:	sc.png 
Views:	24 
Size:	82.0 KB 
ID:	12348

  4. #4
    Junior Member
    Join Date
    Dec 2017
    Posts
    12
    Quote Originally Posted by PaulStoffregen View Post
    I'm running it here on a Teensy 3.5. This is what I see...

    Click image for larger version. 

Name:	sc.png 
Views:	24 
Size:	82.0 KB 
ID:	12348
    Lol that looks right, then there must be something wrong with Teensy - computer connection.

    Any thoughts on why I am able to upload to the Teensy sometimes and not others? Most of the time I have to do the manual switch to programming mode. I am assuming that the culprit has to be related to this issue.

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    17,022
    Are you using another program other than Arduino to talk to the COM port? And using Windows 7 or 8 or XP.

  6. #6
    Junior Member
    Join Date
    Dec 2017
    Posts
    12
    Quote Originally Posted by PaulStoffregen View Post
    Are you using another program other than Arduino to talk to the COM port? And using Windows 7 or 8 or XP.
    Just arduino software and win 7

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    17,022
    The Arduino IDE automatically closes the serial monitor before upload, so you shouldn't be impacted by the Windows 7 USBSER.SYS surprise removal bug. Still, maybe try without the serial monitor window (restart Arduino without ever opening it) and try several uploads to see if that makes any difference.

    Of course there's the obvious hardware stuff, like swapping out any USB hubs & cables that are between your PC and the Teensy.

  8. #8
    Junior Member
    Join Date
    Dec 2017
    Posts
    12
    Quote Originally Posted by PaulStoffregen View Post
    The Arduino IDE automatically closes the serial monitor before upload, so you shouldn't be impacted by the Windows 7 USBSER.SYS surprise removal bug. Still, maybe try without the serial monitor window (restart Arduino without ever opening it) and try several uploads to see if that makes any difference.

    Of course there's the obvious hardware stuff, like swapping out any USB hubs & cables that are between your PC and the Teensy.
    Greetings I hope everyone had a great Holiday,

    So I have tried closing the serial monitor window on start up and all the variants of that (leaving open, baud rate, ect). So now I am pretty sure there is some issue the teensy is having with the communication. Currently when I upload a sketch it will never auto set to programming I always have to manual press the teensy button, previously it would work on and off (finicky). Do you think there is some hardware problem or just something going on with usb issues? I am going to try it in another computer now and see if the problem is still there.

  9. #9
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    17,022
    Quote Originally Posted by tyscof View Post
    Do you think there is some hardware problem or just something going on with usb issues?
    I don't want to say "impossible", but USB problems almost always result in the whole device not working at all. In Windows, the result is usually "Code 10" or "Code 43" in the device manager, showing the device has malfunctioned.

    The USB protocol has CRC checks on all packets, and redundant bits on the tokens. The control transactions which are used for detecting which device has connected to your PC (a process called "enumeration" in USB lingo) have extra CRC checking. Most USB host controllers will try to automatically send a packet 3 times, if errors are detected. All this checking done in the lowest levels of the USB protocol and implemented directly in the hardware allows USB to work flawlessly (but not at max speed) in the presence a small number of errors. When there are a large number of errors, USB generally does not work at all. The case that pretty much never happens is actual errors in the data delivered to software (expect for isochronous protocol, but that's not a factor here... USB serial uses bulk protocol).

    Corrupted data actually seen in the serial monitor is almost certainly something else.

    Are you *really* sure COM4 is the port for your Teensy? Those sorts of squares usually mean non-ascii data, which is the common result when you connect to some other device that actually is hardware serial using a mismatched baud rate.

Posting Permissions

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