Teensy 4.0 and Dynamixel

Status
Not open for further replies.
how can i do controlling dynamixel AX-18A with the Teensy 4.1 ?
The same ways as you would with a Teensy 4.

There are many ways to do so.
The Dynamixel is a half duplex serial protocol, which specification says the TTL signal is 5v, although I have never had issues with driving it with 3.3v.

However I am not always clear if there are no chance that the DXL may drive the TTL line high to 5v and the T4.x IO pins are not 5v compatible.

As mentioned previously in this thread and others, I have done several different circuits to do this.

When I am living dangerously (or using a T3.2 or 3.5, which are 5v tolerant, I might simply hook up a wire, to the TTL and GND to a MUX, where the TTL connects up to a Hardware UART TX pin and I then handle the half duplex in software. The new beta version of Teensyduino actually has some of the half duplex support built in.

Other times I hook up to TX and RX pin and direction pin like some of the circuits mentioned earlier in this thread. and again use support built into the Hardware Serial class.

And in most all of these cases you need some way to run the servo power to the appropriate wire of the servo(s).

There are different libraries I have used to drive these servos. Like BioloidSerial which is old and came from the old Trossen Robotics Bioloid library but made to handle different setups. I have also used some of the newer Robotis libraries and would suggest going that way.
 
@KurtE - I'm trying to get your BioloidSerial.h to work using Serial3 port instead of Serial1 on the Teensy 4.1. I tried changing to #define PAX12Serial &Serial3 in the dxlSerial.h but the bioloid.setNextPost(id,pos) isn't moving the AX12.
Is there something else I need to change? I'm also setting #define AX_BUS_UART Serial3 in the Arduino sketch. Do I need to change anything in dxlSerial.h? If I use your AX12_Test program the servos work fine on Serial3. I'm using software for the half-duplex comms.
 
As far as I know it should work. The code just figures out which Serial port gets passed in to dxlInit:
void dxlInit(long baud, HardwareSerial* pserial, int direction_pin, int tx_pin, int rx_pin ) {

As the AX12 sketch is setup: dxlInit(DXL_BAUD, (HardwareSerial*)&AX_BUS_UART, SERVO_DIRECTION_PIN);

Also depending on your sketch sometimes I forget that maybe used some IO pins to debug something... So you may want to make sure that the TX pin or Serial3 is not used for something else...

Also one of these days may make a version of the library that uses the now built in Half Duplex support that was added to HardwareSerial class...
 
Source Code and Diagram Please

Awesome.

I played around a bit, but it was really easy. Totally unexpected, everything works absolutely fine. :eek:

I still use the circuit as written in my previous post. Then adapted the SerialPortHandler as you suggested.

Code:
const uint8_t DXL_DIR_PIN = -1; // Do not use dir pin


class NewSerialPortHandler : public DYNAMIXEL::SerialPortHandler
{
  public:
    NewSerialPortHandler(HardwareSerial& port, const int dir_pin = -1)
    : SerialPortHandler(port, dir_pin), port_(port), dir_pin_(dir_pin)
    {}

    virtual size_t write(uint8_t c) override
    {
      size_t ret = 0;
      ret = port_.write(c);
      port_.flush();
      return ret;
    }

    virtual size_t write(uint8_t *buf, size_t len) override
    {
      size_t ret = 0;
      ret = port_.write(buf, len);
      port_.flush();
      return ret;     
    }

  private:
    HardwareSerial& port_;
    const int dir_pin_;
};

Tested it with a XL320 and a 2XL430. And of course, you were right. When I said I didn´t use any other boards I forgot to mention that I in fact use a level shifter to shift the 5V to 3.3V, so Teensy doesn´t take damage. The circuit mentioned is on the 3.3V side of the data line.

So thank you very much KurtE!! Made my life a lot easier ;)

Scooba, I know it's been a while, but I'm trying to do the same thing and could use some help. Could you by chance post your complete code? I'm using a Teensy 4.1 and an XL430-W250-T wired directly (with a level shifter and the same TX/RX circuit as you used). A wiring diagram would also be great, but more importantly is the code. Thanks in advance!!
 
Scooba, I know it's been a while, but I'm trying to do the same thing and could use some help. Could you by chance post your complete code? I'm using a Teensy 4.1 and an XL430-W250-T wired directly (with a level shifter and the same TX/RX circuit as you used). A wiring diagram would also be great, but more importantly is the code. Thanks in advance!!

Sorry, I am not Scooba ;)

But really depending on how you are trying to do the wiring will influence what changes if any needed to run with Dynamixel2Arduino library:.

If you setup a circuit similar to what Robotis uses where you have a direction pin, like one of the last boards I was playing with:
screenshot.jpg

You should be able to just use their Dynamixel2Arduino library passing in which Serial port and which direction pin you are using...

If you are just using a level shifter, you don't need any additional Hardware as the Serial ports internally do support Half duplex mode, which uses the TX pin of the UART.
Simply need to do something like: Serial2.begin(1000000, SERIAL_HALF_DUPLEX);
And it will setup the Serial port to only use the TX pin.

Then the above subclass should work, where it just writes the data out and then does a flush, to make sure all of the data goes out and automatically shift back to RX mode.
 
Thanks Kurt! I'll give it a try.

Since I'm not a coder, if anyone happens to have complete code for running this servo directly to a Teensy (or Arduino board) without any other circuits between them, please share :)
 
Thanks Kurt! I'll give it a try.

Since I'm not a coder, if anyone happens to have complete code for running this servo directly to a Teensy (or Arduino board) without any other circuits between them, please share :)

I have not been playing with this lately, but I usually keep examples of different things for this up in the github project: https://github.com/KurtE/Open_CM_CR_Arduino_Sketches
Note: several of these have setups for teensy...

or I have my own library which I am trying to get away from using: https://github.com/KurtE/BioloidSerial
 
Status
Not open for further replies.
Back
Top