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

Thread: Sending commands to Tweensy 3.0 through USB

  1. #1
    Member
    Join Date
    Sep 2013
    Location
    Utah
    Posts
    36

    Sending commands to Tweensy 3.0 through USB

    I want to use the Tweensy 3.0 board as a "go between" between a stepper motor controller and a Linux box. This means that I need to send commands to the Tweensy board.
    Can I do this?
    Some embedded devices I've worked with make difficult to do anything but program the flash. Clearly this won't work for me. I would like to make the interface simple to use, like "motor #1: step forward 5 clicks."

  2. #2
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,256

    Cool

    I know you can read/write text through the USB serial monitor (look at Examples -> Teensy -> UART -> EchoBoth). Whether you can do it outside of the IDE, I don't know. I recall there is some special support in the IDE for the serial monitor.

    An alternative approach would be to get cheap bluetooth transceiver for the Teensy. I use a generic HC-05 and it acts as a serial port on either RX2/TX2 (pins 9/10) or RX3/TX3 (pins 7/8), using the Serial2 or Serial3 devices to talk to it. Here is a real simple program I wrote to test the bluetooth connection (I use the standard password, and I have it paired with my Android phone):

    Code:
    const int leds[] = { 13, 12, 11, 10 };
    
    #define NUM_LEDS (sizeof (leds) / sizeof (leds[0]))
    
    void
    setup (void)
    {
      size_t i;
    
      Serial3.begin (9600);
      Serial3.print ("Start\r\n");
      Serial3.flush ();
    
      for (i = 0; i < NUM_LEDS; i++)
        {
          pinMode (leds[i], OUTPUT);
          digitalWrite (leds[i], LOW);
        }
    }
    
    static int number = 0;
    
    void
    loop (void)
    {
      if (Serial3.available ())
        {
          char ch = Serial3.read ();
          if (ch >= 'a' && ch < 'a' + NUM_LEDS)
    	digitalWrite (leds[ ch-'a' ], LOW);
    
          else if (ch >= 'A' && ch < 'A' + NUM_LEDS)
    	digitalWrite (leds[ ch-'A' ], HIGH);
    
          else if (ch == '.')
    	delay (1000);
    
          else if (ch == ',')
    	delay (250);
    
          else if (ch == '0')
    	{
    	  for (size_t i = 0; i < NUM_LEDS; i++)
    	    digitalWrite (leds[i], LOW);
    	}
    
          else if (ch == '*')
    	{
    	  for (size_t i = 0; i < NUM_LEDS; i++)
    	    digitalWrite (leds[i], HIGH);
    	}
    
          number++;
          Serial3.print ("Bluetooth number: ");
          Serial3.print (number);
          Serial3.print (", read: ");
          Serial3.write (ch);
          Serial3.print ("\r\n");
        }
    }
    <edit>
    I just tried it with the laptop using a cheap bluetooth dongle, and once I paired with the device, I was able to use rfcomm to set up /dev/rfcomm0, and then using minicom -D /dev/rfcomm0, I was able to send text to the Teensy and read back what the Teensy wrote.
    Last edited by MichaelMeissner; 09-25-2013 at 06:04 AM.

  3. #3
    Senior Member
    Join Date
    Jan 2013
    Posts
    966
    Of course you can do that. What obstacles you run against is mostly a question of what software and hardware interfaces are between the Teensy and the Linux box. Is this going to be a cabled solution or wireless connection ?
    If it's ca cable/wire interface, which one is it. USB serial, RS232, RS485, I2C etc ?
    If it's wireless, is it WiFi, Bluetooth, Zigbee etc.
    What software do you intend to use on the Linux box to control the Stepper Motor, what protocols does it support ?
    Somewhere in there is a solution that'll work for you :-)
    Etc.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,576
    Like Michael said, you can use USB Serial. That's the most common choice and it works very well. If your program, use Serial.available() to detect if any data has arrived from your computer, and Serial.read() to get it when it's available.

    To send that data, you can use the Arduino Serial Monitor. After Teensy is running your program, you must select the correct serial device (usually /dev/ttyACM0 on Linux) from Tools > Serial Ports. Then open the serial monitor and use it to send data. If your program uses Serial.print(), whatever it sends will be displayed in the serial monitor.

    There are lots of programming examples online for how to send and receive data using serial ports. They work well, but one common caveat is they usually involve the user having to select the correct port, like you do with Arduino's Tools > Serial Ports menu.

    Another more advanced approach is Raw HID, which sends 64 byte packets in both directions. The main advantage is Raw HID can automatically detect your device. It also works within installing any "driver" on Windows, so Raw HID can be worth the extra effort if you're making a product and writing supporting software.

    But normal USB Serial is so very simple and you can easily test it using the Arduino Serial Monitor, so I'd recommend you start there.

  5. #5
    Member
    Join Date
    Sep 2013
    Location
    Utah
    Posts
    36
    Thanks, gents!
    For more information, I'm trying to program the (SainSmart 4-servo controller). It's a pity that the device is no longer available, because everything I've seen thus far has been positive (no, I have not been able to turn a motor). The biggest hassle with the board is that it has a parallel port that is completely incompatible with all parallel ports. Also, most computers no longer have a physical parallel port, and USB parallel ports don't work with it. So I'm going this route.

    Specs/requirements:
    - The board will be connected to a BusyBox Linux embedded telephone with a USB port (sorry, I can't reveal what it is).
    - I plan using a serial connection, but a wifi connection will work too. Zigbee and Bluetooth are unavailable to the embedded telephone.
    - There are 11 input pins (5 [step/direction] pairs and one enable). There are 5 output "limit" pins for indicating where "home" is.
    - I want to send the controller commands that turns an axis clockwise/counter-clockwise or directly "home" without having to worry about the details.
    - The interface board (i.e., Tweensy 3.0) needs to be powered through the USB (how to do so with wifi? I guess a battery...?). The servo controller works with voltages 24-36V.
    - I'm uncertain how Tweensy 3.0 (3.3V) will work with an IEEE 1284 Centronics port which expects ~5V.

    That's as far as I've gotten.

  6. #6
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,256
    If you can switch servo controllers, it might be simpler to use an off the shelf USB servo controller, such as the Pololu Maestro controllers that support between 6 and 24 servos per controller: http://www.pololu.com/catalog/product/1350.

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,576
    Quote Originally Posted by metalgimp View Post
    - I want to send the controller commands that turns an axis clockwise/counter-clockwise or directly "home" without having to worry about the details.
    You probably want to use the AccelStepper library. It's really nice.


    - I'm uncertain how Tweensy 3.0 (3.3V) will work with an IEEE 1284 Centronics port which expects ~5V.
    I'd start with the easy part, which is the 11 outputs from Teensy to the 11 inputs on the controller. Usually 5 volt inputs accept anything over 2 volts as high and anything under 0.8 volts as low, so it's easy to drive them with a Teensy3 signal. Of course, I can't say for certain if that's how this controller works, but it's pretty likely to be that way.

    Actually, I'd just start with the enable and 1 pair of pins for a single motor.

    Once you get that working, then it's time to consider how to connect those home position signals. The best way would be a buffer like a 74HC4050 chip. You'd run that chip from 3.3 volts. It can accept higher voltage signals and output 3.3 volt versions for Teesny3.

    Another option would be simply using 10K resistors in series with each signal. When the signal drives 5 volts, the resistor will limit the current it feeds into the Teensy3 pin.

    But first, I'd go for just connecting the control signals and get some motors moving.

  8. #8
    Member
    Join Date
    Sep 2013
    Location
    Utah
    Posts
    36
    I was dubious (and, admittedly, a little put out, because I was already invested...) until I looked at the site. I'm impressed.
    Q: The 1350 appears to work with analog servos. Is there an equivalent for stepper motors?

  9. #9
    Member
    Join Date
    Sep 2013
    Location
    Utah
    Posts
    36
    Excellent.
    I'll try it out.

  10. #10
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,256
    Quote Originally Posted by metalgimp View Post
    I was dubious (and, admittedly, a little put out, because I was already invested...) until I looked at the site. I'm impressed.
    Q: The 1350 appears to work with analog servos. Is there an equivalent for stepper motors?
    I don't know. I don't own the Maestro, I've just seen it when I go to their site. I was originally interested in the Maestro because it also allowed for more inputs (before I started reading about i2c).

Tags for this Thread

Posting Permissions

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