Attiny (software) serial communication

Hello guys,

In my latest project, I have two components (GSM and GPS devices) that I need to control through serial communication. This means that I need to reserve in my microcontroller at least 4 GPIO pins for that action.

Now, I would like to know are Attiny85 or Attiny84 able to "help me" control my devices ?
I was reading somewhere that these Attinys do not support two serial communications at once.

Is there anyone here having successfully implemented two serial communications in Attiny controllers?

Thank you in advance for your time and effort.

Sincerely,
Bojan.

Why dont you just go for an atmega328p? I mean, there isnt much difference of size between atmega84 and atmega328p.

Hey Mart,

I know that Atmega328P is able to satisfy my needs. This is my last option. However, I don't like to drive a Ferrari in a first gear! :slight_smile: I mean, I don't want to waste 20 I/O pins and tens of kBs of the program memory. My code is pretty simple. Two serial communications (one hardware and one software or both software serials) and little data processing is everything I need. In addition, these two Attinys are slightly cheaper than Atmega328P.

As soon as I'm sure Attinys can not give me what I want, I will start with Atmega328.

Anyways, thanks for your input.

Sincerely,
Bojan.

What about an attiny 841, which has hardware serial (two of em)?

Though software serial with serial-less tinies should work

Hi DrAzzy,

Attiny841 seems to be a perfect match for my needs.

Just a few things to confirm:

  • Hardware serials are on pins 8, 9 (TXD1, RXD1) and 11, 12 (RXD0, TXD0), right ?

  • Can I use both of them through an Aruino IDE? How can I declare them both in an Arduino sketch?

Thank you very much for your time and useful hints!

Sincerely,
Bojan.

bojankoce:
Hey Mart,

I know that Atmega328P is able to satisfy my needs. This is my last option. However, I don't like to drive a Ferrari in a first gear! :slight_smile: I mean, I don't want to waste 20 I/O pins and tens of kBs of the program memory. My code is pretty simple. Two serial communications (one hardware and one software or both software serials) and little data processing is everything I need. In addition, these two Attinys are slightly cheaper than Atmega328P.

As soon as I'm sure Attinys can not give me what I want, I will start with Atmega328.

Anyways, thanks for your input.

Sincerely,
Bojan.

When the effort and time of trying to use a cheaper piece to its limits exceeds the difference of price of the other option, then one must think about it.
But if you got free time, then its ok.

bojankoce:
Hi DrAzzy,

Attiny841 seems to be a perfect match for my needs.

Just a few things to confirm:

  • Hardware serials are on pins 8, 9 (TXD1, RXD1) and 11, 12 (RXD0, TXD0), right ?

  • Can I use both of them through an Aruino IDE? How can I declare them both in an Arduino sketch?

Thank you very much for your time and useful hints!

Sincerely,
Bojan.

Physical pins 11,12 and 8,9.

If you use my core, they're Serial and Serial1, just like any other Arduino board with two UARTs.

You can get my core from here:
http://drazzy.com/e/tiny841.shtml

mart256:
When the effort and time of trying to use a cheaper piece to its limits exceeds the difference of price of the other option, then one must think about it.
But if you got free time, then its ok.

I agree with you Mart!

The life is full of tradeoffs :slight_smile:
I believe it is worth of investing some initial time and effort trying to find an optimal solution. Especially if there is a chance for a mass production of a device.

Sincerely,
Bojan.

DrAzzy:
Physical pins 11,12 and 8,9.

If you use my core, they're Serial and Serial1, just like any other Arduino board with two UARTs.

You can get my core from here:
ATtiny841 Arduino Core

Thanks DrAzzy,

I will definitely take your suggestion into consideration.

Sincerely,
Bojan.

Cool, yeah - I’ve been loving these parts since I got the core working. That second serial gives them a capability you don’t have on the '328p (also, as you probably saw on that page, the core also supports the 1634.

Is there any special setup required to get the serial ports working with UARTs? I'm probably all mixed up and confused here, but I was trying this simple sketch, and only got nonsense back through the USB serial:

void setup() {
	// put your setup code here, to run once:
	Serial.begin(115200);
	Serial1.begin(115200);
}

void loop() {
	// put your main code here, to run repeatedly:
	Serial.println("ping");
	Serial1.println("pong");
	Serial.flush();
	Serial1.flush();
	delay(5000);
}

I get four characters each time, but they're nonsense.

I'm listening with "screen /dev/cu.usbserial-XXXX 15200" and the same thing using tty.usbserial-XXXX, on OS X 10.10.5.

The ATTiny841 is on a breadboard, powered by a Seeed stuidos "UARTSbee", which has worked fine for me in other projects.

Okay, I managed to solve my own problem: I’m using Elecrab’s ATTiny841 breakout with an external 14.7456MHz crystal.

Why did I pick that crystal? I’m not really sure, but it seemed like a good idea at the time. I want to communicate at 115200 baud, and having a crystal that was a multiple of 115200 sounded like the right thing to do. That’s my story and I’m sticking to it.

So I just added this to boards.txt:

diff --git a/avr/boards.txt b/avr/boards.txt
index c384fd0..5a0da7d 100644
--- a/avr/boards.txt
+++ b/avr/boards.txt
@@ -20,6 +20,10 @@ attinyx41.menu.clock.16external=16 MHz (external)
 attinyx41.menu.clock.16external.bootloader.low_fuses=0xEE
 attinyx41.menu.clock.16external.build.f_cpu=16000000L
 attinyx41.menu.clock.16external.bootloader.file=empty/empty_all.hex
+attinyx41.menu.clock.14external=14.7456 MHz (external)
+attinyx41.menu.clock.14external.bootloader.low_fuses=0xEE
+attinyx41.menu.clock.14external.build.f_cpu=14745600L
+attinyx41.menu.clock.14external.bootloader.file=empty/empty_all.hex
 attinyx41.menu.clock.12external=12 MHz (external)
 attinyx41.menu.clock.12external.bootloader.low_fuses=0xEE
 attinyx41.menu.clock.12external.build.f_cpu=12000000L

This has been submitted as a pull request on GitHub.

Hopefully this helps someone else out there :smiley: