Pages: [1]   Go Down
Author Topic: Control cheap RC toy car RX2 chip with Arduino using only one pin - [SOLVED]  (Read 2607 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everyone,

I bought a cheap Chinese toy car and it has the famous TX2/RX2 chip combo. What I would like to do is get rid off the TX2 transmitter (the remote) and control the RX2 chip in the car with an Arduino.

I know the easiest solution is to simply hook up the Arduino to the RX2 H-Bridge pins and write HIGH, LOW to control the driving and steering movements as explained in this tutorial (http://letsmakerobots.com/node/31757). This is OK, but I want to be able to generate the same pulse signals the TX2 transmitter (remote) is sending to the RX2 (car) receiver directly with the Arduino. The RX2 has a signal input pin (Pin 3 usually on RX2 chips). With the right programming it should be possible to PWM the right combination of pulses from the Arduino to that signal input pin of the RX2 chip to signal movements like forward, backwards, etc.

I have a datasheet here for the RealTek RX2/TX2 chip. On page 4 you can see the data format (pulse signals) the RX2 chip understands.

http://www.jbprojects.net/projects/wifirobot/TX2RX2.doc

W2 W2 W2 W2 (n) x W1 W2 W2 W2 W2 (n) x W1 W2 W2 W2 W2

Number of Function Codes (n) W1 | Function Key
4      End Code
10   Forward   
16   Forward & Turbo
22   Turbo
28   Turbo & Forward & Left   
34   Turbo & Forward & Right   
40   Backward   
46   Backward & Right   
52   Backward & Left
58   Left
64   Right

The W2 are 500 Hz at 75% duty cycle
The W1 are 1KHz at 50% duty cycle.

The W1 pulses are the function code, so for example 10 W1 pulses will cause a forward movement, 58 W1 pulses activate left steering. The W2 pulses seem to be Start and End commands before and after the W1 pulses.

Has anyone ever done something like this? If not, wouldn't it be cool to figure this out and get it documented? Think about it, this method would allow Arduino to RC car communication using only one pin from the Arduino going to a single signal input pin on the RX2 receiver chip. No need to hook up 4 to 5 pins from the Arduino to the RX2 H-Bridge's forward, backward, left, right, turbo pins to control movements.

This would be a fun project and only requires a $5 US cheap Chinese toy car you can find in any store.

Who is up for the challenge?  smiley-cool
« Last Edit: June 11, 2013, 02:41:04 pm by mindprobe » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

After doing some research, it seems Bit-banging Pulse Width Modulation, which apparently allows full control of the duty cycle and frequency, might be a possible way to send a proper signal from the Arduino to the RX2's signal encoder input pin. More ways to send a custom PWM signal are described here (http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM). They are Fast PWM and Phase-Correct PWM.

Does anyone have some ideas how to approach this?
« Last Edit: June 10, 2013, 08:47:07 am by mindprobe » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I managed to connect a small speaker to the TX2 car remote chip SO pin 8 and now I can hear the different PWM pulse signals the buttons forward, reverse, left and right generate. Pretty cool!  smiley-surprise The signal has rougly 1.3 volts when I measure it with a multimeter. I have tried to generate these PWM pulses for the FORWARD command with the Arduino using Bit-banging and when I hook up a speaker to the Arduino, the signals sound identical to TX2 remote signal sounds. With some luck, this generated pulse signal from the Arduino will be understandable by the RX2 in the car and make it controllable. First I will try to connect the TX2 signal output pin 8 directly to the RX2 signal input pin 3. The datasheet of the TX2/RX2 chip has an example testing circuit that does the same, so it should work.

I will keep you guys updated on the progess!
« Last Edit: June 11, 2013, 11:34:17 am by mindprobe » Logged

UK
Offline Offline
Shannon Member
****
Karma: 222
Posts: 12524
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You seem to have presented the problem and identified a viable solution. It seems like a pretty obscure problem so not too surprising that you're the first to tackle it. Why don't you just go ahead and implement your solution?
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The question is, would the Arduino be able to generate the right PWM pulses at the right frequency, speed, stable and at the right voltage and current? I noticed the Arduino PWM signal has 2.6 volts which is twice as much as the signal measured on the TX2 remote (1.3 volts). Is it possible to change the voltage of the signal coming from the Arduino from 2.6 to 1.3 volts using a transistor voltage divider with two transistors of 1Kohm in series or does it not matter what voltage the signal from the Arduino has?

I read something about disabling interrupts, but I don't know what that is or what the difference to bit-banging is. Maybe it's not even needed. Anyone have an idea?
« Last Edit: June 11, 2013, 11:36:54 am by mindprobe » Logged

UK
Offline Offline
Shannon Member
****
Karma: 222
Posts: 12524
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I noticed the Arduino PWM signal has 2.6 volts which is twice as much as the signal measured on the TX2 remote (1.3 volts). Is it possible to change the voltage of the signal coming from the Arduino from 2.6 to 1.3 volts using a transistor voltage divider with two transistors of 1Kohm in series or does it not matter what voltage the signal from the Arduino has?

The Arduino outputs are either 5V or 0V depending whether they're set high or low.

If you need less than 5V you can reduce the voltage using a pair of resistors as a voltage divider.

I don't see any reason why you couldn't generate your output signal entirely in software, using millis() and micros() to determine when the next change is due. I haven't bothered looking at the details of the encoding scheme you describes, but if it's just a digital signal at less than 5V and the highest frequency is only around 1KHz then I don't see any reason why it wouldn't work.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have been able to connect the TX2 pin 8 directly with the RX2 pin 3 to send a communication signal bypassing the antenna completely!  smiley-surprise

Now I will try to send the Arduino generated pulse signal to the RX2.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I got it working!!!  smiley-cool

I can now control the RC car's RX2 receiver chip with just one single pin from the Arduino using pulse signals the RX2 chip can decode and understand. I can fully control the movements of the car. It works absolutely perfect. No need to hook up multiple wires to your RC car robot anymore and no need for the TX2 remote at all. A dream come true. I hope this will bring joy to many people.

Here is the Arduino sketch code:
Code:
void setup()
{
  pinMode(11, OUTPUT);
}

void loop()
{
  for(int i=0; i<=3; i++) // This starts the communication 4 W2 pulses 1KHz 75% duty cycle
  {
    digitalWrite(11, HIGH);
    delayMicroseconds(1500);

    digitalWrite(11, LOW);
    delayMicroseconds(500);
  }
  for(int i=0; i<=9; i++) // This makes the car go "forward" 10 W1 pulses 500Mhz 50% duty cycle
  {
    digitalWrite(11, HIGH);
    delayMicroseconds(500);

    digitalWrite(11, LOW);
    delayMicroseconds(500);
  }
}

Here is a picture of my project:
« Last Edit: June 11, 2013, 02:28:51 pm by mindprobe » Logged

Phoenix, Arizona USA
Offline Offline
Faraday Member
**
Karma: 39
Posts: 5551
Where's the beer?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have to give a huge "bravo" for this; such a hack makes it much easier to hook up and control these vehicles (though you do lose the ability to PWM the drive motor - but that probably isn't much of a loss).

For those coming here, I want to point them to the "mega-thread" on the TX2/RX2 chipset R/C car modding:

http://forum.arduino.cc/index.php/topic,86883.0.html

I'm also going to post a link from there to here, too - all this so things can stay somewhat "together".

Now all that needs to be done is for someone to make a library (hint, hint)...
Logged

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have to give a huge "bravo" for this; such a hack makes it much easier to hook up and control these vehicles (though you do lose the ability to PWM the drive motor - but that probably isn't much of a loss).

I plan on having the RC car drive at very slow and constant speeds to use it as surveillance bot. Being able to alter the speed and not losing too much torque is required.

Theoretically PWM is still an option. You could simply PWM (delay) the actual pulse signal being send to the RX2 and not even lose any torque on the motor. I will run some tests later today.
« Last Edit: June 12, 2013, 03:29:10 pm by mindprobe » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks mindprobe for posting you code. I had been working on a similar project and solved it using the controller chip hardware registers for PWM timing. I'm a afraid I wouldn't do a good job at explaining in details how the PWM registers code works but Chapter 18 from 'Arduino Cookbook' (O'Reilly) helped a lot there.

I refactored my project using your simpler code and I am very glad to report that it appears that the RX2 chips is more responsive to it.

Anyways, I posted a demo (using the hardware pwm code) of my RX2-based toy being controlled by a few buttons on the Arduino: http://youtu.be/7js6pt2g0ac

The source code for both codes are on github: https://github.com/monsieurDavid/rx2-hacks

Cheers!
Logged

Pages: [1]   Go Up
Jump to: