Hello, I'm attempting to read the gps time from an Adafruit Ultimate GPS featherwing using an ESP32CAM. It's what my professor gave me to work with so I'm trying my best.
The problem is that the GPS communicates over serial and the Cam doesn't have any serial ports left. (SD card, camera, programmer all use one).
I've been doing some research and I think my possible solution could be one of these:
EspSoftwareSerial but I don't know how to set it up for reading a gps
Serial.swap()?
HardwareSerial somehow? I saw it in this thread:
But I wasn't sure how they got it working.
I'm just trying to get the example code for the GPS working with the ESP32CAM:
#define GPSSerial Serial1
void setup() {
Serial.begin(115200);
while (!Serial) delay(10);
GPSSerial.begin(9600);
}
void loop() {
if (Serial.available()) {
char c = Serial.read();
GPSSerial.write(c);
}
if (GPSSerial.available()) {
char c = GPSSerial.read();
Serial.write(c);
}
}
I'm not sure I understand. Maybe this is too far out of my league.
I'm trying to receive the output from the gps over uart using this example code:
#define GPSSerial Serial1
void setup() {
// make this baud rate fast enough to we aren't waiting on it
Serial.begin(115200);
// wait for hardware serial to appear
while (!Serial) delay(10);
// 9600 baud is the default rate for the Ultimate GPS
GPSSerial.begin(9600);
}
void loop() {
if (Serial.available()) {
char c = Serial.read();
GPSSerial.write(c);
}
if (GPSSerial.available()) {
char c = GPSSerial.read();
Serial.write(c);
}
}
This code looks like it needs to communicate both ways. How do I set it up to only use the U2RXD pin?
Also what is the point of having two Serial ports open in the code? Hopefully I didn't sound too smart in the first post. I'm a complete novice at this. Thanks
If your using the SD card in one-bit mode, which is normal, then pins 12 and 13 on the SD card are not used, althought they are connected to the SD card, so you can try connecting the GPS to those pins with;
Serial2.begin(115200,SERIAL_8N1,12,13);
Avoid using pins 16 and 17, they are used by the PSRAM.
You can use pin 4, although you probably want to remove the white LED to avoind being blinded.
And if your into soldering, you can attach a wire to pine 33, used for the red LED, and use that.
The ESP32 has 3 serial ports, and you can assign almost any free GPIO pins to be RX or TX. You mostly have to be aware of which pins are available, and not already in use with some device, before making the choice. Unfortunately that information depends on the board manufacturer and is scattered in many bits and pieces around the web.
Since the code you posted in #3 does not use the SD card, all of those pins are available.
I got out my ESP32-CAM and verified that this simple serial port transfer code works with either UART 1 or 2, using pins 14 as RX and 15 as TX.
I connected an RS232-USB 3.3V serial adapter to pins 14, 15 and GND, talking to a Windows terminal program as one serial I/O source, and used the serial monitor as the other.
//DEV MODULE selected for ESP32-CAM
// works as expected with UART2, RX=14, TX=15
// same for UART1
#include <HardwareSerial.h>
HardwareSerial SerialPort(1); // use UART1
void setup()
{
Serial.begin(115200);
while (!Serial);
Serial.println("Serial test");
SerialPort.begin(115200, SERIAL_8N1, 14, 15);
}
void loop()
{
while (Serial.available()) {
SerialPort.write(Serial.read());
}
while (SerialPort.available()) {
Serial.write(SerialPort.read());
}
}
Oh, I think my professor got the esp32cam just for the SD card. I don't think I need the camera though. Is there any way I could preserve the SD card functionality along with the GPS?
Not necessarily... as you can see below there are 4 data lines that connect to the SD card (HS2_DATA0-3).
You can however run the SD card in 1-bit mode. If you do this only GPIO2 is used, and you are free to use the other pins. Accessing the card will be slightly slower... but I doubt you'll notice.
Wow, ok. Will I need to include a library for that?
I haven't gotten to that point yet because I've been getting the MD5 error:
"A fatal error occurred: MD5 of file does not match data in flash!
Failed uploading: uploading error: exit status 2"
This happened after uploading a sketch. I've restarted windows, used a different port and everything. Do I need to download python to reset the flash on the ESP32CAM? What's the easiest way? (sorry to go off topic)
"If your using the SD card in one-bit mode, which is normal, then pins 12 and 13 on the SD card are not used, althought they are connected to the SD card."
Pin 12,13 are DAT2, DAT3 on the SD card and not used in 1 bit mode, so whilst they are connected to the SD card they are not used...............