Skip to content

Commit 51e609b

Browse files
author
shennongmin
committed
Support UNO
1 parent 7e1da51 commit 51e609b

File tree

52 files changed

+1699
-1151
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1699
-1151
lines changed

ESP8266.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,19 @@
4141
}\
4242
} while(0)
4343

44-
44+
#ifdef ESP8266_USE_SOFTWARE_SERIAL
45+
ESP8266::ESP8266(SoftwareSerial &uart, uint32_t baud): m_puart(&uart)
46+
{
47+
m_puart->begin(baud);
48+
rx_empty();
49+
}
50+
#else
4551
ESP8266::ESP8266(HardwareSerial &uart, uint32_t baud): m_puart(&uart)
4652
{
4753
m_puart->begin(baud);
4854
rx_empty();
4955
}
56+
#endif
5057

5158
bool ESP8266::kick(void)
5259
{

ESP8266.h

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,33 @@
2323

2424
#include "Arduino.h"
2525

26+
27+
//#define ESP8266_USE_SOFTWARE_SERIAL
28+
29+
30+
#ifdef ESP8266_USE_SOFTWARE_SERIAL
31+
#include "SoftwareSerial.h"
32+
#endif
33+
34+
2635
/**
2736
* Provide an easy-to-use way to manipulate ESP8266.
2837
*/
2938
class ESP8266 {
3039
public:
31-
32-
/**
40+
41+
#ifdef ESP8266_USE_SOFTWARE_SERIAL
42+
/*
43+
* Constuctor.
44+
*
45+
* @param uart - an reference of SoftwareSerial object.
46+
* @param baud - the buad rate to communicate with ESP8266(default:9600).
47+
*
48+
* @warning parameter baud depends on the AT firmware. 9600 is an common value.
49+
*/
50+
ESP8266(SoftwareSerial &uart, uint32_t baud = 9600);
51+
#else /* HardwareSerial */
52+
/*
3353
* Constuctor.
3454
*
3555
* @param uart - an reference of HardwareSerial object.
@@ -38,6 +58,8 @@ class ESP8266 {
3858
* @warning parameter baud depends on the AT firmware. 9600 is an common value.
3959
*/
4060
ESP8266(HardwareSerial &uart, uint32_t baud = 9600);
61+
#endif
62+
4163

4264
/**
4365
* Verify ESP8266 whether live or not.
@@ -415,9 +437,11 @@ class ESP8266 {
415437
* +IPD,id,len:data
416438
*/
417439

418-
440+
#ifdef ESP8266_USE_SOFTWARE_SERIAL
441+
SoftwareSerial *m_puart; /* The UART to communicate with ESP8266 */
442+
#else
419443
HardwareSerial *m_puart; /* The UART to communicate with ESP8266 */
420-
444+
#endif
421445
};
422446

423447
#endif /* #ifndef __ESP8266_H__ */

README.md

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ Offline API documentation can be found under directory
2121

2222
# How to get started
2323

24-
On the home page of API documentation, the tabs of Modules, Classes and Examples
25-
will be useful for Arduino developers.
24+
On the home page of API documentation, the tabs of Examples, Classes and Modules
25+
will be useful for Arduino lovers.
2626

2727
# API List
2828

29-
ESP8266 (HardwareSerial &uart, uint32_t baud=9600) : Constructor
30-
3129
bool kick (void) : Verify ESP8266 whether live or not.
3230
3331
bool restart (void) : Restart ESP8266 by "AT+RST".
@@ -94,32 +92,67 @@ will be useful for Arduino developers.
9492
# Mainboard Requires
9593

9694
- RAM: not less than 2KBytes
97-
- UART: one hardware serial at least
95+
- Serial: one serial (HardwareSerial or SoftwareSerial) at least
9896

9997
# Suppported Mainboards
100-
98+
99+
- Arduino UNO and its derivatives
100+
- Arduino MEGA and its derivatives
101+
- Iteaduino UNO
101102
- WBoard Pro
102-
- MEGA and its derivatives
103+
104+
# Using SoftwareSerial
105+
106+
If you want to use SoftwareSerial to communicate with ESP8266, you need to modify
107+
the line in file `ESP8266.h`:
108+
109+
//#define ESP8266_USE_SOFTWARE_SERIAL
110+
111+
After modification, it should be:
112+
113+
#define ESP8266_USE_SOFTWARE_SERIAL
114+
103115

104116
# Hardware Connection
105117

106118
WeeESP8266 library only needs an uart for hardware connection. All communications
107119
are done via uart. In each example, you must specify the uart used by mainboard
108120
to communicate with ESP8266 flashed AT firmware.
109121

110-
For MEGA and WBoard Pro, Serial1 will be used if you create an object (named wifi)
122+
## MEGA and WBoard Pro
123+
124+
For MEGA and WBoard Pro, `Serial1` will be used if you create an object (named wifi)
111125
of class ESP8266 in your code like this:
112126

113127
#include "ESP8266.h"
114128
ESP8266 wifi(Serial1);
115129

116-
the connection should be like these:
130+
The connection should be like these:
117131

118132
ESP8266_TX->RX1(D19)
119133
ESP8266_RX->TX1(D18)
120134
ESP8266_CH_PD->3.3V
121135
ESP8266_VCC->3.3V
122136
ESP8266_GND->GND
137+
138+
## UNO
139+
140+
To use SoftwareSerial, `mySerial` will be used if you create an object (named wifi)
141+
of class ESP8266 in your code like this:
142+
143+
#include "ESP8266.h"
144+
#include <SoftwareSerial.h>
145+
146+
SoftwareSerial mySerial(3, 2); /* RX:D3, TX:D2 */
147+
ESP8266 wifi(mySerial);
148+
149+
The connection should be like these:
150+
151+
ESP8266_TX->RX(D3)
152+
ESP8266_RX->TX(D2)
153+
ESP8266_CH_PD->3.3V
154+
ESP8266_VCC->3.3V
155+
ESP8266_GND->GND
123156

124157
# Attention
125158

doc/API-html/_connect_wi_fi_8ino-example.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/API-html/_connect_wi_fi_8ino_source.html

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/API-html/_e_s_p8266_8cpp.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)