If you are looking for a drop-in replacement for Arduino Serial with a smaller memory footprint follow the procedure outlined below to quickly switch your project to Didel TerSer:
* Add `#include <TerSer.h>` at the top of your sketch or select the library from your Arduino IDE (*Sketch* | *Include Library*)
* Use the either the library function names we provide or define your own function names, for example:
`#define Serialprint(x) Text(x)`
* Search for all occurences or `Serial.print` and replace with `Serialprint`
Voila, you have switched to TerSer and enjoy smaller footprint at less mcu cycles
#### Function aliasing
If you do not like our function/method names, feel free to define names that suit your tastes with i.e.:
`#define Serialprint(x) Text(x)`
`#define Serialprint(x,BIN) Bin8(x)`
`#define Serialprint(x,BIN) Bin16(x)`
`#define Serialprint(x) Dec16(x)`
etc.
### TerSer Installation
Go to library manager in your Arduino IDE and search for 'TerSer'.
### Example comparison between Didel TerSer and Arduino Serial
### Example comparison between Didel TerSer and Arduino Serial
| TerSer | Output TerSer | Output Serial | Arduino Serial |
| TerSer | Output TerSer | Output Serial | Arduino Serial |
If you are looking for a drop-in replacement for Arduino Serial with a smaller memory footprint follow the procedure outlined below to quickly switch your project to Didel TerSer:
* Add `#include <TerSer.h>` at the top of your sketch or select the library from your Arduino IDE (*Sketch* | *Include Library*)
* Use the either the library function names we provide or define your own function names, for example:
`#define Serialprint(x) Text(x)`
* Search for all occurences or `Serial.print` and replace with `Serialprint`
Voila, you have switched to TerSer and enjoy smaller footprint at less mcu cycles
#### Function aliasing
If you do not like our function/method names, feel free to define names that suit your tastes with i.e.:
`#define Serialprint(x) Text(x)`
`#define Serialprint(x,BIN) Bin8(x)`
`#define Serialprint(x,BIN) Bin16(x)`
`#define Serialprint(x) Dec16(x)`
etc.
### TerSer Installation
Go to library manager in your Arduino IDE and search for 'TerSer'.
Alternatively just download the TerSer.h into your sketch folder and include it with:
`#include "TerSer.h"`
### TerSer Limitations
### TerSer Limitations
@ -96,9 +95,27 @@ Dec8(); and Dec16(); use a tricky macro to recognize the signed or unsigned data
Code will be shorter and there will be no limitation if you use Dec8u(any unsigned expr); and
Code will be shorter and there will be no limitation if you use Dec8u(any unsigned expr); and
Dec8s(any signed expr);, same of course Dec16u(); and Dec16s();
Dec8s(any signed expr);, same of course Dec16u(); and Dec16s();
### Code size and timing comparison
#### Baud rate
Code size has been obtained by calling one function at a time, compiler under the usual -0s mode. Size is the difference with the empty file size. TerSer.h can of course be used with setup() and loop(). It add the ~300 bytes Arduino initializations.
The baud rate is hardwired into TerSer.h and is by default set to 9600 bps. The serial speed is configured on the UBRR0 register.
Execution time has been measured with a Nop replacing the SendCar function. The time depends on the baud rate, ~1 ms per character displayed at 9600 bits/s.
```void SetupTerSer() {
UBRR0= 103; // 9600 bits/s
UCSR0B=0x18; // -- -- -- rxe txe -- -- --
UCSR0C=0x06; // set mode: 8 data bits, no parity, 1 stop bit```
If you need another baud rate than 9600 you can adjust the value in the TerSer.h according to the table below:
| Baud rate | UBRR0 register *(@16MHz clock)* |
| ---------- | ---------- |
| 2400 | `UBRR0= 416;` |
| 4800 | `UBRR0= 207;` |
| **9600** | `UBRR0= 103;`*(default)* |
| 19200 | `UBRR0= 51;` |
| 38400 | `UBRR0= 25;` |
| 57600 | `UBRR0= 16;` |
| 115200 | `UBRR0= 6;` |
For more information please see the [ATmega328 Datasheet](http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega48A-PA-88A-PA-168A-PA-328-P-DS-DS40002061A.pdf) *(page 182)*.
### Function reference
### Function reference
@ -107,7 +124,7 @@ Execution time has been measured with a Nop replacing the SendCar function. The
| Car(cc); | Send code cc to the UART |
| Car(cc); | Send code cc to the UART |
| cc=Get(); | Wait for a key depressed. Use Teraterm, too tricky with Arduino Terminal |
| cc=Get(); | Wait for a key depressed. Use Teraterm, too tricky with Arduino Terminal |
| Text("abcd"); | Send the text and add a space |
| Text("abcd"); | Send the text and add a space |
|Textln("abcd"); | Same with CRLF |
|Textln("abcd"); | Same with CRLF |
| CR(); | Send a CR-LF |
| CR(); | Send a CR-LF |
| Bin8(v); | Display the 8 low bits of the variable v, converted to integers (all add a space) |
| Bin8(v); | Display the 8 low bits of the variable v, converted to integers (all add a space) |
| Bin16(v); | Display the 16 bits of the variable v, with a dot in the middle |
| Bin16(v); | Display the 16 bits of the variable v, with a dot in the middle |