Control external serial device

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Control external serial device
#1
I'd like to control an external serial device using a bpod r2.  It seems that within the Matlab API, one can forward serial commands to the Module outputs.  If I understand correctly, SM->Module communication occurs at a baud rate hard-coded in the bpod firmware (1.3 Mb/s). The device I'd like to control uses a different baud rate (115200).  Is there a way to set the SM->Module baud rate through the API?  Or is it better to modify the firmware?  If I do the latter, will that disrupt communication with existing modules (e.g. the analog output module)?  Or can I control the baud rate for each Module output separately?  Perhaps there is a better way to control an external serial device than by using the module outputs?
Reply
#2
Hi Mike,

The 'Module' channels are single-ended serial (UART), but to provide robustness over the Ethernet cable, they are converted to a differential signal (RS-485) onboard the state machine. Modules at the receiving end need to convert RS-485 back to single-ended UART. For Arduino and Teensy, we provide shields (1, 2) to accomplish this task with a single IC. In both cases, the channel in the Arduino IDE is 'Serial1'. 

One way to solve your problem is to control Teensy 3.2 with the Teensy Shield. Then, write a simple Arduino sketch that reads any incoming bytes from the state machine on Serial1, and writes them to Serial2 (pins 9, 10 on Teensy) or Serial3 (pins 7,8). You can initialize Serial2 and/or Serial3 at any baud rate you need. A sketch for Teensy3.2 similar to the one you need is in the Bpod_Gen2 'Examples' folder, here. It's an 'Echo Module' that sends incoming bytes back to the state machine. In your case, you'd route them to Serial2 instead, and include Serial2.begin(115200); in the setup() funciton. One advantage of this approach is that you may not need to transmit every byte from the state machine - if the serial protocol of the device you're trying to control has more complicated commands, you can make a library of commands in the Teensy and reference them by index. Note that if you have State Machine r2, you won't need a USB cable to power the Teensy once it's programmed - the state machine supplies power over the Ethernet cable if you connect Teensy to module ports 1-3.

I hope this helps!

-Josh
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)