Driving an RC car with a PS3 controller

Several people have asked me for the code, so here it is. The car is a Rally Monster by Exceed RC.

See this post for details regarding the Arduino, USB host shield, and PS3 controller. For information regarding the hardware setup, see this post.

Advertisements

112 thoughts on “Driving an RC car with a PS3 controller

  1. Hi Omar,

    To make sure I understand you correctly, you have managed to get some sort of response from L2 and R2? If so, you should be very close to getting the response you want. Since you are getting some forward acceleration, but none backwards, I would guess that your ESC is not calibrated to the output range of your Arduino. This website describes your problem (“Now that everything is setup, chances are that you motor might not rotate, or might rotate only forward, or might rotate only to 80% of the throttle (forward and reverse) and then stop: all these are symptoms of lack of calibration, or a calibration done with a different range of PWM signals.”): https://dronesandrovs.wordpress.com/2012/11/24/how-to-control-a-brushless-motor-esc-with-arduino/. Take a look at the video on this page, which should help you understand. You can proceed in two ways. You can map the Arduino output to the current ESC calibration (more difficult), or calibrate your ESC to your Arduino output (easier, provided you have the calibration manual for your ESC). Take a look at the provided link, and let me know if you have any other questions.

    Regards,

    Barrett

  2. Hi Anthony,

    You can use any RC car that has a standard ESC and servo. Both components must respond to a PWM signal (which is standard on any medium to high end RC car). Very cheap RC cars generally do not have standard components, and therefore will not be compatible unless you install standard ESC/servo components. Feel free to send me some pictures of your car and I might be able to tell if it’s compatible.

    Regards,

    Barrett

  3. Hi Robert,

    I have not seen an email from you, so it might have gotten lost in my spam folder. Please post your errors here so that others might learn from you problem/solution.

    Regards,

    Barrett

  4. Hi Ki Hwan,

    Which set of code are you having trouble with (it looks like you’ve posted 3 comments with slightly different pieces of code), and exactly what error are you getting? I will need specific details of the errors to be able to help you.

    Regards,

    Barrett

  5. Hello, i been trying tog et this to work for a few days now with the help of my girlfriend, but we just cant get past “PS3 USB Library Started” and anytime we try to add anything to the code it messes up, is there any way you can put up a link to the FULL complete code you are using on your Arduino so i can just copy and paste? please it would be great, i am going crazy right here haha

  6. good hello, first of all I love the project you have done, I think an excellent job. Well the fact is that for more than investigate not find a way to schedule an ESC rc car with a command of PS4 , to see if you could help me. I managed to program it with the code for the joystick with your example of ps3, but I like to program it with the L2 and R2 , L2 and R2 triggers to slow to accelerate. I get only accelerate , but not to go in reverse. Could you help me?

  7. i’m ki hwan South Korea.

    im studing arduino but it’s not working very well

    I trying to connect Arduino to a RC car, but i don’t know how to sketch.
    so i would appreciate it if you would take a look at my problem please.

    first, my sketch is this.

    USB Usb;
    //USBHub Hub1(&Usb); // Some dongles have a hub inside

    BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
    /* You can create the instance of the class in two ways */
    PS3BT PS3(&Btd); // This will just create the instance
    //PS3BT PS3(&Btd, 0x00, 0x15, 0x83, 0x3D, 0x0A, 0x57); // This will also store the bluetooth address – this can be obtained from the dongle when running the sketch

    bool printTemperature;
    bool printAngle;

    void setup() {
    Serial.begin(115200);
    #if !defined(__MIPSEL__)
    while (!Serial); // Wait for serial port to connect – used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
    #endif
    if (Usb.Init() == -1) {
    Serial.print(F(“\r\nOSC did not start”));
    while (1); //halt
    }
    Serial.print(F(“\r\nPS3 Bluetooth Library Started”));
    }
    void loop() {
    Usb.Task();

    if (PS3.PS3Connected || PS3.PS3NavigationConnected) {
    if (PS3.getAnalogHat(LeftHatX) > 137 || PS3.getAnalogHat(LeftHatX) 137 || PS3.getAnalogHat(LeftHatY) 137 || PS3.getAnalogHat(RightHatX) 137 || PS3.getAnalogHat(RightHatY) < 117) {
    Serial.print(F("\r\nLeftHatX: "));
    Serial.print(PS3.getAnalogHat(LeftHatX));
    Serial.print(F("\tLeftHatY: "));
    Serial.print(PS3.getAnalogHat(LeftHatY));
    if (PS3.PS3Connected) { // The Navigation controller only have one joystick
    Serial.print(F("\tRightHatX: "));
    Serial.print(PS3.getAnalogHat(RightHatX));
    Serial.print(F("\tRightHatY: "));
    Serial.print(PS3.getAnalogHat(RightHatY));
    }
    }

    // Analog button values can be read from almost all buttons
    if (PS3.getAnalogButton(L2) || PS3.getAnalogButton(R2)) {
    Serial.print(F("\r\nL2: "));
    Serial.print(PS3.getAnalogButton(L2));
    if (PS3.PS3Connected) {
    Serial.print(F("\tR2: "));
    Serial.print(PS3.getAnalogButton(R2));
    }
    }
    .
    .
    i'm very confused with my sketch, so need your help.
    why doesn't this sketch move?
    if you solve this problem, please contact me. It would be very helpful. Thank you

  8. i’m ki hwan South Korea.

    im studing arduino but it’s not working very well

    I trying to connect Arduino to a RC car, but i don’t know how to sketch.
    so i would appreciate it if you would take a look at my problem please.

    first, my sketch is this.

    #define OUTPUTPIN 3
    #define OUTPUTPIN 5
    #include
    #include
    #include

    // Satisfy the IDE, which needs to see the include statment in the ino too.
    #ifdef dobogusinclude
    #include
    #include
    #endif

    Servo servo1;
    Servo servo2;

    USB Usb;
    //USBHub Hub1(&Usb); // Some dongles have a hub inside

    BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
    /* You can create the instance of the class in two ways */
    //PS3BT PS3(&Btd); // This will just create the instance
    //PS3BT PS3(&Btd, 0x00, 0x1A, 0x7D, 0xDA, 0x71, 0x13); // This will also store the bluetooth address – this can be obtained from the dongle when running the sketch

    bool printTemperature;
    bool printAngle;

    void setup() {
    Serial.begin(115200);
    while (!Serial); // Wait for serial port to connect – used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
    if (Usb.Init() == -1) {
    Serial.print(F(“\r\nOSC did not start”));
    while (1); //halt
    }
    Serial.print(F(“\r\nPS3 Bluetooth Library Started”));
    pinMode(3, OUTPUT);
    pinMode(5, OUTPUT);
    servo1.attach(5);
    servo2.attach(3);
    }
    void loop()
    {
    Usb.Task();

    if (PS3.PS3Connected || PS3.PS3NavigationConnected) {

    servo1.write(map(PS3.getAnalogHat(RightHatX),0, 255, 0, 100));
    servo1.write(map(PS3.getAnalogHat(LeftHatX),0, 255, 100, 0));

    }
    else
    {
    servo1.write(90);
    servo2.write(90);
    }
    if(PS3.getButtonClick(PS)){
    Serial.print(F(“\r\nPS”));
    PS3.disconnect();
    }
    }

    // Analog button values can be read from almost all buttons
    if (PS3.getAnalogButton(L2) || PS3.getAnalogButton(R2)) {
    Serial.print(F(“\r\nL2: “));
    Serial.print(PS3.getAnalogButton(L2));
    if (PS3.PS3Connected) {
    Serial.print(F(“\tR2: “));
    Serial.print(PS3.getAnalogButton(R2));
    }
    }
    if (PS3.getButtonClick(PS)) {
    Serial.print(F(“\r\nPS”));
    PS3.disconnect();
    }
    else {
    if (PS3.getButtonClick(TRIANGLE))
    Serial.print(F(“\r\nTraingle”));
    if (PS3.getButtonClick(CIRCLE))
    Serial.print(F(“\r\nCircle”));
    if (PS3.getButtonClick(CROSS))
    Serial.print(F(“\r\nCross”));
    if (PS3.getButtonClick(SQUARE))
    Serial.print(F(“\r\nSquare”));

    ‘m very confused with my sketch, so need your help.
    why doesn’t this sketch move?
    if you solve this problem, please contact me. It would be very helpful. Thank you

  9. i’m ki hwan South Korea.

    im studing arduino but it’s not working very well

    I trying to connect Arduino to a RC car, but i don’t know how to sketch.
    so i would appreciate it if you would take a look at my problem please.

    first, my sketch is this.

    #define OUTPUTPIN 3
    #define OUTPUTPIN 5
    #include
    #include
    #include

    // Satisfy the IDE, which needs to see the include statment in the ino too.
    #ifdef dobogusinclude
    #include
    #include
    #endif

    Servo servo1;
    Servo servo2;

    USB Usb;
    //USBHub Hub1(&Usb); // Some dongles have a hub inside

    BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
    /* You can create the instance of the class in two ways */
    //PS3BT PS3(&Btd); // This will just create the instance
    //PS3BT PS3(&Btd, 0x00, 0x1A, 0x7D, 0xDA, 0x71, 0x13); // This will also store the bluetooth address – this can be obtained from the dongle when running the sketch

    bool printTemperature;
    bool printAngle;

    void setup() {
    Serial.begin(115200);
    while (!Serial); // Wait for serial port to connect – used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
    if (Usb.Init() == -1) {
    Serial.print(F(“\r\nOSC did not start”));
    while (1); //halt
    }
    Serial.print(F(“\r\nPS3 Bluetooth Library Started”));
    pinMode(3, OUTPUT);
    pinMode(5, OUTPUT);
    servo1.attach(5);
    servo2.attach(3);
    }
    void loop()
    {
    Usb.Task();

    if (PS3.PS3Connected || PS3.PS3NavigationConnected) {

    servo1.write(map(PS3.getAnalogHat(RightHatX),0, 255, 0, 100));
    servo1.write(map(PS3.getAnalogHat(LeftHatX),0, 255, 100, 0));

    }
    else
    {
    servo1.write(90);
    servo2.write(90);
    }
    if(PS3.getButtonClick(PS)){
    Serial.print(F(“\r\nPS”));
    PS3.disconnect();
    }
    }

    // Analog button values can be read from almost all buttons
    if (PS3.getAnalogButton(L2) || PS3.getAnalogButton(R2)) {
    Serial.print(F(“\r\nL2: “));
    Serial.print(PS3.getAnalogButton(L2));
    if (PS3.PS3Connected) {
    Serial.print(F(“\tR2: “));
    Serial.print(PS3.getAnalogButton(R2));
    }
    }
    if (PS3.getButtonClick(PS)) {
    Serial.print(F(“\r\nPS”));
    PS3.disconnect();
    }
    else {
    if (PS3.getButtonClick(TRIANGLE))
    Serial.print(F(“\r\nTraingle”));
    if (PS3.getButtonClick(CIRCLE))
    Serial.print(F(“\r\nCircle”));
    if (PS3.getButtonClick(CROSS))
    Serial.print(F(“\r\nCross”));
    if (PS3.getButtonClick(SQUARE))
    Serial.print(F(“\r\nSquare”));

    ‘m very confused with my sketch, so need your help.
    why doesn’t this sketch move?
    if you solve this problem, please contact me. It would be very helpful. Thank you

  10. i’m ki hwan South Korea.

    im studing arduino but it’s not working very well

    I trying to connect Arduino to a RC car, but i don’t know how to sketch.
    so i would appreciate it if you would take a look at my problem please.

    first, my sketch is this.

    #define OUTPUTPIN 3
    #define OUTPUTPIN 5
    #include
    #include
    #include

    // Satisfy the IDE, which needs to see the include statment in the ino too.
    #ifdef dobogusinclude
    #include
    #include
    #endif

    Servo servo1;
    Servo servo2;

    USB Usb;
    //USBHub Hub1(&Usb); // Some dongles have a hub inside

    BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
    /* You can create the instance of the class in two ways */
    //PS3BT PS3(&Btd); // This will just create the instance
    //PS3BT PS3(&Btd, 0x00, 0x1A, 0x7D, 0xDA, 0x71, 0x13); // This will also store the bluetooth address – this can be obtained from the dongle when running the sketch

    bool printTemperature;
    bool printAngle;

    void setup() {
    Serial.begin(115200);
    while (!Serial); // Wait for serial port to connect – used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
    if (Usb.Init() == -1) {
    Serial.print(F(“\r\nOSC did not start”));
    while (1); //halt
    }
    Serial.print(F(“\r\nPS3 Bluetooth Library Started”));
    pinMode(3, OUTPUT);
    pinMode(5, OUTPUT);
    servo1.attach(5);
    servo2.attach(3);
    }
    void loop()
    {
    Usb.Task();

    if (PS3.PS3Connected || PS3.PS3NavigationConnected) {

    servo1.write(map(PS3.getAnalogHat(RightHatX),0, 255, 0, 100));
    servo1.write(map(PS3.getAnalogHat(LeftHatX),0, 255, 100, 0));

    }
    else
    {
    servo1.write(90);
    servo2.write(90);
    }
    if(PS3.getButtonClick(PS)){
    Serial.print(F(“\r\nPS”));
    PS3.disconnect();
    }
    }

    // Analog button values can be read from almost all buttons
    if (PS3.getAnalogButton(L2) || PS3.getAnalogButton(R2)) {
    Serial.print(F(“\r\nL2: “));
    Serial.print(PS3.getAnalogButton(L2));
    if (PS3.PS3Connected) {
    Serial.print(F(“\tR2: “));
    Serial.print(PS3.getAnalogButton(R2));
    }
    }
    if (PS3.getButtonClick(PS)) {
    Serial.print(F(“\r\nPS”));
    PS3.disconnect();
    }
    else {
    if (PS3.getButtonClick(TRIANGLE))
    Serial.print(F(“\r\nTraingle”));
    if (PS3.getButtonClick(CIRCLE))
    Serial.print(F(“\r\nCircle”));
    if (PS3.getButtonClick(CROSS))
    Serial.print(F(“\r\nCross”));
    if (PS3.getButtonClick(SQUARE))
    Serial.print(F(“\r\nSquare”));
    .
    .
    .

    and so on
    .
    .
    .

    i’m very confused with my sketch, so need your help.
    why doesn’t this sketch move?
    if you solve this problem, please contact me. It would be very helpful. Thank you

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s