433Mhz communication between Arduino Uno and Attiny85

Hello Everyone,

I might need a piece of advice here as I'm little bit stuck.

I am working on a small project where I need utilize attiny85, Uno and 433Mhz transmit/receive modules.
Objective is to send a string (or char array) from Arduino Uno to attiny85. Attiny part is mandatory as I need a smallest form factor possible and power efficiency.

After short surfing, I see there are few choices of libraries, I mostly came across with Manchester and RadioHead(former VirtualWire).

I decided to go for Manchester due to its simplicity and small size.
I have managed to compile successfully the transmitter and receiver part on Attiny85s. I can send char array from Attiny85 and receive it (LED blink) on another Attiny85 (used same exact code as in examples). both are clocked at 1Mhz (8Mhz did not work), 600 baud rate, powered from 5V supply. I got a decent distance as well with antennas attached, I was able to get 99% of messages through several concrete walls between 2nd floor and hallway, ~30 meters, so LoS should have been even better. But when I tried transmitter sketch on Arduino Uno (of course adjusting the pins) - silence, nothing received.
I posted full description of the issue here, but I am afraid it is no longer maintained, I see last commit 2 years ago.

Anyway, this pushed me also to give a try to RadioHead library. I see some difficulties while people try to compile it, that it needs to tune up, very sensitive to clock speed, uses the same timer as for milis(), occupies almost 90% of Attiny85 ram, etc... But I am stuck on compilation part.

I can compile the transmitter code on Arduino Uno, no problems. I noticed that default initialization of RH_ASK driver does not point to PIN 11 and 12 for Tx and Rx as it is described in RadioHead manual. I assumed it as I have around 0 volts on these pins while code is running. Instead I included PIN arguments like RH_ASK driver(2000, 11, 12, 0) and I see small spikes round 1.2volts now. Ok, Arduino part is more or less ready, proceeding with the receiver .

In RadioHead.h I see a comment that tiny core from spencekonde did not go well and they recommended another one. Here’s the list I tried so far:

  1. http://drazzy.com/package_drazzy.com_index.json
  2. https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json >> Recommended by RadioHead team
  3. Google Code Archive - Long-term storage for Google Code Project Hosting.

My problem is, no matter which core I try, I am getting flooded by errors like below(full log attached):
error: 'uint8_t' does not name a type
error: 'NULL' was not declared in this scope
error: 'millis' was not declared in this scope

First thing I tried was adding #include <stdint.h> to my receiver sketch, did not help, same error. Tried to add it to the header files directly where the error was originating from - same thing. I was wondering if SPI declaration was messing things up, but as I read RadioHead docs, it is already taken into consideration for Attinys and should be handled. Perhaps my libraries are not organized well?

At this moment I am wondering if there is any stable supplement to above 2 libraries that I can use on long run? First seems OK but I am afraid I might face support issues once I have final product, second seems more sophisticated but too heavy for my task + I'm stuck on compiling.

I’m using IDE 1.8.12

Perhaps I missed some of the info I should have provided, let me know I will gladly fill in.
For now I'm looking for some advices, maybe any of you had same issues?

thanks
Sergi

error.log.txt (32 KB)

#include <SoftwareSerial.h>

#include <VirtualWire.h>

SoftwareSerial softwareSerial(10, 3, false);

void setup()

{

softwareSerial.begin(38400);

setVirtualWireForRF433Receiver();

}

void setVirtualWireForRF433Receiver()

{

vw_set_ptt_pin(999);

vw_set_ptt_inverted(false);

vw_set_rx_pin(2);

vw_setup(100); // Bits per sec

vw_rx_start();

}

void loop()

{

uint8_t message[1];

uint8_t messageLength = 1; // the size of the message

if (vw_get_message(message, &messageLength))

{

for (int i = 0; i < messageLength; i++)

{

softwareSerial.println((char)message*);*
if ((char)message == 'A')
{
//do something.
}
}
}
}
That works for me with attiny85 8mhz.
Mills() and prescale are modify by libraries i don't remember if virtual or some inherited, but in this project i don't care.
Software serial is used for debugging on port 3 with usttottl.

Thanks

