Debugging on an ATtiny

Hi,
here I want to report about my experience with debugging on an
ATtiny84 with 16 MHz external clock on a selfmade board.

For debugging on the ATtiny84 I used a 16x2 LCD with I2C interface
because ATtiny84 has no HW UART. But I found that print statements
to this LCD require very long time.

To find a suitable method for debugging I compared HW Serial with
19200 baud, SoftwareSerial with 19200 baud, and LCD with I2C interface
on an Uno (also 16 MHz clock). I tested print statements with 1 and
3 digits, floating point, and a combination of number and string
with following results:

       print(5)	    print(543)	print(3.1415)	print(...)
HW  	21392		125464		177488		    489500
SW  	58832		172772		244196		    549248
LCD 	98292		461780		630288		    1515380

print(...) means "print(iv); print(" U/min");" (iv with 4 digits)
All times are microseconds for 100 print statements in a loop.

I was surprised about the long duration of HW Serial and even LCD.
I had expected much shorter durations.
HW Serial printed to the Serial Monitor and LCD to a connected LCD
display. For SoftwareSerial no Monitor was connected.

Because of the results I decided to use SoftwareSerial on ATtiny84.
To program the ATtiny84 I use a programmer USBasp via ISP connector
on the board. To avoid plugging and unplugging between programming
and testing I selected MISO and MOSI pins as Rx and Tx (pins 5, 6) of
SoftwareSerial. These pins are connected via a plug adapter to a
FTDI board for serial to USB conversion. The overall wiring is shown
in the attached schematic.
schematic

With this setup I can modify sketches, upload them to the controller,
and see the print outputs on the Serial Monitor of my Arduino IDE
without changing any connections.

I tested it with an ATtiny84 but it should work with any ATtiny.

Remark: be aware that SoftwareSerial uses timer1 (16 bit) and may conflict with sketches using timer 1 also.
Meantime I have learned that just typing "Serial.begin(baudrate);" can be used as if a HW UART were onboard. Really the USI HW in the chip is used for that purpose, and no conflicts with using timer 1 will occur.
Posting https://forum.arduino.cc/t/minimizing-flash-ram-use-for-just-hwserial-rx-on-attiny/854526/8 allows to minimize flash and RAM.

Why? The LCD actually sends the content to the LCD in this time frame, while the serial versions just write to a buffer until that buffer is filled and then start to wait until there is space again in the buffer. That in turn means your number are not very useful unfortunately.

The serial interfaces don't care if there's anything connected or not.

As the LCD gets slower if you print more I guess the used controller is not fast enough to handle the input at full speed.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.