VirtualWire - Change tx pin?

Hi all-
I have tried my best to figure out how to change the transmit pin value (vw_set_tx_pin()). I am using virtualwire 1.5 library. Everything works fine if I keep the tx out at pin 12 (default), but I cannot get any other output to work. As I will be using 12 for another feature, I really would like to move the tx pin.

There obviously is something I am not doing right.

Here is transmit and receive codes, both working (only on pin 12 of transmitter). You can see where I have commented out the offending (and unworking) reassignment).

I'd really like to move it!!!!

Transmitter

#include <VirtualWire.h>

void setup()
{
pinMode(13, OUTPUT);
vw_setup(2000); // Bits per sec
// extern void vw_set_tx_pin(1); // change tx pin? Won't work???
}
void loop()
{
const char *msg = "NNW 22.0 25.8 25.5"; // A simple
vw_send((uint8_t *)msg, strlen(msg));
digitalWrite(13, HIGH); // set the LED on to show transmitting
delay(40); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(100);
}

Receiver

#include <VirtualWire.h>
void setup()
{
pinMode(13, OUTPUT);
Serial.begin(9600);
Serial.println("setup");
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i;
// Message with a good checksum received, dump HEX
Serial.print("Got: ");
for (i = 0; i < buflen; i++)
{
Serial.print(buf*, BYTE);*
_ Serial.print("");_

  • }*
    _ Serial.println("");_
  • digitalWrite(13, HIGH); // set the LED on*
  • delay(40); // wait for a second*
  • digitalWrite(13, LOW); // set the LED off*
  • delay(40);*
  • }*
    }
    [/quote]

You have change tx pin to pin 1 which connected to FT232, did you use USB that connected to PC? and you code should be like this, without the "extern void"

#include <VirtualWire.h>

void setup()
{
  pinMode(13, OUTPUT);
  vw_setup(2000); // Bits per sec
  vw_set_tx_pin(1); // change tx pin? Won't work???
}
void loop()
{
const char *msg = "NNW 22.0 25.8 25.5";  // A simple 
vw_send((uint8_t *)msg, strlen(msg));
digitalWrite(13, HIGH);   // set the LED on to show transmitting
    delay(40);              // wait for a second
    digitalWrite(13, LOW);    // set the LED off
delay(100);
}

Thanks for the reply, but although it does compile, it doesn't work at any other pin. :frowning:

Yes, I forgot, you need to switch the order

#include <VirtualWire.h>

void setup()
{
  pinMode(13, OUTPUT);
  vw_set_tx_pin(1); // change tx pin? Won't work???
  vw_setup(2000); // Bits per sec
}
void loop()
{
const char *msg = "NNW 22.0 25.8 25.5";  // A simple
vw_send((uint8_t *)msg, strlen(msg));
digitalWrite(13, HIGH);   // set the LED on to show transmitting
    delay(40);              // wait for a second
    digitalWrite(13, LOW);    // set the LED off
delay(100);
}

Thank you Bill! That was the detail! Now, so that I can learn from this, can you tell me why the order caused that to not work?

You have to set the pin first then the setup function will set that pin to the correct input or output.

Thanks. Lesson learned. Hopefully, as I absorb more and more of the finer detail, I will be able to help someone else in the future. THANK YOU!

Lesson learned on setting vw_set_tx_pin (thanks BillHo!):

For those who may be following this, the devil is in the details. It's important to review the library file when you run into issues like this.

The answer I found is within the comments in the VirtualWire.h file, and qouted below:

  • // Initialise the VirtualWire software, to operate at speed bits per second*
    // Call this one in your setup() after any vw_set_* calls