Works on Uno but not on Yún

Hi Folks,

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);
  }
}

Common problem when people says "it works on an Uno but not on a Yun" is that there are pins being used that are different between an Uno and a Leonardo (on which the AVR part of the Yun is based).

Ralf

I have just been messing about with it some more today, and I have finally managed to get it work. Appears that the issue is actually to do with the hardware rather than the code. The Uno seems to have been completing a circuit with only one wire whereas the Yun required a connection to GND.

The UNO was working more like a transmitter, whereas the Yun requires a complete circuit. Strange but it works!

Yeah, you always want to make sure the grounds are connected. So the question isn't really "why doesn't it work with the Yun?" but really "Why did it ever work with the Uno?"

Completely agree ShapeShifter, the code itself implies that the person who wrote it never connected to GND either but that could just be me reading into their comments a bit much.

Does the UNO have the ability to induct a greater load than the Yun?

cilliand:
Completely agree ShapeShifter, the code itself implies that the person who wrote it never connected to GND either but that could just be me reading into their comments a bit much.

Does the UNO have the ability to induct a greater load than the Yun?

@cilliand
The Yun needs to use power different. #1 it has Wifi.

Jesse

ShapeShifter:
Yeah, you always want to make sure the grounds are connected. So the question isn't really "why doesn't it work with the Yun?" but really "Why did it ever work with the Uno?"

+1

Ralf :confused: