Skip to content

AltSoftSerial support #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
7 changes: 7 additions & 0 deletions ESP8266.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ ESP8266::ESP8266(SoftwareSerial &uart, uint32_t baud): m_puart(&uart)
m_puart->begin(baud);
rx_empty();
}
#elif defined(ESP8266_USE_ALTSOFT_SERIAL)
ESP8266::ESP8266(AltSoftSerial &uart, uint32_t baud): m_puart(&uart)
{
m_puart->begin(baud);
rx_empty();
}

#else
ESP8266::ESP8266(HardwareSerial &uart, uint32_t baud): m_puart(&uart)
{
Expand Down
18 changes: 18 additions & 0 deletions ESP8266.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@


//#define ESP8266_USE_SOFTWARE_SERIAL
//#define ESP8266_USE_ALTSOFT_SERIAL


#ifdef ESP8266_USE_SOFTWARE_SERIAL
#include "SoftwareSerial.h"
#endif

#ifdef ESP8266_USE_ALTSOFT_SERIAL
#include "AltSoftSerial.h"
#endif

/**
* Provide an easy-to-use way to manipulate ESP8266.
Expand All @@ -48,6 +52,18 @@ class ESP8266 {
* @warning parameter baud depends on the AT firmware. 9600 is an common value.
*/
ESP8266(SoftwareSerial &uart, uint32_t baud = 9600);

#elif defined(ESP8266_USE_ALTSOFT_SERIAL)
/*
* Constuctor.
*
* @param uart - an reference of AltSoftSerial object.
* @param baud - the buad rate to communicate with ESP8266(default:9600).
*
* @warning parameter baud depends on the AT firmware. 9600 is an common value.
*/
ESP8266(AltSoftSerial &uart, uint32_t baud = 9600);

#else /* HardwareSerial */
/*
* Constuctor.
Expand Down Expand Up @@ -459,6 +475,8 @@ class ESP8266 {

#ifdef ESP8266_USE_SOFTWARE_SERIAL
SoftwareSerial *m_puart; /* The UART to communicate with ESP8266 */
#elif defined(ESP8266_USE_ALTSOFT_SERIAL)
AltSoftSerial *m_puart; /* The UART to communicate with ESP8266 */
#else
HardwareSerial *m_puart; /* The UART to communicate with ESP8266 */
#endif
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ After modification, it should be:

#define ESP8266_USE_SOFTWARE_SERIAL

# Using AltSoftSerial

There is a alternative to SoftwareSerial (a.k.a NewSoftSerial).
AltSoftSerial is particularly useful when simultaneous data flows are needed.
https://www.pjrc.com/teensy/td_libs_AltSoftSerial.html

If you want to use AltSoftSerial to communicate with ESP8266, you need to modify
the line in file `ESP8266.h`:

//#define ESP8266_USE_ALTSOFT_SERIAL

After modification, it should be:

#define ESP8266_USE_ALTSOFT_SERIAL

# Hardware Connection

Expand Down