Skip to content

Instantly share code, notes, and snippets.

@numpad0
Last active March 9, 2019 17:03
Show Gist options
  • Save numpad0/ef4aca084bf8163134ec00098d965267 to your computer and use it in GitHub Desktop.
Save numpad0/ef4aca084bf8163134ec00098d965267 to your computer and use it in GitHub Desktop.
Combined version of https://github.com/monsieurDavid/rx2-hacks and https://github.com/dimircea/RX2-TX2-RC and a midnight hour with an oscilloscope
/**
* Control Realtek RX2 (RX2 -G) RC Receiver with Arduino
*
* @author Mircea Diaconescu, Octomber 28, 2013
* @source https://github.com/dimircea/
* GPL v3 License
*
* Many cheap RC toys are based on TX2 / RX2 transmitter / receiver ICs.
* This Arduino sketch allows to replace the TX2 based Remote Control with Arduino.
* Just one single pin is used from the Arduino board.
*
* Connect Arduino pin 10 to the solder point where the toy antenna is connected or to the toy antenna cable.
* One can replace pin 10 with other free digital pin available on the Arduino board.
*
* TX-2B/RX-2B datasheet: http://www.datasheetarchive.com/dl/Datasheet-035/DSA0017137.pdf
*/
/*
Edited by @numpad0 2019/03/10
Tested in combination of an Arduino Uno R3 and second-sourced chip marked (RL) RLRX2
Magic numbers were tuned using oscilloscope for my Uno R3 but shoudldn't be far off for yours
Note: This can NOT be modified further to create a command spam pseudo pwm for smooth steering.
It's just not possible because command sequence takes 15+ ms and steering returns well within that time.
Hack off the chip and solder your own solution if that's what you're looking for.
*/
/*
About command format
|< Start code or "W2" >|< Command code or "W1" >|< Start code > |
1110 1110 1110 1110 1010101010...1010101010 1110 1110 1110 1110
- 1 bit = 500us. Datasheet says 500Hz 75% duty... no just 1110 @ 1kHz.
- Actual signals are not to be spaced. 1110111010101010...
- Command code table defines number of repetition of 10 for each commands. Endcode = 10101010.
*/
/** Functions (aka W1) - as defined by the IC datasheet */
#define COMMAND_ENDCODE 4
#define COMMAND_FORWARD 10
#define COMMAND_FORWARD_TURBO 16
#define COMMAND_TURBO 22
#define COMMAND_FORWARD_LEFT 28
#define COMMAND_FORWARD_RIGHT 34
#define COMMAND_BACKWARD 40
#define COMMAND_BACKWARD_RIGHT 46
#define COMMAND_BACKWARD_LEFT 52
#define COMMAND_LEFT 58
#define COMMAND_RIGHT 64
//output pins
#define ANTENNA 10
unsigned long currentMicros = 0;
/** Initialize the Arduino data and pin */
void setup() {
pinMode( ANTENNA, OUTPUT);
pinMode( 13, OUTPUT);
digitalWrite(13, HIGH);
}
/** Loop code */
void loop() {
// add here your commands to control the RX2 module...
// Double startcode, reduces desync
startcode();
for(int i=0; i<1000;i++){
startcode();
trigger( COMMAND_LEFT);
}
}
void startcode(){
//start code sequence
for (int w2 = 0; w2 < 4; w2++) {
currentMicros = micros();
while (micros() - currentMicros < 1480) {
digitalWrite(ANTENNA, HIGH);
}
while (micros() - currentMicros < 1970) {
digitalWrite(ANTENNA, LOW);
}
}
}
void trigger(int mode) {
//function code sequence
for (int w1 = 0; w1 < mode; w1++) {
currentMicros = micros();
while (micros() - currentMicros < 490) {
digitalWrite(ANTENNA, HIGH);
}
while (micros() - currentMicros < 990) {
digitalWrite(ANTENNA, LOW);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment