SendOnlySoftwareSerial on ATtiny402

I was keen to know if you can use Nick Gammon’s SendOnlySoftwareSerial as a debug aid on an ATtiny402 as this device only has a few pins.

Well it turns out you can - I had to specify 0 as the TXD pin and this made serial data appear on the default pin PA6 (If you try to specify this as using pin 6 - you get the error "Digital pin is constant, but not a valid pin"

Here’s a working ‘Blinky’ type program and PlatformIO.ini.

// ATtiny402 as test device
// Example code using SendOnlySoftwareSerial by Nick Gammon - uses less flash than Serial.print()
// Warning - if you're using interrupts - beware!

// <>
#include <Arduino.h>
#include <SendOnlySoftwareSerial.h>		// saves a pin for output debug

/*  pin information
  	    	VDD|		 |GND
		TXD PA6|		 |PA3 
   		RXD PA7|		 |PA0 UDIP
	  		PA1|		 |PA2
#define BAUD 38400						// serial comms baud rate
SendOnlySoftwareSerial mySerial (0);	// set up the serial output stream to PA6 - I guess 0 means default ??
void system_init(void);           		// placeholder for compiler - but there's not much initialisation to do for this example 

void setup() {

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

void mcu_init(void)							/* MCU initialization */
	/* On AVR devices all peripherals are enable from power on reset, this
	 * disables all peripherals to save power. Driver shall enable
	 * peripheral if used */

	/* Set all pins to low power mode */
	for (uint8_t i = 0; i < 8; i++) {
		*((uint8_t *)&PORTA + 0x10 + i) |= 1 << PORT_PULLUPEN_bp;
void system_init(){							/* system initialization */
; PlatformIO Project Configuration File
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
; Please visit documentation for the other options and examples

platform = atmelmegaavr
board = ATtiny402
board_build.f_cpu = 20000000L
framework = arduino
upload_speed = 115200
upload_port = COM7
upload_flags =
upload_command = pymcuprog write --erase $UPLOAD_FLAGS --filename $SOURCE

I had to download the library and insert the SendOnlySoftwareSerial.cpp and SendOnlySoftwareSerial.h in the lib folder as per picture below

The compilation / load output is as below

 *  Executing task in folder ATtiny402_SendOnlySoftware_SerialTest: C:\Users\Peter\.platformio\penv\Scripts\platformio.exe run --target upload 

Processing ATtiny402 (platform: atmelmegaavr; board: ATtiny402; framework: arduino)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
PLATFORM: Atmel megaAVR (1.6.0) > ATtiny402        
HARDWARE: ATTINY402 20MHz, 256B RAM, 4KB Flash     
 - framework-arduino-megaavr-megatinycore @ 2.5.11 
 - tool-avrdude-megaavr @ 3.60300.220118 (6.3.0)   
 - toolchain-atmelavr @ 3.70300.220127 (7.3.0)     
LDF: Library Dependency Finder ->
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 16 compatible libraries
Scanning dependencies...
Dependency Graph
|-- SendOnlySoftwareSerial
Building in release mode  
Compiling .pio\build\ATtiny402\src\main.cpp.o
Linking .pio\build\ATtiny402\firmware.elf
Checking size .pio\build\ATtiny402\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  12.1% (used 31 bytes from 256 bytes)
Flash: [===       ]  25.3% (used 1035 bytes from 4096 bytes)
Configuring upload protocol...
AVAILABLE: jtag2updi
CURRENT: upload_protocol = jtag2updi
Looking for upload port...
Using manually specified: COM7
Uploading .pio\build\ATtiny402\firmware.hex
Connecting to SerialUPDI
Pinging device...
Ping response: 1E9227
Erasing device before writing from hex file...
Writing from hex file...
Writing flash...
=============================================================================== [SUCCESS] Took 8.62 seconds ===============================================================================