Creating a RC car with ESP32 and TAMIYA’s BUGGY CAR CHASSIS SET (Part 3: Controlling servo motors and DC motors with a PS3 controller, troubleshooting)

ESP32

It is continued from Part 2.

PS3 controller controls servo motors only

The code is almost the same as the one on this site, with the addition of a line to display serial communication for debugging.

#include<ESP32Servo.h>
#include <Ps3Controller.h>

#define SERVO_OUT 5   //5 pin for servo output
#define INIT_ANGLE 90 //initial servo angle
Servo myServo;

  int joy_left_y;  //left joystick Y
  int joy_right_x;  //right joystick X

  const float joy2servo = 0.2344f; //joystick input to servo angle gain
  int servo_angle;

void setup() {
    myServo.attach(SERVO_OUT);
    myServo.write(INIT_ANGLE); //servo angle initiation    
    Ps3.begin("##:##:##:##:##:##"); //MAC adress. Please change ##       
    Serial.begin(115200);           //Debug
}

void loop() {
  if(!Ps3.isConnected())
        return;

  //左側ジョイスティックのy軸制御    
  if( Ps3.event.analog_changed.stick.ly ){  
    joy_left_y = Ps3.data.analog.stick.ly;
  }
  
  //右側ジョイスティックのx軸制御
  if( Ps3.event.analog_changed.stick.rx ){
    joy_right_x = Ps3.data.analog.stick.rx;

    //なくても大丈夫だけど、±5を不感帯とする。
    if(abs(joy_right_x) < 5){
      joy_right_x = 0;
    }
    
    //ジョイスティックの読み値をサーボ角に変換
    servo_angle = (int)(joy2servo * joy_right_x + INIT_ANGLE);
    myServo.write(servo_angle);
    Serial.println(servo_angle);           //Debug用
  }
}

The following problems occurred.

  • Problem 1: Immediate disconnection from controller (lamp goes out)
    When I checked the serial communication for debugging, I found a message “Brownout detector was triggered”.
    This message seemed to be caused by the lack of USB power supply for ESP32. I solved this problem by preparing separate power supplies for the servo motor and ESP32.
    “Brownout detector was triggered” message. lack of USB power supply.
  • Problem 2: Servo turns in various directions in small increments (rampant).
    The cause was that the GNDs of the servo and ESP32 were not unified. It is a basic thing, but I inadvertently forgot to wire it.

PS3 controller controls both servo and DC motors

I tried to move the servo motor and DC motor using the code on this site, but it did not work in my environment. The symptoms are that the DC motor moves normally with the left stick, but the servo motor moves at the same time, and the servo moves only a little with the right stick.
The cause was a PWM signal channel confusion. The PWM channel input to the motor driver (L298N) was not specified, and both the servo motor and motor driver PWM signal channels were set to 0. The problem was solved by setting the PWM channel to the motor driver from 0 to 13.

Please refer to this article this article for how to specify channels when outputting multiple PWM signals with ESP32.

Please also see the previous article.

その①はこちら

その 1.5 はこちら

その②はこちら

その④はこちら

コメント

タイトルとURLをコピーしました