Arduino Forum

Using Arduino => Microcontrollers => Topic started by: liv09 on Sep 18, 2019, 12:20 am

Title: AT TIny 84 Feasability
Post by: liv09 on Sep 18, 2019, 12:20 am
I am attempting to use an ATtiny84 to input serial data from a water flow sensor. This data will then be transmitted via bluetooth to an app on my phone which will then show the amount of water being used. Is the ATtiny 84 a good choice to accomplish this? I am starting to question my choice of chip from all of the forums I have already read through. Any guidance on where to start with this project would really help. I have found the same sensor being used directly with the arduino and similar bluetooth projects also using the arduino directly, but I would like to continue using the ardunio as an ISP to complete this project.
Title: Re: AT TIny 84 Feasability
Post by: CrossRoads on Sep 18, 2019, 12:38 am
Seems like a poor choice of chip.
Low on IO, only 9 pins -  need 4 for SPI, 2 for water sensor serial, 2 for bluetooth serial, only leaves 1 for anything else.
Low on serial ports, sorta has 1:
"The Universal Serial Interface (USI), provides the basic hardware resources needed for serial
communication. Combined with a minimum of control software, the USI allows significantly
higher transfer rates and uses less code space than solutions based on software only. Interrupts
are included to minimize the processor load."
Low on SRAM and flash memory, 512 bytes and 8 kbytes.

You could try it, and when you run out of memory, move to a bigger chip to continue your programming.

The 
Title: Re: AT TIny 84 Feasability
Post by: jremington on Sep 18, 2019, 01:44 am
If the water sensor is just a switch, for example counting liters or gallons, and you use a Bluetooth wireless serial (https://www.amazon.com/Bluetooth-Wireless-Serial-Transceiver-Backplane/dp/B015QQRRY4) module to transmit the data, then that chip would be fine. Even an ATtiny13 would work.

You can bit-bang TTL serial (i.e. use software serial). Total I/O pins required = 2 if transmit only.
Title: Re: AT TIny 84 Feasability
Post by: DrAzzy on Sep 18, 2019, 04:29 am
Bad choice. Your application likely needs 2 serial ports (bluetooth and sensor), the tiny84 has none, and more than one software serial port is inadvisable.

The 841 might be what you want, assuming you write your code tightly enough to fit in 8k... it's a pin compatible part, but has better peripherals (2 serial ports, another 16-bit timer, more adc pins) (but isn't available in the throughhole package)
Title: Re: AT TIny 84 Feasability
Post by: jremington on Sep 18, 2019, 04:46 am
Few water flow sensors have a serial port (most are just a switch), but the OP needs to tell us what they have selected.
Title: Re: AT TIny 84 Feasability
Post by: 6v6gt on Sep 18, 2019, 03:08 pm
Interestingly, even with LTO enabled, the ATtiny841 appears to use 80bytes more RAM than the ATtiny84 for the same simple sketch:

Code: [Select]

void setup() {
  Serial.begin(9600) ;
  Serial.print(F("hello world") ) ;
}

void loop() {
}


ATtiny84:     79 Bytes
ATTiny841: 159 Bytes
Core: Spence Konde 1.1.4
Title: Re: AT TIny 84 Feasability
Post by: DrAzzy on Sep 19, 2019, 01:52 am
Will investigate why it's so much (assuming it reproduces on current version), thanks for bringing that to my attention.

That is an *ancient* version of my core though; we are up to 1.3.2... strongly suggest updating!
Title: Re: AT TIny 84 Feasability
Post by: 6v6gt on Sep 19, 2019, 11:04 am
Will investigate why it's so much (assuming it reproduces on current version), thanks for bringing that to my attention.

That is an *ancient* version of my core though; we are up to 1.3.2... strongly suggest updating!
I've just done an upgrade Arduino IDE version 1.8.9 and your ATtinyCore 1.3.1 which I had been putting off for a long time. I thought I would lie low until the tales of segmentation faults etc. with the some newer IDE died down a bit.
Anyway, the results are better now but still perhaps enough to force someone to use the ATtiny84 instead of the ATtiny841
ATtiny84:     79 Bytes (as before)
ATTiny841: 128Bytes (was 159 Bytes with 1.1.4)
Core: Spence Konde 1.3.1
Title: Re: AT TIny 84 Feasability
Post by: westfw on Sep 19, 2019, 12:36 pm
Presumably the 841 has at serial isr buffers for at least one UART...
Title: Re: AT TIny 84 Feasability
Post by: DrAzzy on Sep 19, 2019, 10:36 pm
1.3.1?!

ARGH! I forgot to update the board manager json for 1.3.2! That will be available tonight. 1.3.2 is an important bugfix release - 1.3.0 and 1.3.1 were bad releases - they had problems with some attiny board defs.

Edit: 1.3.2 is now live in board manager.
Title: Re: AT TIny 84 Feasability
Post by: 6v6gt on Sep 20, 2019, 02:36 pm
OK. I've tried 1.3.2. From the RAM usage, it makes no difference.

ATtiny84:     79 Bytes (as before)
ATTiny841: 128Bytes (was 159 Bytes with 1.1.4)
Core: Spence Konde 1.3.2
Title: Re: AT TIny 84 Feasability
Post by: DrAzzy on Sep 20, 2019, 11:15 pm
As I said, I'll look into this.

My making a point of 1.3.2 vs 1.3.1 was more because I wanted to make sure you didn't stay on 1.3.1 and run into the bugs that made several board selections unusable.
Title: Re: AT TIny 84 Feasability
Post by: westfw on Sep 21, 2019, 01:17 am
[ATtiny84]% avr-nm -S --size-sort /tmp/OldArduBuild/*.elf | grep -v ' '
008000aa 00000001 b millis_timer_fract
008000ab 00000004 b millis_timer_millis
008000a6 00000004 b millis_timer_overflow_count
00800060 00000010 d _ZTV18TinySoftwareSerial
00800094 00000012 b Serial
00800070 00000024 b rx_buffer
[ATtiny841] avr-nm -S --size-sort /tmp/OldArduBuild/*.elf | grep -v ' '
0080017b 00000001 b millis_timer_fract
0080017c 00000004 b millis_timer_millis
00800177 00000004 b millis_timer_overflow_count
00800100 00000010 d _ZTV14HardwareSerial
00800158 0000001f b Serial
00800134 00000024 b rx_buffer
00800110 00000024 b rx_buffer1

Title: Re: AT TIny 84 Feasability
Post by: DrAzzy on Sep 21, 2019, 11:14 pm
Thanks for the help (and the incantation - I wasn't aware of that one), westfw!

I've checked in a fix for this, it'll be in 1.3.3 and is in github version now. I just took the copout and pulled in the latest version of HardwareSerial from the official arduino AVR core, and tweaked the buffer size used on the 1634.