Using ATtiny85 with RadioHead

I am unable to compile without errors the example given in the RadioHead library ask_transmitter when using an ATtiny85.

Under Tools, I get the following

Board:ATtiny25/45/85"
Chip: “ATtiny85”
Clock: “8MHz(internal)”
B:O:D:Levels: B.O.D. Disabled

Programmer “Arduino as ISP”

I hava also successfully burnt the bootloader.

However when I compile it I get the following error messages of which I have only shown some.
The issue appears to be with the Serial.

C:\Users\user\Dropbox\Arduino\libraries\RadioHead\RH_Serial.cpp: In member function ‘virtual bool RH_Serial::available()’:

C:\Users\user\Dropbox\Arduino\libraries\RadioHead\RH_Serial.cpp:36:27: error: invalid use of incomplete type ‘class HardwareSerial’

while (!_rxBufValid &&_serial.available())

^~~~~~~

In file included from C:\Users\user\Dropbox\Arduino\libraries\RadioHead\RH_Serial.cpp:6:0:

C:\Users\user\Dropbox\Arduino\libraries\RadioHead/RH_Serial.h:40:7: note: forward declaration of ‘class HardwareSerial’

class HardwareSerial;

The code is as follows:

// ask_transmitter.pde
// -*- mode: C++ -*-
// Simple example of how to use RadioHead to transmit messages
// with a simple ASK transmitter in a very simple way.
// Implements a simplex (one-way) transmitter with an TX-C1 module

#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile

RH_ASK driver;
// RH_ASK driver(2000, 2, 4, 5); // ESP8266: do not use pin 11
//RH_ASK driver(2000, 4, 3); // 200bps, TX on D3 (pin 2)
void setup()
{
    Serial.begin(9600);    // Debugging only
    if (!driver.init())
         Serial.println("init failed");
}

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

    driver.send((uint8_t *)msg, strlen(msg));
    driver.waitPacketSent();
    delay(200);
}

What am I doing wrong? Hopefully someone will provide an answer.

I think that Arduino does not support the hardware serial port (USI) on the ATtiny85. You can always use some version of software serial.

I don't use RadioHead, but you may need to set a parameter in the library to inform it you are using the ATtiny85.

VirtualWire will work just as well for simple applications and takes up less program memory.

Thanks jremington,

Below is part of the documentation from RH_ASK.h which shows that it can be used with an ATtiny85.
Maybe there is a later library?
I know the settings compile OK when I remove RadioHead from the sketch just to make sure that all was well with the basics.
VirtualWire is probably not an option as the corresponding receiver runs RadioHead (it is using an Arduino Mega) and the ATtiny Tx was planned to replace an Arduino Nano running RadioHead.

/// RH_ASK works with ATTiny85, using Arduino 1.0.5 and tinycore from
/// https://code.google.com/p/arduino-tiny/downloads/detail?name=arduino-tiny-0100-0018.zip
/// Tested with the examples ask_transmitter and ask_receiver on ATTiny85.
/// Caution: The RAM memory requirements on an ATTiny85 are very tight. Even the bare bones
/// ask_transmitter sketch barely fits in eh RAM available on the ATTiny85. Its unlikely to work on
/// smaller ATTinys such as the ATTiny45 etc. If you have wierd behaviour, consider
/// reducing the size of RH_ASK_MAX_PAYLOAD_LEN to the minimum you can work with.
/// Caution: the default internal clock speed on an ATTiny85 is 1MHz. You MUST set the internal clock speed
/// to 8MHz. You can do this with Arduino IDE, tineycore and ArduinoISP by setting the board type to "ATtiny85@8MHz’,
/// setting theProgrammer to ‘Arduino as ISP’ and selecting Tools->Burn Bootloader. This does not actually burn a
/// bootloader into the tiny, it just changes the fuses so the chip runs at 8MHz.
/// If you run the chip at 1MHz, you will get RK_ASK speeds 1/8th of the expected.
///
/// Initialise RH_ASK for ATTiny85 like this:
/// // #include <SPI.h> // comment this out, not needed
/// RH_ASK driver(2000, 4, 3); // 200bps, TX on D3 (pin 2), RX on D4 (pin 3)
/// then:
/// Connect D3 (pin 2) as the output to the transmitter
/// Connect D4 (pin 3) as the input from the receiver.

Maybe there is a later library?

Download the latest from the author's site to be sure.

If the library is trying to use hardware serial, it won't work. Maybe the Arduino boards definition is not correct.

You could also try another Arduino core, see this post: Which core for ATTiny85? - Microcontrollers - Arduino Forum The core maintained by forum member "DrAzzy" has a software serial with the same name as hardware serial (Serial.begin() etc.).

Just a quick test sketch before I start researching your suggestions.

#include <RH_ASK.h>
void setup() {
// put your setup code here, to run once:

}

void loop() {
// put your main code here, to run repeatedly:

}

The above sketch gives me the same compiling errors.

Maybe I should changeover to VirtualWire for both Tx and Rx side or even consider rc-switch.
Not certain whether these would give me as good communication reliability as RadioHead.

I also notice that the “Looking glass” search function in the IDE does not work anymore??

So many questions and possibilities.

I will get back to try your suggestions soon.

Thanks.

The above sketch gives me the same compiling errors.

Of course; the error is in the library, as configured.

For one way message transfer (as in the example you posted), I doubt there is a difference in reliability between VirtualWire and RadioHead. Both use a CRC checksum for message integrity.

Radio is inherently unreliable, and with RadioHead, you have the more complex option of multiple back and forth transmissions with message acknowledging. But you have to use that option to benefit from it.

I found that rc-switch works OK with the ATtiny85 but not RadioHead or VirtualWire.

I am already using RadioHead successfully with the Rx and an Arduino Mega while the TX uses RadioHead and a Arduino Nano so I am reluctant to change both to rc-switch.

My purpose in trying this was to investigate the possible replacement of the Nano with an ATtiny85 for size and lower current use but unfortunately it doesn't compile successfully.

I think I will stick with the Nano Tx as I use a 4060 14 stage ripple counter (with its configured RC oscillator) combined with a 74C02N monostable to generate a pulse which turns on the Nano for about 2.5 seconds every 20 minutes to transmit the information. The 4060 and the 74C02 consume only micro amps of current and hardly add to the overall current drain. I can still get over a year without changing the AAA alkaline battery supply and I can use a stock standard Nano.

Incidently, my background was microwave and other radio frequency design as a professional electronics engineer so I am well aware of reliability in radio communications.

Thanks for your help.

Close to the end of the stuff in post #2 it tells how to modify the constructor to tell it which pins to use for serial on the tiny85. You have that line in your code but it is commented out and you’re using the no parameter constructor. You might try just following the directions.

Did you mean the line

//RH_ASK driver(2000, 4, 3); // 200bps, TX on D3 (pin 2) ???

It makes no difference whether this is uncommented or not as the compile error remains the same.

Incidently in preferences for board manager I have the following which is a side issue but it may throw a light on why the compilation errors occur.

http://arduino.esp8266.com/stable/package_esp8266com_index.json
https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json
http://drazzy.com/package_drazzy.com_index.json

Also, an earlier version of the Arduino may work but I have not tried that approach.
Perhaps I have to modify the library code but that is beyond my capabilities.

Did you also comment out the one that isn't commented out now when you un-commented that one?

(That was hard to say)

RH_ASK driver;

Is that one left in there? This one causes errors.

Download Radiohead 1.92 and and compile the example in “ask_transmitter”. You will find it different to yours. I include the example below which compiles for me without that error but runs into issues with memory size (I did not bother installing other cores to see if one would fit):

// ask_transmitter.pde
// -*- mode: C++ -*-
// Simple example of how to use RadioHead to transmit messages
// with a simple ASK transmitter in a very simple way.
// Implements a simplex (one-way) transmitter with an TX-C1 module
// Tested on Arduino Mega, Duemilanova, Uno, Due, Teensy, ESP-12

#include <RH_ASK.h>
#ifdef RH_HAVE_HARDWARE_SPI
#include <SPI.h> // Not actually used but needed to compile
#endif

//RH_ASK driver;
// RH_ASK driver(2000, 4, 5, 0); // ESP8266 or ESP32: do not use pin 11 or 2
RH_ASK driver(2000, 3, 4, 0); // ATTiny, RX on D3 (pin 2 on attiny85) TX on D4 (pin 3 on attiny85), 

void setup()
{
#ifdef RH_HAVE_SERIAL
    Serial.begin(9600);    // Debugging only
#endif
    if (!driver.init())
#ifdef RH_HAVE_SERIAL
         Serial.println("init failed");
#else
  ;
#endif
}

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

    driver.send((uint8_t *)msg, strlen(msg));
    driver.waitPacketSent();
    delay(200);
}

Just a quick reply to Delta_G

My comments on your comments as follows (a bit easier to say)

I have tried what you suggest - in fact you name it and I have tried it.

I only hope that I haven't done something fundamentally wrong but I don't think so.

Interesting, I had just posted a reply and the "lemming" comment came in and wiped it. Is this normal as I am lucky it was only a few lines?

Anyway, "lemming" I did use that example as shown in my first post but I will check to see what version of RadioHead I am using and ensure I am using Radiohead 1.92

Will get back to you when I clarify this.

Thanks.

Thanks lemming,

That compiles without errors using Radiohead 1.92. So glad as I was beginning to wonder if I had made some fundamental error.

However, as you say low memory is a problem and I will need to check other cores to see if more memory can be obtained.

See below the messages below after compilation.

Sketch uses 4812 bytes (58%) of program storage space. Maximum is 8192 bytes.
Global variables use 423 bytes (82%) of dynamic memory, leaving 89 bytes for local variables. Maximum is 512 bytes.
Low memory available, stability problems may occur.