RF modules with VirtualWire and ATtiny85 not working

I am trying to use VirtualWire with RF modules and ATtiny85.
My ATtiny85 is working fine. I can run the “blink” example with no trouble.

I also tested the TX and RX modules with two arduinos and it all works OK.

But after uploading the sketch of transmitter to the ATtiny85, nothing happens. The TX does not send anything to the receiver, and the test led keeps turned ON everytime.

I’ve tried with VirtualWire 1.14 and arduino 1.0.5 (i also tried with arduino 1.0.3, 1.0, 0022)
I’ve read that VirtualWire 1.14 supports ATtiny85 so I can’t understand what’s happening.

The RF modules i’m using:

Just one additional comment: if I comment the vw_* commands in the sketch, the led works normally (it goes ON and then OFF after a second).

And here is the code:

For the TX (running in ATtiny85):

#include <VirtualWire.h>

const int led_pin = 0;
const int tx_pin = 1;

void setup()
{
  vw_setup(2000);
  vw_set_ptt_inverted(true);
  vw_set_tx_pin(tx_pin);
   
  pinMode(led_pin, OUTPUT); 
}

void loop()
{
  char msg[7] = {'h','e','l','l','o',' ','#'};

  digitalWrite(led_pin, HIGH); 
  delay(1000);
  
  vw_send((uint8_t *)msg, 7);
  vw_wait_tx(); 
 
  digitalWrite(led_pin, LOW);
  delay(1000); 
}

For the RX (running in Arduino UNO)

#include <VirtualWire.h>

const int led_pin = 0;
const int rx_pin = 11;

void setup()
{
    Serial.begin(9600);	
    Serial.println("setup");
    
	vw_set_rx_pin(rx_pin);
    vw_set_ptt_inverted(true);
    vw_setup(2000);	 

    vw_rx_start();  
}

void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;

    if (vw_get_message(buf, &buflen)) 
    {
		int i;

        digitalWrite(led_pin, HIGH); 
	
		Serial.print("Got: ");
	
		for (i = 0; i < buflen; i++)
		{
			Serial.print(buf[i], HEX);
			Serial.print(" ");
		}
		Serial.println("");
		digitalWrite(led_pin, LOW);
	}
}

Thanks in advance for your help.

This morning I ran into this exact problem myself.

Once the vw_setup() function is reached my indicating LED is left HIGH and no activity occurs on my output pin to the transmitter. I'm using Arduino 1.0.5 and virtual wire 1.16. And all of my efforts seem to work fine on the UNO.

Did you come up with a solution?

I couldn't make it work with VirtualWire. I finnaly did it with MANCHESTER library, it is a bit harder to code than VirtualWire (VW allows to send full text messages, and MANCHESTER only sends int (characters, one by one) but it works OK on ATiny85

Hope it helps.

I've been looking at this library as an alternative.

I'll update if I ever get VW working.

Hi,

I think I am also running into similar problems. I spent now a full evening debugging and for me it is like that:

  • I can send messages, that works very well, also the rest of the code seemed to work.
  • After some debugging I found that actually using Virtualwire on Attiny85 messes up the delay and millis function. The millis function is always returns the same value (1 or so). I guess something with the timers gets messed up by virtualwire.

You could try not using any delays in your code if you can reproduce my problem. Now of course it would be great to know how to resolve the issue. For me this whole low level timer thing is still somewhat magic…

Best,
Tommi

Check out my other post on this topic, I’ve got it working ok.

I am using the script below to transmit integers with virtual wire. Receiving on an UNO. I’m not sure I’m correct in the char array sizing but it works.

/* 

Transmitter on attiny 85

*/

#include <VirtualWire.h>

// LED's
const int ledPin = 0;

int Sensor1Data;

char Sensor1CharMsg[4]; 

void setup() {

 // PinModes 
 // LED 
 pinMode(0,OUTPUT);
 pinMode(1, OUTPUT);

 
 // VirtualWire setup

    vw_set_tx_pin(1);    
    vw_setup(2000);	 // Bits per sec
  

}

void loop() {
  
  // Read and store Sensor 1 data
  Sensor1Data = 45;
  
  // Convert integer data to Char array directly 
  itoa(Sensor1Data,Sensor1CharMsg,10);
  

 
 digitalWrite(ledPin, HIGH); // Turn on a light to show transmitting

  vw_send((uint8_t *)Sensor1CharMsg, strlen(Sensor1CharMsg));
  vw_wait_tx(); // Wait until the whole message is gone
 
   delay(100); 

 digitalWrite(ledPin, LOW); // Turn off a light after transmission
 
 delay(1000); 
 
} // END void loop...
/* 

int Receiver UNO

*/

#include <VirtualWire.h>

// LED's
int ledPin = 13;

// Sensors 
int Sensor1Data;

// RF Transmission container
char Sensor1CharMsg[4]; 

void setup() {
  Serial.begin(9600);
  
  // sets the digital pin as output
  pinMode(ledPin, OUTPUT);      
    
    // VirtualWire 
    // Initialise the IO and ISR
    // Required for DR3100
    //vw_set_ptt_inverted(true); 
    // Bits per sec
    
    vw_setup(2000);     
        vw_set_rx_pin(2);
    // Start the receiver PLL running
    vw_rx_start();       

} // END void setup

void loop(){
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    
    // Non-blocking
    if (vw_get_message(buf, &buflen)) 
    {
    int i;
        // Turn on a light to show received good message 
        digitalWrite(13, true); 
    
        // Message with a good checksum received, dump it. 
        for (i = 0; i < buflen; i++)
    {            
          // Fill Sensor1CharMsg Char array with corresponding 
          // chars from buffer.   
          Sensor1CharMsg[i] = char(buf[i]);
    }
        
        // Null terminate the char array
        // This needs to be done otherwise problems will occur
        // when the incoming messages has less digits than the
        // one before. 
        Sensor1CharMsg[buflen] = '\0';
        
        // Convert Sensor1CharMsg Char array to integer
        Sensor1Data = atoi(Sensor1CharMsg);
        
        
        // DEBUG 
        Serial.print("Sensor 1: ");
        Serial.println(Sensor1Data);
        
        int y;
        for (y=0; y<4;y++){
          Serial.print(Sensor1Data + y);
          Serial.println();
          }
        
        // END DEBUG
                
        // Turn off light to and await next message 
        digitalWrite(13, false);
    }
}