Gruber
HobbyMasters
M.L. Toys
KidsWheels
Gruber
HobbyMasters
M.L. Toys
KidsWheels
HobbyMasters M.L. Toys
Gruber
KidsWheels
Adding R/C to your Powerwheels vehicles? Using R/C parts on your Powerwheels?
By Suchtrk
#150072
So long story short my In-Laws bought our son a best choice RC jeep for his birthday. with a ride on weight capacity of 65ish pounds. we take it out of course as soon as its charged for him to try and he loves it. works pretty well in the back yard. we then decide to walk him around the neighborhood with it and it starts acting up. it will drive in either forward or reverse for a short bit and then "stall" for lack of better word then take back off. my only guess looking at it was that one of the 3 self resetting fusees is blowing. I also find on the "motherboard" that the connector is melting. we get that settled with the place of purchase and i am now setting with a free half broke powerwheels and have committed to converting it to quality RC parts. i decided to set up and Arduino to interpret the RC receiver so that my son wouldn't lose the ability to use the peddle as he gets older and learns how to drive himself. i was hoping to see if anyone on here had messed with an Arduino before and could look over the sketch that i have come up with. it seems to work well on my bench but wanted to see if some one with more experience could take a look at it. Thanks
Code: Select all
#include <Servo.h>
 

Servo esc;

const int pedalPin = 4; // pedal input pin
const int forwardPin = 5; // 2 way shift switch forward input pin
const int reversePin = 6; // 2 way shift switch reverse input pin

int pedalstate = 0; // variable for pedal state
int forwardstate = 0; // varable for forward state
int reversestate = 0; // varable for reverse state
int throttle = 90; // throttle varable set to neutral


#define RCCHANNEL2PIN 2 // RC channel 2 "throttle" pin
#define RCCHANNEL3PIN 3 // RC channel 3 "park" pin

#define RC_NUM_CHANNELS 2 // array size

#define RC_CH2 0 // spacific array slot "throttle"
#define RC_CH3 1 // spacific array slot "park"

uint16_t rc_values[RC_NUM_CHANNELS]; // rc reading arrays
uint32_t rc_start[RC_NUM_CHANNELS];
volatile uint16_t rc_shared[RC_NUM_CHANNELS];


void calc_ch2() // void to calculate channel 2 "throttle" input from reciver
{
  calc_input(RC_CH2, RCCHANNEL2PIN);
 
}

void calc_ch3() // void to calculate channel 3 "park" from reciver
{
  calc_input(RC_CH3, RCCHANNEL3PIN);
  
}

void calc_input(uint8_t channel, uint8_t input_pin) // void to calculate pulse length from reciver
{
  if (digitalRead(input_pin) == HIGH)
  {
    rc_start[channel] = micros();
  } else {
    uint16_t rc_compare = (uint16_t)(micros() - rc_start[channel]);
    rc_shared[channel] = rc_compare;
  }
}

void rc_read_values() // void to copy rc_shared array to rc_values array
{
  noInterrupts();
  memcpy(rc_values, (const void *)rc_shared, sizeof(rc_shared));
  interrupts();
}
 
void setup()
{
esc.attach(9); // esc attached to pin 9

pinMode(pedalPin, INPUT); // throttle pedal pin set to input
digitalWrite(pedalPin, HIGH); // throttle pin set to use pullup resistor
pinMode(forwardPin, INPUT); // forward pin set as input
digitalWrite(forwardPin, HIGH); // forward pin set to use pullup resistor
pinMode(reversePin, INPUT); // reverse pin set to input
digitalWrite(reversePin, HIGH); // reverse pin set to use pullup resistor

pinMode(RCCHANNEL2PIN, INPUT); //RC channel 2 "throttle" pin set to input
pinMode(RCCHANNEL3PIN, INPUT); // RC channel 3 "park" pin set to input

attachInterrupt(digitalPinToInterrupt(RCCHANNEL2PIN), calc_ch2, CHANGE);// attach intrrupt to catch "throttle" input
attachInterrupt(digitalPinToInterrupt(RCCHANNEL3PIN), calc_ch3, CHANGE);// attach intrrupt to catch "park" input

Serial.begin(9600); // serial monitor

}
 
void loop()
{
rc_read_values(); // coppy array
rc_values[0] = map(rc_values[0], 1000, 2000, 0, 179); // map "throttle" from pulse lenght to degrees
rc_values[0] = constrain(rc_values[0], 5, 179); // constrain "throttle" between 5-179 degrees
rc_values[1] = map(rc_values[1], 1000, 2000, 0, 179); // map "park" from pulse lenght to degrees
rc_values[1] = constrain(rc_values[1], 5, 179); // constrain "park" between 5-179


pedalstate = digitalRead(pedalPin); // read foot pedal state
forwardstate = digitalRead(forwardPin); // read gear shift state forward
reversestate = digitalRead(reversePin); // read gear shift state reverse

if (rc_values[1] > 165 ) // check if rc controll is on or set to park
{
throttle = 90;
} 
else if (rc_values[0] < 90 || rc_values[0] > 100 ) // check to see if there is input from controller for throttle
{
  throttle = rc_values[0];
}
else 
{
  if (forwardstate == LOW && reversestate == HIGH) // check what possition shifter is in "forward"
  {
    if (pedalstate == LOW) // check if pedal is pressed
    {
       throttle = 165;
    }
    else
    {
    throttle = 90;
    }
  }
  else if (forwardstate == HIGH && reversestate == LOW) // check what possition chifter is in "reverse"
  { 
    if (pedalstate == LOW) // check if pedal is pressed
    {
      throttle = 25;
      }
      else
      {
        throttle = 90;
        }
  }
  else 
  {
    throttle = 90;
    }
}

esc.write(throttle); // write throttle value to ESC


Serial.print("pedal: ");
Serial.println(pedalstate);
Serial.print("reverse: ");
Serial.println(reversestate);
Serial.print("forward: ");
Serial.println(forwardstate);
Serial.print("throttl: ");
Serial.println(throttle);
Serial.print("rc: ");
Serial.print(rc_values[0]);
Serial.print(" ");
Serial.println(rc_values[1]);
delay(1000);
}
 


I'd say it's consistent. There are 3 negative fee[…]

Throttle options?

Looks like a much better setup than the scooter E[…]

Brake question with ESC

Can you re-upload an image we can read? This one […]

These links work very well. I'm also looking for t[…]

HobbyMasters Udemy Course