What’s cooler than a remote controlled car? A smartphone controlled car!
The LightBlue Bean can be used to make existing projects and toys talk to your smartphone. In this tutorial we show you how to integrate the Bean in an existing RC car and use the iOS app LightBlue to control it. Reverse engineering fun guaranteed!
We’ve been using our RC van to deliver all sorts of things by iPhone:
Here’s what you’ll need:
- A LightBlue Bean
- An RC car
- A soldering iron
- Screwdriver, machete, and other disassembly tools
Disassembly
We chose an VW Bus from Maisto, available here. It’s pretty cheap, easy to hack and has a lot of room for our additions. Start by taking the screws out from the bottom of the bus and then remove the plastic cover. If you need more room to fit everything, the window piece can also be popped out.
The Investigation
Note: If you are using the VW Bus, you can skip this step. The next step identifies the needed pins
Most RC cars work by receiving their controls via RF (49MHz in our case) and then decode the sent signal. We want to interrupt the signal and replace it with inputs from the bean so that Bluetooth from iOS device can control it. The Bean itself can’t handle the current to drive the motors so we need to connect to the motor controllers. The bus has one motor for steering and one for moving, each with a separate H bridge motor controller. We are interested in finding the input pins for each motor controller.
To identify the H Bridge ICs, probe the positive end of the motor to the various ICs on the main board using a multi meter on continuity test mode or in resistance mode. Once the connection is found (beep on the meter or 0 ohms) the H bridge has been found! Repeat the process for the other motor. You can verify that the IC is indeed an H bridge by searching the name of the chip on the internet. The VW Bus uses Hotchip HT5125FE H bridges. Find a data sheet for the H bridge and find which pins are for the input if you are using a different car.
The Wiring
When one input to the H bridge is driven high, the motor will go in one direction. When the other input pin is driven high, the motor will travel in the opposite direction. We need to solder each input to a corresponding PWM from the Bean. Soldering directly to the pins can be risky because the stress from the wire might break a pad or a pin, so if a resistor is connected to a pin, solder the connection to that instead, or use rework wire.
On the bus we used, the resistors used are:
- R16 – Forward (Pin 0 on the Bean)
- R17 – Backward (Pin 1 on the Bean)
- R18 – Left (Pin 3 on the Bean)
- R19 – Right (Pin 2 on the Bean)
If there is interference from the hand held controller, the resistors can be removed thus isolating the H bridge from the rest of the board.
This is how we wired it to the Bean:
The Code
C++
/*
Bean RC Car Sketch
This uses the RC car example at http://legacy.punchthrough.com/bean/?page_id=5157
and needs the LightBlue App
*/
//Define the pins for the motor controllers
int mForward = 0;
int mReverse = 1;
int mRight = 2;
int mLeft = 3;
//define constant for full PWM signal
#define MOTOR_HIGH 255
//Define inputs for LightBlue
#define XYPAD_X 8
#define XYPAD_Y 9
//Variables to store the sandbox inputs
static uint8_t gas;
static uint8_t steering;
void setup()
{
//Setup pins
pinMode(mReverse, OUTPUT);
pinMode(mForward, OUTPUT);
pinMode(mLeft, OUTPUT);
pinMode(mRight, OUTPUT);
//Need serial for LightBlue
Serial.begin(57600);
Serial.setTimeout(5);
}
void loop()
{
/*
Steering via sanbox controls.
The gas is set proportionally with a dead zone,
while steering is either off, left or right (the car was designed to stall the steering motor when turning).
Gas:
1 --------- 100 160 --------- 255
Reverse stop forward
Stering:
1 --------- 100 160 --------- 255
left stop right
*/
//Create a buffer to recieve from LightBlue, along with length
char rec_buffer[64];
size_t rec_length = 64;
//Set the length to number of bytes recieved
rec_length = Serial.readBytes(rec_buffer, rec_length);
if ( rec_length > 0 )
{
Bean.setLed(255,255,255);
// There may be both X and Y values read in
// a single packet. Handle this case.
// Byte[0] : X/Y control #
// Byte[1] : Value [0,255]
for (int i = 0; i < rec_length - 1; i += 2 )
{
if ( rec_buffer[i] == XYPAD_X )
{
steering = rec_buffer[i + 1];
}
else if ( rec_buffer[i] == XYPAD_Y )
{
gas = rec_buffer[i + 1];
}
}
}
else{
Bean.setLed(0,0,0);
}
//Setup steering control and deadzones
if (steering < 100) {
//left
analogWrite(mRight, 0);
analogWrite(mLeft, MOTOR_HIGH);
}
else if (steering > 160) {
//right
analogWrite(mRight, MOTOR_HIGH);
analogWrite(mLeft, 0);
}
else {
//straight
analogWrite(mRight, 0);
analogWrite(mLeft, 0);
}
if (gas < 120) {
//forward (inverted)
analogWrite(mForward, 255 - gas);
analogWrite(mReverse, 0);
}
else if (gas > 136) {
//reverse
analogWrite(mForward, 0);
analogWrite(mReverse, gas);
}
else {
//stop
analogWrite(mForward, 0);
analogWrite(mReverse, 0);
}
}
Drive
In the iOS app LightBlue there’s a section called Sandbox that can be used to send and receive data from the Bean without having to make your own iOS app. Connect to a Bean trough the app, press options and select Sandbox. Click on the trackpad in the bottom and set the input to the center of the screen, then turn the bus on. The controls for driving are similar to an arcade game. If the controls are incorrect, try switching the the pins in the code for mForward, mReverse, mLeft and mRight.
What’s Next?
The VW Bus can be further modified. We added a buzzer for a horn and blue LED headlights. Next step: integrating the Bean in a real car and making it smartphone controlled. What could go wrong? Or maybe not…
For more examples on how to use Sandbox in LightBlue, check out XYBlink (control output) and SetXY (control input).
Corin Rypkema05.19.2015
Comments
Please log in or sign up to comment.