Hi everyone,
I'm working on a GPS project. Here my GPS is connected to Arduino NANO and getting Date Time information. Then I tried to sending those data to ESP8266 via I2C communication. I used I2C because I'm hoping to connect two Arduino to ESP8266 and ESP8266 haven't two UARTs. So I used this sketch in my Arduino NANO and got some result.
#include <Wire.h>
#include "SparkFun_Ublox_Arduino_Library.h"
SFE_UBLOX_GPS myGPS;
#include <SoftwareSerial.h>
SoftwareSerial mySerial(4, 3);
long lastTime = 0;
void setup()
{
Serial.begin(115200);
while (!Serial);
Serial.println("SparkFun Ublox Example");
do {
Serial.println("GPS: trying 38400 baud");
mySerial.begin(38400);
if (myGPS.begin(mySerial) == true) break;
delay(100);
Serial.println("GPS: trying 9600 baud");
mySerial.begin(9600);
if (myGPS.begin(mySerial) == true) {
Serial.println("GPS: connected at 9600 baud, switching to 38400");
myGPS.setSerialRate(38400);
delay(100);
} else {
delay(2000);
}
} while (1);
Serial.println("GPS serial connected");
myGPS.setUART1Output(COM_TYPE_UBX);
myGPS.saveConfiguration();
Wire.begin(8);
}
void loop()
{
if (millis() - lastTime > 500)
{
lastTime = millis();
long TOW = myGPS.getTimeOfWeek();
int Year = myGPS.getYear();
int Month = myGPS.getMonth();
int Day = myGPS.getDay();
int Hour = myGPS.getHour();
int Min = myGPS.getMinute();
int Second = myGPS.getSecond();
Serial.print(Year);
Serial.print(",");
Serial.print(Month);
Serial.print(",");
Serial.print(Day);
Serial.print(",");
Serial.print(Hour);
Serial.print(",");
Serial.print(Min);
Serial.print(",");
Serial.print(Second);
Serial.print(",");
Serial.print(TOW);
Wire.write(Year);
Wire.write(",");
Wire.write(Month);
Wire.write(",");
Wire.write(Day);
Wire.write(",");
Wire.write(Hour);
Wire.write(",");
Wire.write(Min);
Wire.write(",");
Wire.write(Second);
Wire.write(",");
Wire.write(TOW);
Serial.println();
}
}
In my Arduino Serial monitor I got this results,
2022,10,10,12,38,38,131936000
2022,10,10,12,38,38,131936200
Then in my ESP8266 I used this sketch to receive data.
#include <Wire.h>
void setup() {
Serial.begin(9600);
Wire.begin(D1, D2);
}
void loop() {
Wire.requestFrom(8,10);
while(Wire.available()){
char c = Wire.read();
Serial.print(c);
}
Serial.println();
delay(100);
}
But I couldn't get better result and my Serial monitor like this,
⸮⸮⸮⸮⸮⸮⸮⸮⸮
⸮⸮⸮⸮⸮⸮⸮⸮⸮
⸮⸮⸮⸮⸮⸮⸮⸮⸮
I tried several times but I couldn't get better result same as my Arduino Serial output. So how can I solve this. Please give me some help.
Thank You.
