|
| 1 | + |
| 2 | +[](https://github.com/marketplace/actions/arduino_ci) |
| 3 | +[](https://github.com/RobTillaart/SWSerialOut/actions/workflows/arduino-lint.yml) |
| 4 | +[](https://github.com/RobTillaart/SWSerialOut/actions/workflows/jsoncheck.yml) |
| 5 | +[](https://github.com/RobTillaart/SWSerialOut/issues) |
| 6 | + |
| 7 | +[](https://github.com/RobTillaart/SWSerialOut/blob/master/LICENSE) |
| 8 | +[](https://github.com/RobTillaart/SWSerialOut/releases) |
| 9 | +[](https://registry.platformio.org/libraries/robtillaart/SWSerialOut) |
| 10 | + |
| 11 | + |
| 12 | +# SWSerialOut |
| 13 | + |
| 14 | +Arduino library for SWSerialOut, supports only data out (TX). |
| 15 | + |
| 16 | + |
| 17 | +## Description |
| 18 | + |
| 19 | +**Experimental** |
| 20 | + |
| 21 | +SWSerialOut is a library that only implements the transmit function. |
| 22 | +There are devices that do not send back information, or in some cases |
| 23 | +you do not use the "returned" information. |
| 24 | +In those cases there is no need for the receive function, interrupt |
| 25 | +handling, buffers etc. |
| 26 | + |
| 27 | +This is where SWSerialOut comes in, it can only transmit data and does |
| 28 | +that by implementing the **public Stream** interface. |
| 29 | +So its interface is similar to any Stream like Serial or SoftwareSerial, |
| 30 | +as the user can use **print()** and **println()** for al the output. |
| 31 | + |
| 32 | +The input side of the Stream interface, **available()**, **peek()**, |
| 33 | +and **read()** are stubs returning 0. |
| 34 | + |
| 35 | +The library does not need to buffer incoming data, and it does not buffer outgoing data either. Therefore it can be blocking. |
| 36 | +So use the library with care. |
| 37 | + |
| 38 | + |
| 39 | +#### Test |
| 40 | + |
| 41 | +Test are done with example sketch **SWSO_test.ino** et al which |
| 42 | +reads the send data back via hardware Serial. |
| 43 | +The serial pulses, especially baud rates above 19200, will improve |
| 44 | +with a proper pull up resistor e.g. 4K7. |
| 45 | + |
| 46 | +| baud | UNO | ESP32 | other | |
| 47 | +|---------:|:-----:|:-------:|:-------:| |
| 48 | +| 300 | Y | Y | |
| 49 | +| 600 | Y | Y | |
| 50 | +| 1200 | Y | Y | |
| 51 | +| 2400 | Y | Y | |
| 52 | +| 4800 | Y | Y | |
| 53 | +| 7200 | Y | Y | |
| 54 | +| 9600 | Y | Y | |
| 55 | +| 19200 | Y | Y | |
| 56 | +| 38400 | - | Y | |
| 57 | +| 57600 | - | Y | |
| 58 | +| 76800 | - | Y | |
| 59 | +| 100000 | - | Y | |
| 60 | + |
| 61 | + |
| 62 | +Note: the code is not really optimized for any platform (yet). |
| 63 | +So the library will not match the top speed of other software serial implementations. |
| 64 | + |
| 65 | +If you have tested this library with another platform, please let me know by |
| 66 | +opening an issue with the relevant data. |
| 67 | + |
| 68 | + |
| 69 | +#### Related |
| 70 | + |
| 71 | +- https://github.com/RobTillaart/MiniMP3 - minimal version only needs serial out. |
| 72 | + |
| 73 | + |
| 74 | +## Interface |
| 75 | + |
| 76 | +```cpp |
| 77 | +#include "SWSerialOut.h" |
| 78 | +``` |
| 79 | + |
| 80 | +#### Constructor |
| 81 | + |
| 82 | +- **SWSerialOut(uint8_t TXpin)** constructor. |
| 83 | +- **void begin(uint32_t baudRate)** set baud rate (see table above) |
| 84 | +- **void begin(uint32_t baudRate, char \* params)** params implemented. |
| 85 | +however not tested yet. |
| 86 | +The params are range checked. |
| 87 | + |
| 88 | +params is e.g. "8N1" = 8 bit, None parity, 1 stop-bit |
| 89 | + |
| 90 | +| param | value | default | notes | |
| 91 | +|:---------:|:----------|:---------:|:--------| |
| 92 | +| bit | 5,6,7,8 | 8 | to be tested |
| 93 | +| parity | N,E,O,S,M | N | to be tested |
| 94 | +| stop bits | 0,1,2,3 | 1 | to be tested |
| 95 | + |
| 96 | + |
| 97 | +#### Stream interface |
| 98 | + |
| 99 | +The SWSerialOut implements the **public Stream** interface, so |
| 100 | +it will support the following functions (indirect from Print): |
| 101 | + |
| 102 | +- **size_t write(char c)** idem. |
| 103 | +- **size_t print(...)** idem. |
| 104 | +- **size_t println(...)** idem. |
| 105 | + |
| 106 | +The input functions are stubs, just returning 0. |
| 107 | + |
| 108 | + |
| 109 | +#### Interrupts |
| 110 | + |
| 111 | +To have a more constant timing while sending the bits one can disable |
| 112 | +interrupts during the transfer of the data. |
| 113 | + |
| 114 | +- **void disableInterrupts(bool b)** enable/disable interrupts during send. |
| 115 | + |
| 116 | + |
| 117 | +#### Debug |
| 118 | + |
| 119 | +- **void debug()** dump internal variables. |
| 120 | + |
| 121 | + |
| 122 | +## Future |
| 123 | + |
| 124 | + |
| 125 | +#### Must |
| 126 | + |
| 127 | +- update documentation |
| 128 | +- test bits, parity, stop bits |
| 129 | + |
| 130 | + |
| 131 | +#### Should |
| 132 | + |
| 133 | +- examples |
| 134 | + - performance sketch |
| 135 | + |
| 136 | + |
| 137 | +#### Could |
| 138 | + |
| 139 | +- unit tests? |
| 140 | +- support inverse logic. |
| 141 | +- support 9 bits (low priority) |
| 142 | +- add RTS / CTS handshake? |
| 143 | +- investigate optimized transfer per platform |
| 144 | + - higher baud rates, especially AVR. |
| 145 | + |
| 146 | + |
| 147 | +#### Wont |
| 148 | + |
| 149 | +- read() |
| 150 | +- non blocking version |
| 151 | + |
| 152 | + |
| 153 | +## Support |
| 154 | + |
| 155 | +If you appreciate my libraries, you can support the development and maintenance. |
| 156 | +Improve the quality of the libraries by providing issues and Pull Requests, or |
| 157 | +donate through PayPal or GitHub sponsors. |
| 158 | + |
| 159 | +Thank you, |
| 160 | + |
0 commit comments