I found some code that works to transmit the required signal to an RX-2B RC receiver, the code works great from my Uno but when I tried to run it from my Yún nothing happens.
The code has definitely uploaded as I tested with an LED and the pin is getting a HIGH voltage written to it.
Does anyone have any idea what the issue might be? Code below.
Thanks.
/**
* 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
*/
/** 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_PIN 9
/** Initialize the Arduino data and pin */
void setup() {
pinMode( ANTENNA_PIN, OUTPUT);
}
/** Loop code */
void loop() {
// add here your commands to control the RX2 module...
// for test purposes, here a continuous forward command is sent
sendCommand( COMMAND_FORWARD);
}
/** Send command to the RX2 IC */
void sendCommand( int command) {
int w1 = 0, w2 = 0;
/** start code sequence 4 x W2, ~625Hz, Duty Cycle 75% */
for ( w2 = 0; w2 < 4; w2++) {
digitalWrite( ANTENNA_PIN, HIGH);
delayMicroseconds( 1200);
digitalWrite( ANTENNA_PIN, LOW);
delayMicroseconds( 400);
}
/** function code sequence, n x W1, ~1.25KHz, Duty Cycle 50% */
for ( w1 = 0; w1 < command; w1++) {
digitalWrite( ANTENNA_PIN, HIGH);
delayMicroseconds( 400);
digitalWrite( ANTENNA_PIN, LOW);
delayMicroseconds( 400);
}
}
-
Note that delayMicroseconds() based timing is only consistent if you disable interrupts, though that would probably lead to intermittent rather than complete failure. It's also not particularly accurate, as the time of intervening operations must be taken into account, too. Your data rate is slow enough that you might be able to use a sound card as an oscilloscope to debug the timing.Chris Stratton– Chris Stratton2015年01月26日 16:46:53 +00:00Commented Jan 26, 2015 at 16:46
-
Thanks for the info Chris, I will disable interrupts and see if it makes a difference. There is other code here link which does a similar job but again doesn't work on the Yun, only the Uno and another variant which I haven't had a chance to try yet linkCillian– Cillian2015年01月26日 17:12:43 +00:00Commented Jan 26, 2015 at 17:12
-
Try the sound card, probing through a .1 - 1uF capacitor, starting with the uno. It will be educational if nothing else.Chris Stratton– Chris Stratton2015年01月26日 17:17:01 +00:00Commented Jan 26, 2015 at 17:17
-
Indeed it would, any resources?Cillian– Cillian2015年01月26日 18:43:23 +00:00Commented Jan 26, 2015 at 18:43
1 Answer 1
A Yun is like a Leonardo with a CPU running GNU/Linux at its side. If your sketch works with a Leonardo, it's likely to work with a Yun.
Uno has a different MCU and thus not every sketch will just work, especially those using the hardware serial. You'll have to convert them.
-
As this bears no relation to the operations performed by the posted code it is at most a comment. It is nowhere near being an answer.Chris Stratton– Chris Stratton2015年01月26日 16:44:32 +00:00Commented Jan 26, 2015 at 16:44