Go Down

Topic: Sychronization in virtuel wire (Read 2 times) previous topic - next topic

PaulS

The VirualWire library uses three pins - 10, 11, and 12 by default. You can change which pins it uses for any of the three functions.

myfaithnka

Forgive me for being a lot ignorant.

I know 12 is default tx,11 is rx.But 10 is a new information,please tell me more.

PaulS

From VirtualWire.h:
Code: [Select]
    // Set the digital IO pin to be for transmit data
    // Defaults to 12
    extern void vw_set_tx_pin(uint8_t pin);

    // Set the digital IO pin to be for receive data
    // Defaults to 11
    extern void vw_set_rx_pin(uint8_t pin);

    // Set the digital IO pin to enable the transmitter (press to talk)
    // Defaults to 10
    extern void vw_set_ptt_pin(uint8_t pin);

CrossRoads

Many of the simple RF RX/Tx devices do not need press to talk, they only send what shows up on the data pins,
so you may not need that for your device.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

PaulS

Quote
so you may not need that for your device.

If you don't set it, though, the default pin (10) will be messed with. You can set it to a non-valid pin number, though, like 99.

CrossRoads

So you got me wondering if I just got lucky with my RF remote control then:

I am using pin 10 as Slave Select with SPI to a MAX7221, I only made these statements for the receiver:
Code: [Select]

  // Initialise the Wireless Receiver IO and ISR
  // set Virtual Wire data input to Pin 9 from 11
  vw_set_rx_pin(9);  // found this in forum 25 Aug 09
  // set the Bits per sec
  vw_setup(2000);
  // Start the receive PLL running
  vw_rx_start();

and only this for the transmitter, with D10 being used as a Column pin for a keypad, and D11/D13 not used.
Code: [Select]

// Initialise the IO and ISR for VirtualWire
  vw_setup(4000);                       // Bits per sec - had to double from 2000 with 8MHz 3.3V Pro-Mini


Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

PaulS

Quote
with D10 being used as a Column pin for a keypad, and D11/D13 not used.

As long as you don't try to read from the keypad while transmitting, you can get away with this. But, how can D11 to D13 not be used, if you are
Quote
with SPI to a MAX7221,

SPI uses 11 to 13, with 10 as the default slave select for many libraries.

CrossRoads

Only the reciever used SPI, hence the reassignment.
Didn't use any library, wrote my own MAX7221 code. Pretty simple, just SPI.transfers.

On the transmitter, code gets interrupted, reads the keypad, transmits. SPI not used, so no Rx/TX pin reassignment.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

myfaithnka

Hi all,

Sorry for late reply.

I never defined pin 10 through any library,so virtual wire may be using it by default.

I am shifting the ptt pin to 15,which is undefined for uno.

I will update soon.



CrossRoads

"I am shifting the ptt pin to 15,which is undefined for uno."
15 is not undefined - it is the same as A1 (A0-A5 = D14-D19).
If you want undefined, I would go for >=20.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

myfaithnka

Dear cross roads,

forgive me if its blunder...

Does it mean I can use the A0-A5 pins just like the others ?

functions like digital write,analog write etc can too be done there ??? 

PaulS

Quote
functions like digital write,analog write etc can too be done there ??? 

digitalWrite() - yes.
analogWrite() - no - none of the analog as digital pins are PWM pins.
pinMode() - yes.

Inferno

Hey myfaithnka can you post your fixed transmitter and receiver code after you fixed your synchronization problem. I am trying to send integer values from two sensors and I am having the same problem you had with the mixed up values, but I can't figure out what is wrong. Thanks in advance.

Go Up