Yes I will be trying VirtualWire as well. Which attiny core you are using?
I hesitated about that as it is sort of discontinued..

Sergi

Hi,
this version Commits · damellis/attiny · GitHub

V 1.0.2.

I recommend VirtualWire. It has no known bugs and does not need support.

It is also much smaller than RadioHead, and therefore more appropriate for small processors like the ATtinys. But check to see which are supported (the ATtiny85 is).

jremington:
But check to see which are supported (the ATtiny85 is).

Hi,
Sergi, i used it : VirtualWire: VirtualWire library for Arduino and other boards

In my project i use an attiny85 and one rf433mhz with a small solar panel (500ma max) to control a parking gate system.
without sleep mode it's working for year.

very small current.

Thanks jremington, Hp9000. I have it in my weekend plan. Will post how it goes.

Short test, 2 news.

Good one: It works. VirtualWire transmitter on Uno, code below

// transmitter.pde
//
// Simple example of how to use VirtualWire to transmit messages
// Implements a simplex (one-way) transmitter with an TX-C1 module
//
// See VirtualWire.h for detailed API docs
// Author: Mike McCauley (mikem@airspayce.com)
// Copyright (C) 2008 Mike McCauley
// $Id: transmitter.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $

#include <VirtualWire.h>

void setup()
{
    Serial.begin(9600);
    Serial.println("setup");
    // Initialise the IO and ISR
    vw_set_ptt_inverted(false); // Required for DR3100
    vw_setup(600);	 // Bits per sec
}

void loop()
{
    const char *msg = "hello";

    digitalWrite(13, true); // Flash a light to show transmitting
    vw_send((uint8_t *)msg, strlen(msg));
    vw_wait_tx(); // Wait until the whole message is gone
    digitalWrite(13, false);
    delay(200);
}

and receiver on Attiny85, with this core , code below:

// receiver.pde
//
// Simple example of how to use VirtualWire to receive messages
// Implements a simplex (one-way) receiver with an Rx-B1 module
//
// See VirtualWire.h for detailed API docs
// Author: Mike McCauley (mikem@airspayce.com)
// Copyright (C) 2008 Mike McCauley
// $Id: receiver.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $

#include <VirtualWire.h>
#define GreenLED 0

void setup()
{
    //Serial.begin(9600);	// Debugging only
    //Serial.println("setup");
      
    digitalWrite(GreenLED, HIGH); // Flash a light to show received good message
    delay(200);
    digitalWrite(GreenLED, LOW);
    delay(200);

    // Initialise the IO and ISR
    vw_set_ptt_inverted(false); // Required for DR3100
    vw_setup(600);	 // Bits per sec
    vw_set_rx_pin(2);
    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 it.
	    //Serial.print("Got: ");
	
	    for (i = 0; i < buflen; i++){
	      //Serial.print(buf[i], HEX);
	      //Serial.print(" ");
	    }
	    //Serial.println("");
      digitalWrite(GreenLED, HIGH); // Flash a light to show received good message
      delay(200);
      digitalWrite(GreenLED, LOW);
    }
}

I can see receiver LED blink while Uno is ON, so at least its catching some signal

Bad news:

  • Timer is widely off on both ends - expected
  • more than 50% of messages are lost
  • distance is less then 5-6 meters even with the antennas and this is LoS, if I move behind a wall - silence. Same hardware was giving above 30m even through multiple walls with Manchester code.
  • LED light is almost invisible (dim), but same LED is bright for blinky code - I think it is also related to timer

I will be experimenting with it more, as I need to get a decent coverage (`100m) and also need the millis() back :slight_smile:

Use balanced dipole antennas (34 cm from tip to tip) as shown below. One antenna lead is connected to RX/TX ground, the other to RX/TX ANT. You should get around 300 meters range.

jremington:
Use balanced dipole antennas (34 cm from tip to tip) as shown below. One antenna lead is connected to RX/TX ground, the other to RX/TX ANT. You should get around 300 meters range.

Thanks, that's a nice piece of advice, I've seen advantages of dipole, but receiver is a small keychain size pager.
I could do it on transmitter/gateway side only, that should help a little bit.

I need to get a decent coverage (`100m)

With a self contained, keyfob sized remote, you cannot expect 100 m range.