Proceeding the PS4ToPi, PyWakePS4onBT and JoystickUDP homebrew projects today redheadedstep shared some Padawan PlayStation 4 Controller Arduino Sketches adding support for PS4 controls to D-O / R2D2 droids.
Download: padawanps4-master.zip / GIT
From the README.md: Padawan PS4
Padawan PS4 is a set of Arduino Sketches that work to control different droids. Right now, it just has sketches for connecting to the PS4 Controller and controller D-O. D-O is 3D printed from plans from Mr Baddeley.
Setup
This sketch is pulled from the USB Host Shield project. It is a basic sketch that lets you verify that your controller is connected and all the joysticks and buttons are working.
Hardware
You will need the following hardware in your D-O:
Servos
This sketch is used to control D-O.
Install Libraries
Before you start, you need to install some libraries. Open your Arduino IDE and click on Tools -> Manage Libraries. You will want to install the following libraries:
Changes to ServoEasing library
You may need to make some changes to the ServoEasing library depending on your servos.
On line 35, you will want to enable the servo expander (Adafruit PWM):
On lines 207-215, you will want to change the values to match the FS5103R/FS5106R:
Changes to YetAnotherDebouncer Library
You will need to make one small change to this library. It defaults to only sending a boolean value (true/false) because it is made for buttons, but we want it to send an integer value (joystick position). Simply change bool to int on line 16:
Configuration
The sketch is setup assuming that you are using the same servos as specified in the D-O instructions. These servos are:
Test Mode
While testing, you can enable TEST_MODE. This will bypass the controller and send signals directly to the servos. Each servo will run the maximum speed in one direction for 1.5 seconds, then reverse and run the maximum speed in the other direction for 1.5 seconds. Logs are output to the serial console so you can know which servo is being tested.
You can enable TEST_MODE by changing this constant in the file:
Additionally, while you are in TEST_MODE, if you connect the controller, the automatic testing will stop and the controller testing will start. While in controller test mode, any button or joystick you press on the controller will be output to the serial console. The controller will not control the servos.
Controls
The sketch is setup to control D-O using the following controls:
If you need any help, send an email to [email protected] or create an issue on the repository.
Credits
Credit goes to Kristian Lauszus ([email protected]) for creating the PS4 library for the USB Host Shield, Mr Baddeley for the 3-D files for D-O, authors of the various libraries, and you for building a droid!
Finally, following our Holochess (Dejarik) recollection below is a holiday flashback for Star Wars fans who still remember The Star Wars Holiday Special (1978) where Chewbacca and Han Solo aim to celebrate Life Day on the Wookiee's homeworld of Kashyyyk with Chewbacca's family including Mallatobuck (Malla), Attichitcuk (Itchy), and Lumpawarrump or Lumpawaroo (Lumpy) despite running into an Imperial blockade... let the party begin!
Star Wars: The Rise of Skywalker Final Trailer
STAR WARS Battlefront II: The Rise of Skywalker Official PS4 Trailer
Download: padawanps4-master.zip / GIT
From the README.md: Padawan PS4
Padawan PS4 is a set of Arduino Sketches that work to control different droids. Right now, it just has sketches for connecting to the PS4 Controller and controller D-O. D-O is 3D printed from plans from Mr Baddeley.
Setup
- Load the sketch onto your arduino
- Plug the Bluetooth USB into the USB Host Shield.
- Pair your PS4 controller to the bluetooth by holding down Share + PS Button. The light on the controller should blink rapidly as it is pairing, then go solid blue.
This sketch is pulled from the USB Host Shield project. It is a basic sketch that lets you verify that your controller is connected and all the joysticks and buttons are working.
Hardware
You will need the following hardware in your D-O:
Servos
- (2) FS5103R or FS5106R - Continuous Rotation Servos for the wheels
- (2) MG90S or SG90S - 180° Servos for the neck
- (2) MG99R - 90° Servos for the nodbar
- Arduino Mega or Uno
- USB Host Shield
- MP3 Shield
- Adafruit PWM Board
- USB Bluetooth Adapter
- Kinivo BTD-400 USB Bluetooth Adapter for PC
- Azio USB Micro Bluetooth Adapter V4.0 EDR and aptX
- Note: check that the adapter is compatible. BestBuy sells an Insignia one that does NOT work
- PS4 DualShock controller
This sketch is used to control D-O.
Install Libraries
Before you start, you need to install some libraries. Open your Arduino IDE and click on Tools -> Manage Libraries. You will want to install the following libraries:
- ServoEasing by Armin Joachimsmeyer
- Adafruit PWM Servo Driver Library by Adafruit
- Yet Another Arduino Debounce Library by Paulo Costa
- USB Host Shield Library 2.0 by Oleg Mazurov (Circuits@Home)
Changes to ServoEasing library
You may need to make some changes to the ServoEasing library depending on your servos.
On line 35, you will want to enable the servo expander (Adafruit PWM):
Code:
/*
* For use with e.g. the Adafruit PCA9685 16-Channel Servo Driver aOffUnits.
*/
#define USE_PCA9685_SERVO_EXPANDER
Code:
/*
* Definitions here are only for convenience. You may freely modify them.
*/
#define MICROSECONDS_FOR_ROTATING_SERVO_CLOCKWISE_MAX (MICROSECONDS_FOR_ROTATING_SERVO_STOP - 1000)
#define MICROSECONDS_FOR_ROTATING_SERVO_CLOCKWISE_HALF (MICROSECONDS_FOR_ROTATING_SERVO_STOP - 500)
#define MICROSECONDS_FOR_ROTATING_SERVO_CLOCKWISE_QUARTER (MICROSECONDS_FOR_ROTATING_SERVO_STOP - 250)
#define MICROSECONDS_FOR_ROTATING_SERVO_COUNTER_CLOCKWISE_MAX (MICROSECONDS_FOR_ROTATING_SERVO_STOP + 1000)
#define MICROSECONDS_FOR_ROTATING_SERVO_COUNTER_CLOCKWISE_HALF (MICROSECONDS_FOR_ROTATING_SERVO_STOP + 500)
#define MICROSECONDS_FOR_ROTATING_SERVO_COUNTER_CLOCKWISE_QUARTER (MICROSECONDS_FOR_ROTATING_SERVO_STOP + 250)
You will need to make one small change to this library. It defaults to only sending a boolean value (true/false) because it is made for buttons, but we want it to send an integer value (joystick position). Simply change bool to int on line 16:
Code:
// Old code
template<typename clock=Clock::Millis, typename value_t=bool>
// New code
template<typename clock=Clock::Millis, typename value_t=int>
The sketch is setup assuming that you are using the same servos as specified in the D-O instructions. These servos are:
- (2) FS5103R or FS5106R - Continuous Rotation Servos for the wheels
- (2) MG90S or SG90S - 180° Servos for the neck
- (2) MG99R - 90° Servos for the nodbar
- FS5103R or FS5106R - Named as RIGHT_THROTTLE or LEFT_THROTTLE
- MG90S or SG90S - Named as NECK_TURN (bottom servo) or NECK_TILT (top servo)
- MG99R - Named as HEAD_TILT (mainbar servo) or HEAD_NOD (nodbar servo)
Code:
/*
* Sets the PWM pin number for the right wheel
*/
const int RIGHT_THROTTLE_PWM_PIN = 1;
While testing, you can enable TEST_MODE. This will bypass the controller and send signals directly to the servos. Each servo will run the maximum speed in one direction for 1.5 seconds, then reverse and run the maximum speed in the other direction for 1.5 seconds. Logs are output to the serial console so you can know which servo is being tested.
You can enable TEST_MODE by changing this constant in the file:
Code:
/*
* Sets the sketch into test mode for testing the servos and PWM
*/
const boolean TEST_MODE = false;
const int TEST_MODE_DELAY = 1500;
Controls
The sketch is setup to control D-O using the following controls:
- Left Joystick Up - Both wheels move forward
- Left Joystick Down - Both wheels move backward
- Left Joystick Left - Left wheel moves backward, right wheel moves forward (like a tank turning)
- Left Joystick Right - Right wheel moves backward, left wheel moves forward (like a tank turning)
- Right Joystick Up - Mainbar rotates forward (moving the head box forward)
- Right Joystick Down - Mainbar rotates backward (moving the head box back)
- Right Joystick Left - Head rotates left (moving the head left, like nodding the word "no")
- Right Joystick Right - Head rotates right (moving the head right, like nodding the word "no")
- Tilt Controller Forward - Nodbar rotates up (tilting the head down, like nodding "yes")
- Tilt Controller Backward - Nodbar rotates down (tilting the head up, like nodding "yes")
- Tilt Controller Left - Head tilts left (cocks the head left, like in the movie)
- Tilt Controller Right - Head tilts right (cocks the head right, like in the movie)
- Press Button (Circle) - Activate a sound on PIN A0
- Press Button (Triangle) - Activate a sound on PIN A1
- Press Button (Square) - Activate a sound on PIN A5
- Press Button (Cross) - Activate a sound on PIN A4
If you need any help, send an email to [email protected] or create an issue on the repository.
Credits
Credit goes to Kristian Lauszus ([email protected]) for creating the PS4 library for the USB Host Shield, Mr Baddeley for the 3-D files for D-O, authors of the various libraries, and you for building a droid!
Finally, following our Holochess (Dejarik) recollection below is a holiday flashback for Star Wars fans who still remember The Star Wars Holiday Special (1978) where Chewbacca and Han Solo aim to celebrate Life Day on the Wookiee's homeworld of Kashyyyk with Chewbacca's family including Mallatobuck (Malla), Attichitcuk (Itchy), and Lumpawarrump or Lumpawaroo (Lumpy) despite running into an Imperial blockade... let the party begin!
Star Wars: The Rise of Skywalker Final Trailer
STAR WARS Battlefront II: The Rise of Skywalker Official PS4 Trailer