Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,21 @@
*.exe
*.out
*.app

# VSCode
.vscode

# PlatformIO
.pio

# Arduino
.arduino

# Development files (for testing only, not part of library)
# These files are kept locally for development but not distributed
platformio.ini
src/main.cpp
quick-build.sh
ESP32_README.md
build.sh

178 changes: 138 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,70 @@
# Serial Terminal library for Arduino
# πŸ–₯️ Serial Terminal library for Arduino

This is a universal Serial Terminal library for Arduino to parse ASCII commands and arguments.
This is a universal Serial Terminal library for Arduino to parse ASCII commands and arguments with enhanced features including command history, tab completion, and improved terminal editing capabilities.

![Serial Terminal](https://raw.githubusercontent.com/Erriez/ErriezSerialTerminal/master/extras/ScreenshotSerialTerminal.png)
## πŸ†• What's New in This Version

This enhanced version introduces powerful new features that transform your Arduino serial terminal into a modern, user-friendly command interface. **Command History** allows you to navigate through previously entered commands using arrow keys (↑/↓), while **Tab Completion** provides intelligent command auto-completion when you press the Tab key. The library now supports **larger buffers** (256 bytes vs 32 bytes) and **extended command lengths** (12 characters vs 8 characters), enabling more complex commands and longer argument lists. Enhanced terminal editing includes improved backspace support, better cursor control, and automatic character echoing for a seamless terminal experience. Built-in **history management functions** let you view and clear command history programmatically. All these improvements maintain full backward compatibility with existing code, ensuring your current projects continue to work without any modifications while gaining access to these powerful new capabilities.

## Hardware
<img src="https://raw.githubusercontent.com/peterhtcui/ErriezSerialTerminal/enhanced-features/extras/ScreenshotSerialTerminal.png" alt="Serial Terminal" width="600">


## πŸ”§ Hardware

Any Arduino hardware with a serial port, such as:

Arduino:
* UNO
* Nano
* Micro
* Pro or Pro Mini
* Mega or Mega2560
* Leonardo
**Arduino:**
* 🟦 UNO
* 🟦 Nano
* 🟦 Micro
* 🟦 Pro or Pro Mini
* 🟦 Mega or Mega2560
* 🟦 Leonardo

Other targets:
* DUE
* ESP8266
* ESP32
* SAMD21
* STM32F1
**Other targets:**
* πŸ”΅ DUE
* 🟠 ESP8266
* 🟣 ESP32
* 🟒 SAMD21
* πŸ”΄ STM32F1


## Examples
## πŸ“š Examples

Arduino IDE | Examples | Erriez Serial Terminal |

* [ErriezSerialTerminal](https://github.com/Erriez/ErriezSerialTerminal/blob/master/examples/ErriezSerialTerminal/ErriezSerialTerminal.ino)
* πŸ“– [ErriezSerialTerminal](https://github.com/Erriez/ErriezSerialTerminal/blob/master/examples/ErriezSerialTerminal/ErriezSerialTerminal.ino) - Basic example
* πŸ”„ [ErriezSerialTerminal_EchoAndCallback](https://github.com/Erriez/ErriezSerialTerminal/blob/master/examples/ErriezSerialTerminal_EchoAndCallback/ErriezSerialTerminal_EchoAndCallback.ino) - Advanced example with character echoing
* ⭐ [ErriezSerialTerminal_Enhanced](https://github.com/Erriez/ErriezSerialTerminal/blob/master/examples/ErriezSerialTerminal_Enhanced/ErriezSerialTerminal_Enhanced.ino) - **NEW**: Demonstrates all enhanced features including command history and tab completion


## πŸ“– Documentation

- 🌐 [Online HTML](https://erriez.github.io/ErriezSerialTerminal)
- πŸ“„ [Download PDF](https://github.com/Erriez/ErriezSerialTerminal/raw/master/ErriezSerialTerminal.pdf)


## Documentation
## ✨ Enhanced Features

- [Online HTML](https://erriez.github.io/ErriezSerialTerminal)
- [Download PDF](https://github.com/Erriez/ErriezSerialTerminal/raw/master/ErriezSerialTerminal.pdf)
**πŸ†• NEW in this version:**

* πŸ“œ **Command History**: Navigate through previously entered commands using ↑/↓ arrow keys
* πŸ”„ **Tab Completion**: Auto-complete commands by pressing the Tab key
* ✏️ **Enhanced Terminal Editing**: Better backspace support and line editing capabilities
* πŸ“ˆ **Larger Buffer**: Increased from 32 to 256 bytes for longer commands and more arguments
* πŸ“ **Extended Command Length**: Support for commands up to 12 characters (increased from 8)
* πŸ—‚οΈ **History Management**: Built-in functions to view and clear command history

## Usage
**πŸ–₯️ Terminal Features:**
* ⬆️⬇️ Arrow key navigation for command history
* ⌨️ Tab key for command auto-completion
* ⌫ Enhanced backspace and delete key support
* ✏️ Improved line editing and cursor control
* πŸ”Š Character echoing for better terminal experience

**Initialization**
## πŸš€ Usage

**βš™οΈ Initialization**

Create a Serial Terminal object. This can be initialized with optional newline and delimiter characters.

Expand Down Expand Up @@ -69,7 +93,7 @@ void setup()
digitalWrite(LED_BUILTIN, LOW);
}
```
**Register new commands**
**πŸ“ Register new commands**

Commands must be registered at startup with a corresponding ```callback handler``` . This registers the command only, excluding arguments.

Expand Down Expand Up @@ -113,7 +137,7 @@ void cmdLedOff()
}
```

**Set default handler**
**🎯 Set default handler**

Optional: The default handler will be called when the command is not recognized.

Expand All @@ -134,7 +158,7 @@ void unknownCommand(const char *command)
}
```

**Read from serial port**
**πŸ“‘ Read from serial port**

Read from the serial port in the main loop:

Expand All @@ -146,7 +170,7 @@ void loop()
}
```

**Get next argument**
**➑️ Get next argument**

Get pointer to next argument in serial receive buffer:

Expand All @@ -163,7 +187,7 @@ if (arg != NULL) {
}
```

**Get remaining characters**
**πŸ“„ Get remaining characters**

Get pointer to remaining characters in serial receive buffer:

Expand All @@ -178,7 +202,7 @@ if (arg != NULL) {
}
```

**Clear buffer**
**🧹 Clear buffer**

Optional: The serial receive buffer can be cleared with the following call:

Expand All @@ -187,7 +211,7 @@ term.clearBuffer();
```


**Enable/Disable Character Echoing**
**πŸ”Š Enable/Disable Character Echoing**

Optional: Allow for any entered charecters to be printed back to the Serial interface.
This is useful for terminal programs like PuTTY.
Expand All @@ -198,7 +222,7 @@ term.setSerialEcho(true); //Enable Character Echoing
```


**Set Post Command Handler**
**⚑ Set Post Command Handler**

Optional: Add a function to be called AFTER a command has been handled.

Expand All @@ -218,24 +242,98 @@ void setPostCommandHandler()
}
```

## Library configuration
**πŸ“œ Command History Management**

The library now includes built-in command history functionality:

```c++
void setup()
{
...

// Add commands that can be accessed via history
term.addCommand("history", cmdShowHistory);
term.addCommand("clear", cmdClearHistory);
}

void cmdShowHistory()
{
// Display command history
term.showHistory();
}

void cmdClearHistory()
{
// Clear command history
term.clearHistory();
Serial.println(F("Command history cleared."));
}
```

**✨ Enhanced Terminal Features**

The library automatically provides these enhanced features when character echoing is enabled:

```c++
void setup()
{
...

// Enable character echoing for enhanced features
term.setSerialEcho(true);

// Features automatically available:
// - Arrow key navigation (↑/↓) for command history
// - Tab completion for commands
// - Enhanced backspace and editing
}
```

## βš™οΈ Library configuration

```SerialTerminal.h``` contains the following configuration macro's:

* ```ST_RX_BUFFER_SIZE``` : The default serial receive buffer size is 32 Bytes. This includes the command and arguments, excluding the ```'\0'``` character.
* ```ST_NUM_COMMAND_CHARS```: The default number of command characters is 8 Bytes, excluding the ```'\0'``` character.
**πŸ“ˆ Enhanced Configuration:**
* πŸ“¦ ```ST_RX_BUFFER_SIZE``` : The serial receive buffer size is now **256 Bytes** (increased from 32). This includes the command and arguments, excluding the ```'\0'``` character.
* πŸ“ ```ST_NUM_COMMAND_CHARS```: The number of command characters is now **12 Bytes** (increased from 8), excluding the ```'\0'``` character.

**πŸ†• New Configuration:**
* πŸ“œ ```ST_MAX_HISTORY_ENTRIES```: Maximum number of history entries (default: 20)
* πŸ“„ ```ST_HISTORY_ENTRY_SIZE```: Maximum length of each history entry (default: 128 characters)

**πŸ”„ Legacy Configuration (backward compatible):**
* βœ… All original functionality is preserved
* βœ… Default behavior remains unchanged for existing code


## Library dependencies
## πŸ“¦ Library dependencies

* None.
* ❌ None.


## Library installation
## πŸ“₯ Library installation

Please refer to the [Wiki](https://github.com/Erriez/ErriezArduinoLibrariesAndSketches/wiki) page.


## Other Arduino Libraries and Sketches from Erriez
## πŸ–₯️ Terminal Compatibility

For the best experience with enhanced features, use a terminal emulator that supports:

**πŸ’» Recommended Terminal Emulators:**
* πŸͺŸ **PuTTY** (Windows) - Full support for arrow keys and Tab completion
* 🍎 **Terminal** (macOS) - Native support for all enhanced features
* 🐧 **GNOME Terminal** (Linux) - Complete ANSI escape sequence support
* πŸ”§ **Arduino IDE Serial Monitor** - Basic support (limited arrow key functionality)

**✨ Enhanced Features Requirements:**
* 🎯 ANSI escape sequence support (for arrow key navigation)
* ⌨️ Tab character handling (for command completion)
* πŸ”Š Character echoing capability
* πŸ“ Proper line ending support (CR or LF)

**⚠️ Note:** The Arduino IDE Serial Monitor has limited support for arrow keys. For full enhanced functionality, use a dedicated terminal emulator like PuTTY.

## πŸ”— Other Arduino Libraries and Sketches from Erriez

* [Erriez Libraries and Sketches](https://github.com/Erriez/ErriezArduinoLibrariesAndSketches)
* πŸ“š [Erriez Libraries and Sketches](https://github.com/Erriez/ErriezArduinoLibrariesAndSketches)
Loading