RC car steering and motors linked

I'm working on a project where I wanted to make an RC car using a Rocket League car body but I can't seem to get the steering and driving to work. I'm using "Remote XY" to control the car and I have gotten it to link up and I can control both the steering and the driving with the app. The problem I have is that if any point in the session I turn the motor on to drive the car forward the servo jerks to the right and then no longer responds to any input. Once I restart the car the servo works properly again, until I turn the motors on for the car to drive. I am using a DRV8833 to for motor control, and 2 18650 cells for power. The code for the car is attached below.

/*
   -- New project --
   
   This source code of graphical user interface 
   has been generated automatically by RemoteXY editor.
   To compile this code using RemoteXY library 3.1.13 or later version 
   download by link http://remotexy.com/en/library/
   To connect using RemoteXY mobile app by link http://remotexy.com/en/download/                   
     - for ANDROID 4.15.01 or later version;
     - for iOS 1.12.1 or later version;
    
   This source code is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.    
*/

//////////////////////////////////////////////
//        RemoteXY include library          //
//////////////////////////////////////////////

// you can enable debug logging to Serial at 115200
//#define REMOTEXY__DEBUGLOG    

// RemoteXY select connection mode and include library 
#define REMOTEXY_MODE__ESP32CORE_BLE

#include <BLEDevice.h>

// RemoteXY connection settings 
#define REMOTEXY_BLUETOOTH_NAME "Fennec"


#include <RemoteXY.h>

// RemoteXY GUI configuration  
#pragma pack(push, 1)  
uint8_t RemoteXY_CONF[] =   // 90 bytes
  { 255,2,0,0,0,83,0,19,0,0,0,70,101,110,110,101,99,0,24,2,
  106,200,200,84,1,1,4,0,4,35,155,36,12,142,7,5,68,48,2,26,
  4,36,159,36,12,25,44,68,5,176,2,26,129,248,47,71,29,34,20,48,
  12,64,17,68,105,114,101,99,116,105,111,110,0,129,249,52,71,29,150,10,
  34,12,64,17,83,112,101,101,100,0 };
  
// this structure defines all the variables and events of your control interface 
struct {

    // input variables
  int8_t speed; // from -100 to 100
  int8_t steer; // from -100 to 100

    // other variable
  uint8_t connect_flag;  // =1 if wire connected, else =0

} RemoteXY;   
#pragma pack(pop)
 
/////////////////////////////////////////////
//           END RemoteXY include          //
/////////////////////////////////////////////

#include <ESP32Servo.h>

#define steering 15

#define forward 18
#define backward 19
#define sleep 21

Servo servo;
int steerRange = 20;
int center = 92;


void setup() 
{
  RemoteXY_Init (); 

  // TODO you setup code
  pinMode(sleep, OUTPUT);
  pinMode(forward, OUTPUT);
  pinMode(backward, OUTPUT);
  servo.attach(steering);
  servo.write(center);// move servo to center position -> 90°
  Serial.begin(115200);
  Serial.println("running");
}

void loop() { 
  RemoteXY_Handler ();

  float speed = RemoteXY.speed;
  float steer = RemoteXY.steer;
  // TODO you loop code
  // use the RemoteXY structure for data transfer
  // do not call delay(), use instead RemoteXY_delay() 

  if(speed != 0){
    if(speed > 0){
      digitalWrite(sleep, HIGH);
      //Serial.println("Motor On");
      digitalWrite(backward, LOW);
      Serial.print("Forward: ");
      Serial.println((speed/100) * 65535);
      analogWrite(forward, (speed/100) * 65535);
      //Serial.println("Move Forward");
    }
    if(speed < 0){
      digitalWrite(sleep, HIGH);
      //Serial.println("Motor On");
      digitalWrite(forward, LOW);
      Serial.print("Backward: ");
      Serial.println((speed/100) * -65535);
      analogWrite(backward, (speed/100) * -65535);
      //Serial.println("Move Backward");
    }
  }else{
    digitalWrite(sleep, LOW);
    digitalWrite(backward, LOW);
    digitalWrite(forward, LOW);
    //Serial.println("Motor Off");
  }

  if(steer != 0){
    int steerChange = steer * steerRange * .01;
    // Serial.println(steer);
    // Serial.println(steer * steerRange);
    // Serial.println(steerChange);
    Serial.println(center + steerChange);
    if(steer < 0){
      servo.write(center + steerChange);
      //Serial.println("Right");
    }
    if(steer > 0){
      servo.write(center + steerChange);
      //Serial.println("Left");
    }
  }else{
    servo.write(center);//Recenter
    //Serial.println("Center");
  }
}

How do you power the servo, and how thick are the battery holder wires.
Leo..

Please post a schematic of how everything is wired.

Attached are the schematic and the pinout for the specific EPS32 I am using. The battery is wired to power the whole system, but I am currently testing with the switch left open.

The servo should never be powered directly from the controller. You need a separate power supply around 5-6volts. 7.4v if they are the heavy duty servos.

Also keep in mind the servo needs to be tied to the same ground as the controller, otherwise it won’t work.

You may want to also have some 220uf capacitors in there too, otherwise you may get brownouts if the motors or servo draw too much current.

Another thing I am wondering is, why you have 2 dc motors in parallel instead of using the B side of that driver? Also the driver is always connected to the battery, it should have a switch too, or just rewire your switch so that the driver and controller get power at the same time.

Is bat- the same as GND? You may want to ground that battery instead of it just going to bat-.

I'll make some of these adjustments soon, the end goal for this project is to be a "proof of concept" before I make one with better parts, so I'm not worried about using the capacitors.

I'll tie to servo to the battery power instead of the controller, but I only want to use 1 power supply. Everything is small, so I'm using a SG90 servo for reference.

For the motors, I have 2 motor per rear wheel, I found that connecting them in parallel meant I could just change the state on 1 channel to change direction. I suppose I could swap it to the B side, but that will just add more code and wires. I can rewire the driver, but it seemed to work just fine on battery power how I have it.

I'm not sure if BAT - is the same as GND, I'm using the board found here. I should've said VMotor, but I have the batteries wired to the 2 pins on VMotor.

Thanks for all the advice, although I'm not sure if this will address the servo problem I'm having.

Your servo isn’t getting enough voltage and the 8v power supply is too much for the servo. If this was a real world application, your servo wouldn’t work in either scenario. The 8v would actually burn out the servo.

The servo works just fine while powered from the controller, I drew the schematic to show how I had it wired to have it work. I looked at the datasheet for the SG90 and you’re right, the recommended voltage is 4.8-6.

I already tried powering the servo using a separate 9V D battery and it worked the same way as I mentioned earlier. 2 separate power supplies but when the rear wheel motors turned on the steering jerked and locked up. I will look into a way to lower the voltage running to the SG90, but I want this car to have only 1 power supply.

I feel like this design is close to working but there is something small I’m missing to make it work with 1 power supply.

You can have 1 supply, you will just need a 5 volt regulator for the servo.

Okay I will do that once I have the chance to work on the circuit again, I already have the voltage regulator. I’ll update the post if this doesn’t resolve my initial issue I was having.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.