Playstation 2 controller library updated to work on Teensy 3.1

KurtE

Senior Member+
Sorry if this turns out to be a duplicate of other stuff, but thought I would mention.

A high percentage of the Lynxmotion robots sold are sold with a Playstation 2 controllers to control them. The PS2 controllers use a SPI like interface to talk to the controller. If you wish to have more information on how they work, my favorite place for information is: http://store.curiousinventor.com/guides/PS2

When they converted their robots to run on Arduinos, we used the PS2 library that will developed by Bill Porter. Over the last few years, I have made some changes to it, to fix a few issues as well as to get it to first work on Chipkit boards (Pic32), Arduino Due, and:

Today I made some changes to it, to make it work with the Teensy 3.1. I updated my branch of this project up on github:
https://github.com/KurtE/Arduino-PS2X
 
Sorry if this turns out to be a duplicate of other stuff, but thought I would mention.

A high percentage of the Lynxmotion robots sold are sold with a Playstation 2 controllers to control them. The PS2 controllers use a SPI like interface to talk to the controller. If you wish to have more information on how they work, my favorite place for information is: http://store.curiousinventor.com/guides/PS2

When they converted their robots to run on Arduinos, we used the PS2 library that will developed by Bill Porter. Over the last few years, I have made some changes to it, to fix a few issues as well as to get it to first work on Chipkit boards (Pic32), Arduino Due, and:

Today I made some changes to it, to make it work with the Teensy 3.1. I updated my branch of this project up on github:
https://github.com/KurtE/Arduino-PS2X

Thanks for doing this work, I have previously worked with Bill Porter's PS2 library for Arduino's, so having that tool in my Teensy 3.1 toolchest is awesome.
 
This is awesome!! Just the stuff I was looking for. Would this library work on Teensy 4.1 as well? I'm planning to use Teensy 4.1 as follows:

1) Send ROS odometry and IMU data via USB Serial0 to RPi/Jetson Nano running rosmaster

2) Packetized Serial with two Sabertooth 2X12 over Serial 1 (Using Sabertooth.h library)

3) MPU6050 [VCC_3.3v, GND, SCL, SDA] connected to Teensy 4.1 [3.3v, GND, 19, 18]

4) Lynxmotion PS2 V4 controller [clock, command, attention, data, Pressures?, Rumble?] to Teensy 4.1 [13,11,10,12, true, true] and use this library.

5) 4x Motor encoders (with interrupt on both channels so total 8 interrupt pins) on pins that are left after connecting MPU6050, Sabertooths and PS2 controller.

I'm a mechanical engineer and I do not understand the finer details. Would a setup like the above work without any issues? Any advice would be much helpful.

Context: I'm building the base for an Autonomous robot to Implement SLAM. The Teensy 4.1 with 4x motors with encoders, 2x dual Sabertooth, MPU6050, and PS2 controller is basically my base_control layer upon which I intend to stack ROS layer either using Jetson Nano or Raspberry Pi for now and in the future may use Jetson Xavier NX for Reinforcement Learning etc.

Note: Except for PS2 v4 controller, which I have ordered just now, I got the Sabertooth, ROS serial, MPU6050 and the motor encoders working on Arduino Mega. I hope all those Arduino Sketches work on Teensy 4.1 without issues.
 
Last edited:
Hi @AdzTheDemon - as you may have noticed the last comments in this thread were over 7 years ago. Which I have probably not used much since then.

Curious Are we talking Ros or ROS2?

Note: my ROS is really rusty and mostly I learn a little and then off to something else. So take my ROS advice with a grain of salt.

First round was with ROS with a hexapod: https://github.com/KevinOchs/hexapod_ros
Later to try to get back into ros, I purchased a Robotis Turtlebot3, started with their ROS stuff, was converting to their later ROS2 stuff, but have been distracted again from it for a year or two.

Personally I would not recommend using the PS2... It is temperamental and the like.

If it were me, I would probably go with either a PS3 or a PS4 controller. With these you have a couple options on how to use them.
a) You could hook them up to Teensy 4.1 using USB Host port, and our library, which supports several bluetooth dongles and a few different game controllers like PS3 and 4...

b) connect it up to RPI over bluetooth.

But again it may depend on how ROS you want to make it. Example Turtlebot 3 has their own controller built in to their ROS code that runs on their OpenCR board, such that you can control the turtle even when not running the
full ROS stack. Regardless of which way you could also choose to have the Teensy and/or the RPI publish topics associated with the controller.

On side note, if I were building my own base that uses motors, I personally would probably go with Roboclaw controllers over Sabertooth, although I have not played with either in a long time. But Roboclaws have support built int for handling the wheel encoders.

Good luck
 
Back
Top