## Lab: Serial Communication between ESP32 and GPS
ESP32 has multiple hardware UARTs, making it ideal for GPS integration without software emulation.
**Required Hardware:**
- NEO6MV2 GPS Module
- ESP32 or ESP32-S3 Development Board
**Wiring:**
| GY-NEO6MV2 | ESP32-S3 |
|------------|----------|
| VCC | 5V |
| GND | GND |
| TX | 1 (RX) |
| RX | 2 (TX) |
**Code:**
```cpp
#include
#include
#define RX 1 // Connect to GPS Module's TX pin
#define TX 2 // Connect to GPS Module's RX pin
#define BAUD_RATE 9600 // Baud rate for GPS Module
HardwareSerial ss(2); // Use UART2
void setup() {
Serial.begin(9600);
ss.begin(BAUD_RATE, SERIAL_8N1, RX, TX); // Initialize the serial port
}
void loop() {
// If there is data in the receive buffer of the hardware serial
while (ss.available() > 0) {
// Read a byte of data from the buffer
char gpsData = ss.read();
// Send the read data to the UNO R3 IDE serial monitor
Serial.write(gpsData);
}
}
```
**Code Explanation:**
- `#include `: For ESP32's native UARTs.
- `HardwareSerial ss(2)`: Selects UART2.
- `ss.begin(BAUD_RATE, SERIAL_8N1, RX, TX)`: Configures 8 data bits, no parity, 1 stop bit.
**Results:** Similar to UNO R3 experiment; view NMEA data in Serial Monitor.
**Related Information:** ESP32 supports up to 3 UARTs, configurable on any GPIO. For power efficiency, use deep sleep modes in battery-powered GPS applications.
- Choosing a selection results in a full page refresh.