Pages: [1]   Go Down
Author Topic: attiny85 VirtualWire to Mega2560  (Read 1581 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi!

I'm having some trouble with RF-communication (433MHz) between a attiny85 with 16MHz external oscillator and a Arduino Mega2560.

Receiver (Mega2560)
Code:
#include <VirtualWire.h>

void setup()
{
  // Initialise the IO and ISR
  Serial.begin(115200);
  Serial.println("Setup...");
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  vw_set_ptt_inverted(true);
  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;

    digitalWrite(13, HIGH); // Flash a light to show received good message
    // Message with a good checksum received, dump it.
    Serial.print("Got: ");

    for (i = 0; i < buflen; i++)
    {
      Serial.print(buf[i]);
    }
    Serial.println("");
    digitalWrite(13, LOW);
  }
}

Transmitter
Code:
//Transmitter. Sends integer as 2 bytes once per second

#include <VirtualWire.h>
#undef round

uint16_t data =0;  //the integer to send

void setup()
{   
    vw_set_tx_pin(4);
    vw_setup(); // 2000 Bits per sec
}

void loop()
{
    data +=1;
    uint8_t number[2] ;
    number[0] = data;
    number[1] = data >> 8;  //send 2 bytes
    vw_send(number, 2);
    vw_wait_tx(); // Wait until the whole message is gone
    delay(1000);  //send every second
}

This code works fine when I use another Mega2560 for transmitting, but not with the attiny85. I assume this is some kind of timing error. That's why I use a 16MHz oscillator to the attiny, to match the Mega2560 in speed.

Since I don't yet own an oscilloscope, I connected LED's to the transmitting pin of both the attiny and the Mega2560 and I got some interesting results. It seems like the attiny takes almost a second to transfer the message when the Mega2560 does it in a couple of milliseconds (if even that long).

I had to change two rows in the VirtualWire-library to get it to compile on the attiny
Code:
#ifndef TEST
    // Set up timer1 for a tick every 62.50 microseconds
    // for 2000 bits per sec
    TCCR0A = 0; [b]<--- Changed TCCR1A to TCCR0A[/b]
    TCCR0B = _BV(WGM02) | _BV(CS10); [b]<--- Changed TCCR1B to TCCR0B and WGM12 to WGM02[/b]
    // Caution: special procedures for setting 16 bit regs
    OCR1A = ocr1a;
    // Enable interrupt
#ifdef TIMSK1
    // atmega168
    TIMSK1 |= _BV(OCIE1A);
#else
    // others
    TIMSK |= _BV(OCIE1A);
#endif

#endif

My boards.txt
Code:
attiny85at16.bootloader.low_fuses=0xFF
attiny85at16.bootloader.high_fuses=0xD7
attiny85at16.bootloader.extended_fuses=0xFF
attiny85at16.bootloader.path=empty
attiny85at16.bootloader.file=empty85at8.hex

attiny85at16.bootloader.unlock_bits=0xFF
attiny85at16.bootloader.lock_bits=0xFF

attiny85at16.build.mcu=attiny85
attiny85at16.build.f_cpu=16000000L
attiny85at16.build.core=tiny

What can I do to resolve this? I also tried to get two attiny85 to communicate with each other (both at 16MHz) and it worked fine (but slower than the Mega2560).
Logged

ITALY
Offline Offline
Full Member
***
Karma: 1
Posts: 188
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Torkel, sorry for my bad english. Unfortunately I can' t help you with your trouble, but I have a question for you and you could help me. I' m trying RF-communication between 2 attiny85 with external 16MHZ oscillator using your library modifications. I don' t understand why do you use vw_set_tx_pin(4). In this way I suppose you set pin PB4 (phisically pin n°3) like output for tx. Isn' t this pin used for the oscillator?
Thank you.
Regards.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 209
Posts: 13016
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Does this help...
http://arduino.cc/forum/index.php/topic,63755.0.html

Or this...
http://arduino.cc/forum/index.php/topic,60239.0.html
Logged

ITALY
Offline Offline
Full Member
***
Karma: 1
Posts: 188
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sounds interesting..thank you!
Logged

Pages: [1]   Go Up
Jump to: