// If I use SPI and UART at the same time, it causes a reboot
// https://forum.arduino.cc/t/if-i-use-spi-and-uart-at-the-same-time-it-causes-a-reboot/1416885
// https://www.youtube.com/watch?v=A00CvNi1rzQ
// https://github.com/upiir/arduino_temperature_gauge
#include <SPI.h>
#include <MFRC522.h>
#include <TFT_eSPI.h>
#include <math.h>
#include <TinyGPSPlus.h>
#define SIM800_RX 18 // RX ESP32 -> TX del SIM800
#define SIM800_TX 17 // TX ESP32 -> RX del SIM800
#define NEO6M_RX 41 // RX ESP32 -> TX del SIM800
#define NEO6M_TX 42 // TX ESP32 -> RX del SIM800
#define SS_LECTOR 38
#define RST_LECTOR 4
TinyGPSPlus gps;
MFRC522 rfid(SS_LECTOR, RST_LECTOR);
TFT_eSPI tft = TFT_eSPI();
int year;
byte month, day, hour, minute, second, hundredths;
void setup() {
Serial.begin(115200);
Serial1.begin(9600, SERIAL_8N1, SIM800_RX, SIM800_TX); // UART1 SIM800 RX= 18 TX = 17
Serial2.begin(9600, SERIAL_8N1, NEO6M_RX, NEO6M_TX); // UART2 for GPS NEO
delay(1000); //IF I DONT PUT THIS DELAY, ESP32 WILL CRASH EVERYTIME!!
SPI.begin(36, 37, 35); // SCK, MISO, MOSI, //START SPI
//rfid.PCD_Init();
//tft.init();
Serial.println("System Ready");
}
void loop() {
if (Serial1.available()) {
char data = Serial1.read();
Serial.write(data);
}
if (Serial.available()) {
Serial1.write(Serial.read());
}
while (Serial2.available() > 0) {
gps.encode(Serial2.read());
}
}