Minimal bit-bang send serial 38400/115200 baud for 1MHz or 115200/230400 baud for 8 or 16MHz ATtiny clock

Overview

Attiny Serial Out

Available as Arduino library "ATtinySerialOut"

Version 2.0.1 - work in progress

License: GPL v3 Installation instructions Commits since latest Build Status Hit Counter

Minimal bit-bang send serial

115200 baud for 1/8/16 MHz ATtiny clock.

Perfect for debugging purposes.

Provides Serial.print / println functions for easy software porting.

Code size is only 76 [email protected] baud or 196 [email protected] baud (including first call).

Provides additional fast printHex() and printlnHex() functions.

Default TX pin is PB2 on a ATtiny85.

Version 2

From this version, ATtinySerialOut.cpp is renamed to ATtinySerialOut.hpp. You should include it once in your main program (.ino file) like done in the examples. I you accidently included it more than once, you will see errors like this:

(.text+0x0): multiple definition of `initTXPin()'
.\ShowInfo.cpp.o (symbol from plugin):(.text+0x0): first defined here

To fix the error, you must rename the include directive in the file mentioned in the error (here: ShowInfo.cpp) from #include "ATtinySerialOut.hpp" to #include "ATtinySerialOut.h".

Compile options / macros for this library

To customize the library to different requirements, there are some compile options / macros available.
Modify it by commenting them out or in, or change the values if applicable. Or define the macro with the -D compiler option for global compile (the latter is not possible with the Arduino IDE, so consider using Sloeber.

Macro Default File Description
TX_PIN PB2 (PA1 for ATtiny87/167) Before #include <TinySerialOut.hpp> The pin to use for transmitting bit bang serial.
USE_PORTB_FOR_TX_PIN disabled Before #include <TinySerialOut.hpp> If defined, port B is used for TX pin for ATtiny87/167.
TINY_SERIAL_DO_NOT_USE_115200BAUD disabled Before #include <TinySerialOut.hpp> To force using other baud rates. The rates are 38400 baud at 1 MHz (which has smaller code size) or 230400 baud at 8/16 MHz.
TINY_SERIAL_INHERIT_FROM_PRINT disabled Before #include <TinySerialOut.hpp> If defined, you can use this class as a replacement for standard Serial as a print class e.g. for functions like void prinInfo(Print *aSerial). Increases program size.

Changing include (*.h) files with Arduino IDE

First, use Sketch > Show Sketch Folder (Ctrl+K).
If you have not yet saved the example as your own sketch, then you are instantly in the right library folder.
Otherwise you have to navigate to the parallel libraries folder and select the library you want to access.
In both cases the library source and include files are located in the libraries src directory.
The modification must be renewed for each new library version!

Modifying compile options with Sloeber IDE

If you are using Sloeber as your IDE, you can easily define global symbols with Properties > Arduino > CompileOptions.
Sloeber settings

Serial functions provided (linefeed is \n instead of \r\n):

    void print(const __FlashStringHelper *aStringPtr);
    void print(const char *aStringPtr);
    void print(char aChar);
    void print(uint8_t aByte, uint8_t aBase = 10);
    void print(int16_t, uint8_t aBase = 10);
    void print(uint16_t aInteger, uint8_t aBase = 10);
    void print(uint32_t aLong, uint8_t aBase = 10);
    void print(uint32_t aLong, uint8_t aBase = 10);
    void print(double aFloat, uint8_t aDigits = 2);

    void printHex(uint8_t aByte); // with 0x prefix

    void println(const __FlashStringHelper *aStringPtr);
    void println(char aChar);
    void println(uint8_t aByte, uint8_t aBase = 10);
    void println(int16_t aInteger, uint8_t aBase = 10);
    void println(uint16_t aInteger, uint8_t aBase = 10);
    void println(int32_t aLong, uint8_t aBase = 10);
    void println(uint32_t aLong, uint8_t aBase = 10);
    void println(double aFloat, uint8_t aDigits = 2);

    void println(void);

Error call of overloaded 'println(fstr_t*)' is ambiguous.

Please use the new Digistump core. Since version 1.2.0, the library is no longer compatible with the old cores supplied by digistump.

OpenWindowAlarm example

This example issues an alarm if the chip sensor detect a falling teperarure and is fully documented here

Revision History

Version 2.0.1 - work in progress

  • Added USE_PORTB_FOR_TX_PIN to allow TX pin on port B for ATtiny87/167.

Version 2.0.0 - 09/2021

  • Renamed ATtinySerialOut.cpp to ATtinySerialOut.hpp => TX pin can be defined in main program.
  • Added symbol TINY_SERIAL_INHERIT_FROM_PRINT - if defined, you can use this class as a replacement for standard Serial as a print class.

Version 1.2.2 - 03/2021

  • Cloned ATtinySerialOut.cpp as ATtinySerialOut.hpp for direct include.
  • Added ATtiny88 support.

Version 1.2.1 - 10/2020

  • Added ATtinyX4 support.

Version 1.2.0 - 7/2020

  • Removed workaround #define __FlashStringHelper fstr_t for old Digispark core < 1.6.8 in order to work with core >= 1.7.0.
  • Added ATtiny167 support.
  • Moved functions from h to cpp file.

Version 1.1.0 - 5/2020

  • Removed symbol TINY_SERIAL_INHERIT_FROM_PRINT and replaced by macro #define Print TinySerialOut
  • Changed int to int16_t and long to int32_t.
  • Use utoa() and ultoa() for uint16_t and uint32_t.

Version 1.0.5 - 3/2020

  • Added function writeCRLF()

Version 1.0.4 - 1/2020

  • Symbol TINY_SERIAL_INHERIT_FROM_PRINT - if defined, you can use this class as a replacement for standard Serial as a print class.
  • Improved all ...Hex() functions.
  • Define FlashStringHelper for digispark.
  • Changed label loop to txloop in write1Start8Data1StopNoParity() for 38400 baud.

Version 1.0.3

  • OpenWindowAlarm example updated.

Version 1.0.2

  • printHex() now using capital letters.
  • Improved OpenWindowAlarm example.

Version 1.0.1

  • Renamed example to be consistent.

Version 1.0.0

Initial Arduino library version.

Remark

C version of serial code is included for better understanding, but assembler version is used. This is because for the C code the timing depends on compiler optimisation switches. You should get the right timing if you compile the C code it with Arduino standard settings or:

avr-g++ -I"C:\arduino\hardware\arduino\avr\cores\arduino" -I"C:\arduino\hardware\arduino\avr\variants\standard" -c -g -w -Os -ffunction-sections -fdata-sections -mmcu=attiny85 -DF_CPU=1000000UL -MMD -o "TinySerialOut.o" "TinySerialOut.cpp"

If you find this library useful, please give it a star.

You might also like...
Satellite clock/decoupled clock estimation and PPP-AR

Cube Cube is a secondary development based on RTKLIB and mainly composed of two modules, satellite clock/decoupled clock estimation (the server end) a

Flutter-Clock-and-Reminder-App - a highly functional clock and reminder app developed on flutter framework.

clock_app A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if thi

A small utility to set the clock on a Hayes Stack Chronograph over its serial port.

chronosync A small utility to set the clock on a Hayes Stack Chronograph over its serial port. Synopsis chronosync [-d] [-s serial speed] serial devi

The function is based on MQTT. When the original serial of ESP8266/ESP32 cannot be used, it can replace serial print.
The function is based on MQTT. When the original serial of ESP8266/ESP32 cannot be used, it can replace serial print.

MqttPrint and MqttMonitor The function is based on MQTT. When the original serial of ESP8266/ESP32 cannot be used, it can replace serial print. MqttPr

Feature-rich C99 library for memory scanning purposes, designed for Windows running machines, meant to work on both 32-bit and 64-bit portable executables. Has a modern C++ wrapper.

memscan Feature-rich C99 library for memory scanning purposes, designed for Windows running machines, meant to work on both 32-bit and 64-bit portable

Bit-Map is a simple bit map.

Bit-Map Bit-Map is a simple bit map. Usage Create a map uint8** bitmap; uint64 map_size = 32; // bit number pfs_create_bitmap(bitmap,

A video input (V4L2) to NDI converter that works with Raspberry Pi (32-bit and 64-bit), and Intel/AMD CPUs

V4L2 to NDI V4L2 to NDI is an application that connects to attached V4L2 devices and encodes the video signal into NDI It uses the NDI library, allowi

COBS framing with implicit run-length-encoding, optimized for data containing statistically a bit more 0 and FF bytes in a row, as data often carry 16, 32 or 64 bit numbers with small values.

TCOBS Table of Contents About The project TCOBS Specification TCOBS code Getting Started 4.1. Prerequisites 4.2. Installation 4.3. Usage in Go 4.3.1.

A minimal C-Compiler for my 16-bit RISC Architecture.

A minimal C-Compiler for my 16-bit RISC Architecture.

Minimal Linux Live (MLL) is a tiny educational Linux distribution, which is designed to be built from scratch by using a collection of automated shell scripts. Minimal Linux Live offers a core environment with just the Linux kernel, GNU C library, and Busybox userland utilities.
Minimal Linux Live (MLL) is a tiny educational Linux distribution, which is designed to be built from scratch by using a collection of automated shell scripts. Minimal Linux Live offers a core environment with just the Linux kernel, GNU C library, and Busybox userland utilities.

Minimal Linux Live (MLL) is a tiny educational Linux distribution, which is designed to be built from scratch by using a collection of automated shell scripts. Minimal Linux Live offers a core environment with just the Linux kernel, GNU C library, and Busybox userland utilities.

Send messages to a LED Matrix display through Telegram. Inspired by a tweet from Smarter Every Day

Send messages to a LED Matrix display through Telegram. Inspired by a tweet from Smarter Every Day

Allows for multiple SwitchBot buttons and curtains to be controlled via MQTT sent to ESP32. ESP32 will send BLE commands to switchbots and return MQTT responses to the broker. Also supports Meter/Temp Sensor

SwitchBot-MQTT-BLE-ESP32 Switchbot local control using ESP32. no switchbot hub used/required. works with any smarthub that supports MQTT https://githu

A Dart package to send native 💬 toasts on Windows. Based on WinToast.
A Dart package to send native 💬 toasts on Windows. Based on WinToast.

desktoasts A Dart package to send native 💬 toasts on Windows. Installation For Flutter dependencies: ... desktoasts: ^0.0.2 For Dart CLI here Sup

HamMessenger is a portable device that uses a ham radio and the APRS protocol as a medium to send and receive text messages.
HamMessenger is a portable device that uses a ham radio and the APRS protocol as a medium to send and receive text messages.

HamMessenger is a portable, battery powered device that runs on a microcontroller and interfaces with an inexpensive ham radio to send and receive text messages and provide position updates using the APRS protocol. Messages and position updates sent via HamMessenger can be viewed on sites such as aprs.fi. HamMessenger messages are NOT encrypted!

Inter-process communication library to enable allocation between processes/threads and send/receive of allocated regions between producers/consumer processes or threads using this ipc buffer.

This is a relatively simple IPC buffer that allows multiple processes and threads to share a dynamic heap allocator, designate "channels" between processes, and share that memory between producer/consumer pairs on those channels.

An AutoHotkey library that enables AHK to send keystrokes by drivers.

An AutoHotkey library that enables AHK to send keystrokes by drivers.

First-up chord-send and tap-and-hold chord repeat extensions to QMK.

Quantum Mechanical Keyboard Firmware This is a keyboard firmware based on the tmk_keyboard firmware with some useful features for Atmel AVR and ARM co

Send virtual keyboard presses in godot on linux/windows

gdvk - Godot Virtual Keyboard Send virtual keyboard presses in godot on linux/windows Please inform me about how my code is shit; I'm new to C++. Comp

Comments
  • Add a way to change the tx pin programmatically

    Add a way to change the tx pin programmatically

    Enhancement: It would be very nice to have a way to change the TX pin without having to change the header file itself e.g., by providing it as a parameter to the initTXPin() method.

    opened by jbaumann 11
  • Question: is it possible to use this via USB

    Question: is it possible to use this via USB

    Hi @ArminJo, this is a great repo! I'm wondering if this is possible to use via USB on digispark tiny, similar to digiCDC library (which doesn't work anymore). Thank you.

    opened by wujiang 1
  • Send ASCII commands to terminal?

    Send ASCII commands to terminal?

    Hi, great work! Is it possible to send from your library a sequence for clear the terminal?

    I want something similar to:

    Serial.write(27);       //ESC command
    Serial.print("[2J");    //clear screen command
    Serial.write(27);
    Serial.print("[H");     //cursor to home command 
    

    But I can't make it work. How can I achieve it?

    Regards!

    opened by EtnasSoft 1
Releases(v2.1.1)
Owner
Armin
Arduino addict. Java programmer in real life.
Armin
ESP32-S2 and CC1101S 433Mhz usb stick to record and send car gates/garages data keys and open stuff

HackZeGarage ESP32-S2 and CC1101S 433Mhz usb stick to record and send car gates/garages data keys and open stuff **HackZeGarage @sulfuroid / Dr CADIC

Dr PhilMorph 5 Mar 16, 2022
Websocket client for Arduino, with fast data send

Websocket client for Arduino, with fast data send This is a simple library that implements a Websocket client running on an Arduino. Rationale For our

Davide Monari 29 Aug 4, 2022
Arduino software emulation of a real-time clock based on the milliseconds timer of the CPU

Clock-Library Arduino software emulation of a real-time clock based on the milliseconds timer of the CPU. The clock works with a resolution of one min

Dirk Ohme 4 Jun 25, 2022
An Arduino library with additions to vanilla Serial.print(). Chainable methods and verbosity levels. Suitable for debug messages.

advancedSerial This library provides some additions to vanilla Serial.print(): 1. Chainable print() and println() methods: // you can chain print() a

Vasily Klenov 17 Dec 13, 2022
Software emulated serial using hardware timers for improved compatibility

AltSoftSerial Library Improved software emulated serial, using hardware timers for precise signal timing and availability of CPU time for other librar

Paul Stoffregen 279 Dec 12, 2022
Easily and asynchronously interact with a serial device requiring call-and-response style commands.

Arduino Managed Serial Device Note This library was formerly less-descriptively named "Arduino Async Duplex" This library allows you to asynchronously

Adam Coddington 20 Nov 20, 2022
Easily and asynchronously interact with a serial device requiring call-and-response style commands.

Arduino Managed Serial Device Note This library was formerly less-descriptively named "Arduino Async Duplex" This library allows you to asynchronously

Adam Coddington 20 Nov 20, 2022
Arduino client for the Serial To TCP Bridge Protocol PC side service

Arduino Serial to TCP Bridge Client Arduino client for the Serial To TCP Bridge Protocol gateway service. Open a TCP connection to a server from the A

Roan Brand 13 Apr 12, 2022
A Wiring/Arduino library to tokenize and parse commands received over a phisical/software serial port or buffer.

A Wiring/Arduino library to tokenize and parse commands received over a phisical/software serial port or buffer.

Guglielmo Braguglia 5 Jun 9, 2022
Serial Data Monitor is a multiplatform (Windows, Linux, Mac, ...) tool to interactively receive/edit/monitor data and send commands to an embedded system via the serial bus

See wiki for full documentation Serial Data Monitor Description Serial Data Monitor is a multiplatform (Windows, Linux, Mac, ...) tool to interactivel

monnoliv 4 Oct 29, 2021