Pages: [1]   Go Down
Author Topic: Help...Teensy board PC USB control problem  (Read 1321 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am not sure if there is a more appropriate place to post his so my apologies in advance if this is not the correct place...

I am using a Teensy board which is an arduino variant and has the capability to communicate with a PC's USB COM port
once a sketch is running but  I am having some problems sending commands to it from my PC.

On the Teensy board and using the Arduino IDE, there is a set up in the tools drop down for the COM port serial monitor which  
I am using to view the serial data.

Here is my code:
Code:

int Red = 0;    // control pin for the Red LED
int Green = 1;  // control pin for the Green LED
int cmd;                 //  input command from PC  

  
void setup() {  
  pinMode(Red, OUTPUT);  // Set Red LED pin as an output pin  
  pinMode(Green, OUTPUT);  // Set Green LED pin as an output pin  
  
  Serial.begin(9600);  
 
}  
  
void loop() {  
  // wait for serial input  
  if (Serial.available() > 0) {       // read the incoming byte:  
    cmd = Serial.read();             //Serial.println("cmd read =");   `
    Serial.print(cmd);  
    Serial.println("");                  // prints another carriage return

   // ASCII '<' is 44, ASCII '>' is 46 (comma and period, really)  
 if (cmd == 114) { digitalWrite(Red, HIGH); }   // turn on red led.
 if (cmd == 115) { digitalWrite(Red, LOW); }    // turn off red led
 if (cmd == 103) { digitalWrite(Green, HIGH); }  // turn on green led
 if (cmd == 104) { digitalWrite(Green, LOW); }   // turn off green led  
  }  
}


I can send an r, s, g, or h from the COM 3 Serial monitor which sets my leds on and off as they should per the code
but the next step is to get the PC to communicate these characters to it...

I made a winbatch script that I am using to send these characters out to the Com port 3 and I have these logged in a log file and they
appear to be sent to the serial port without a problem but the teensy board is not seeing these
nor is the Com3 serial monitor.

Why can't the arduino pick up on this data sent to it with the winbatch script?

Is there any other way to test this such as sending a character to the com port from the command line prompt?

thanks in advance for any useful ideas in figuring this thing out...
 

Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 206
Posts: 12849
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


From a command-line, I think this sends "WHATEVER" to the serial port...

 echo WHATEVER > COM3:

I think you can send an entire file like this...

 copy MyFilenameGoesHere.txt COM3:


I know two things about the Teensy and its serial port...

1. The baud rate is irrelevant.  Communications is always at 12 Mbps.

2. It works.  I've been able to communicate in both directions.


Unfortunately, that doesn't help you very much.  WinBatch may need some sort of delay or wait command to ensure the data makes it to the Teensy before WinBatch terminates.
« Last Edit: April 28, 2010, 04:28:08 pm by bcook » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49040
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You don't have the Serial Monitor window open when sending the data to the Arduino from the winbatch script, do you?
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks for the reply-

I have tried it with the serial monitor window open and with it closed and it doesn't change the LEDS in either configuration...
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the reply-

I tried every possible combination of this but was not successful...


From a command-line, I think this sends "WHATEVER" to the serial port...

 echo WHATEVER > COM3:

I think you can send an entire file like this...

 copy MyFilenameGoesHere.txt COM3:


I know two things about the Teensy and its serial port...

1. The baud rate is irrelevant.  Communications is always at 12 Mbps.

2. It works.  I've been able to communicate in both directions.


Unfortunately, that doesn't help you very much.  WinBatch may need some sort of delay or wait command to ensure the data makes it to the Teensy before WinBatch terminates.
Logged

0
Offline Offline
God Member
*****
Karma: 26
Posts: 608
Always making something...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Just a quick followup...

After much investigation, it turned out Winbatch has a bug where it erroneously sends the break signal when opening any serial port.

Teensy uses the break signal as its command to reboot, so every time Winbatch tried to open the port, Teensy would reboot.  Because it's native on-chip USB instead of a USB-serial converter, the port would disappear right as Winbatch was opening it.  The Arduino serial monitor and other terminal emulators would work fine.

On a normal Arduino, DTR from the USB-serial chip reboots the processor.  That obviously isn't an option for Teensy since rebooting means also rebooting the USB stack, so the break signal was used instead.

It also turns out the Mac OS-X USB serial driver has a bug where it can't send the break signal.  You can call tcsendbreak() and OS-X returns a success status code, but nothing is actually transmitted.  So to make OS-X work, reboot upon setting the baud rate to 134 bits/sec was implemented.

In the latest "experimental" 0.9 Teensyduino code, I have switched Windows and Linux support to use 134 baud setting instead of the break signal, and the reset-on-break behavior has been removed.

This should allow Teensy to work with Winbatch, or any other programs that unexpectedly sends the break signal.  Just don't set the baud rate to 134.  On Teensy, the data transfer is always native 12 Mbit/sec with native flow control, no matter what the baud rate setting in software.

« Last Edit: August 20, 2010, 08:34:13 am by pjrc » Logged

Pages: [1]   Go Up
Jump to: