2

I was building a Bluetooth car with attiny85 (Arduino IDE) and HC05 bluetooth module. I need 4 IO pins to control the car. Since attiny have only 5vIO's, I am left with only 1 pin to connect to HC05. I would only be receiving data from HC05. So, I want to use that leftover pin as RxD to receive data.


#include //the software serial library
#define RxD 4

SoftwareSerial blueToothSerial(RxD);

But when I do this It gives the following error


No matching function for call to 'SoftwareSerial::SoftwareSerial(int)'

Though it works fine, when I also define a TxD pin. But I want to use only one pin (RxD). Please help.

1
  • 1
    This constructor SoftwareSerial(rxPin, txPin, inverse_logic) requires two parameters (regarding the pins), and according to the error message, there is not any constructor with only one parameter. You could try to call it with an invalid pin number (e.g. 99) for TX, so if it checks for valid pins it will just skip the initialization of an invalid pin number.
    – Bence Kaulics
    Commented Jun 13, 2016 at 13:14

2 Answers 2

1

I suggest you get rid of SoftwareSerial and use instead this Simple ATtiny USI UART. This is a driver for a receive-only UART that uses the USI port of the ATtiny85. It is superior to a software-only UART as it makes good use of the hardware, leaving more time for the CPU to do more useful things (or sleep and save battery). Also, unlike SoftwareSerial, it does not need to block interrupts for long periods, which is a good thing.

0

The constructor for the SoftwareSerial object expects to be given both a TX and and RX pin (and, optionally, a boolean value representing whether or not it should use inverse logic.) From SoftwareSerial.h, see:

SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic = false);

If you want to use the library in the way you've written, you'll need to either modify the existing constructor or write a new one into the library.

As a quick test, I've added the following lines to each of the listed source files:

SoftwareSerial.h

SoftwareSerial(uint8_t receivePin, bool inverse_logic = false);

SoftwareSerial.cpp

SoftwareSerial::SoftwareSerial(uint8_t receivePin, bool inverse_logic /* = false */) :
_rx_delay_centering(0),
_rx_delay_intrabit(0),
_rx_delay_stopbit(0),
_tx_delay(0),
_buffer_overflow(false),
_inverse_logic(inverse_logic)
{
  setRX(receivePin);
}

Now there's a constructor that allows for a single RX pin argument like you've outlined in your initial example. The problem is that this is likely to break anytime the Arduino codebase gets updated and your changes get blown away.

Best practice may dictate writing your own driver to use the serial functionality of your ATTiny without the possibility of accidentally using the TX functions, but if this is a one-off then maybe Bence Kaulics' suggestion of just feeding it a nonsense pin would be the least time-consuming.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.