How to parse the GPS live, real-time String variable values strlat1 & strlon1 from the Data Frame of the I2C Slave message received:
Bits of the Master sketch
//Write message to the slave //Wire.println(((strlat1)) + (", ") + ((strlon1)));
Bits of the Slave sketch
//Slave received message from the Master
//snprintf(message, 64, "%lu Packets."); //Wire.slaveWrite((uint8_t )message, strlen(message)); Serial Monitor did print the received Master's message correctly, as sent!!!!
//Slave// Serial.println(strlat1);
//Slave// Serial.println(strlon1);?????? However, never printed the String's variable assigned value, blank???????
Hello Kolaha, I finally got back on track with my post issue. Your suggested sketch changes where incorporated with no problem compiling. However no results parsing the String variables from the folling?
//Libraries I2C Edit on GitHub I2C
//https://espressif-docs.readthedocs-hosted.com/projects/arduino-esp32/en/latest/api/i2c.html#arduino-esp32-i2c-api
#include <SoftwareSerial.h>
#include "Wire.h"
#include "String.h"
#define I2C_DEV_ADDR 0x55//ESP32-Wrover - Hex = 0055 - Dec = 85 - Elecrow ILI9488 3.5 in. TFT display
float flat1, flon1;
String strlat1, strlon1;
void onRequest(){
Wire.print(" Packets.");
Serial.println("onRequest");
}
void onReceive(int len){
while(Wire.available()){
Serial.write(Wire.read());//prints the message to the Serial Monitor!!!!
}
// Serial.println();
}
void setup() {
Serial.begin(115200);
Serial.println("Step_3_I2C_com_with_a_ESP32-Wrover_Slave_Kolaha.ino");
Serial.println("ILI9488 3.5in. ESP32-32 TFT Display");
Serial.println("06_10_2024");
Serial.setDebugOutput(true);
Wire.onReceive(onReceive);
Wire.onRequest(onRequest);
Wire.begin((uint8_t)I2C_DEV_ADDR);
}
void loop() {
#if CONFIG_IDF_TARGET_ESP32
char message[64];
strlat1 = "";
strlon1 = "";
// snprintf(message, 64, "%lu Packets.", i++);
snprintf(message, 64, "%lu Packets.");
Wire.slaveWrite((uint8_t *)message, strlen(message));
// size_t slaveWrite(const unit_t *, size_t);
int i;
for ( i = 0; i < sizeof(message); i++) {
if (message[i] == ',')break;
}
int b;
for ( b = 0; b < i; b++) strlat1 = strlat1 + message[b];
i = i + 2;
for ( b = 0; b < (sizeof(message) - i); b++) strlon1 = strlon1 + message[b + i];
Serial.println("************************************");
Serial.print("strlat1 #1 ");Serial.println(strlat1);
Serial.print("strlon1 #1 ");Serial.println(strlon1);
Serial.println("************************************");
#endif
Serial.println("************************************");
Serial.print("strlat1 #2 ");Serial.println(strlat1);
Serial.print("strlon1 #2 ");Serial.println(strlon1);
Serial.println("************************************");
}type or paste code here
I used your PrtScr>ctrl-V command to attach a screenshot, not sure if it attached the correct screenshot?? How do I select the actual screenshot to attach, the most recent in memory?
Hello Kolaha, here is the Master's sketch that is receiving the live, real-time GPS data and converting it to flat1 & flon1, the converting it to strlat1 & strlon1 to send the message to the Slave:
**//Write message to the slave**
Wire.beginTransmission(I2C_DEV_ADDR);
Wire.println();
Wire.println((strlat1) + (", ") + (strlon1));
My choice to use two micros to do this project is complicated. I have my front end project completed with a pair of TTGO T7 v1.3 micros that are sharing coordinates via LoRa radios and displaying the "distance between" on a I2C 16x2 LCD. Then I decided to convert the display with an ILI9488 3.5 in. TFT Elecrow LCD Display to visualize our positions on off-line maps as we travel the many trails of the Manistee National Forest located in the State of Michigan in the USA. Since the original LCD utilized I2C com and the Elecrow display like wise utilized I2C com, it seemed easier to utilize both micros due to memory considerations. Boy, was I in for an big learning surprise converting from the simple 16x2 LCD to the TFT Display, but I am determined.
The original sketch I found on GitHub worked utilizing Strings, hence I stayed with it.
Wire.println((strlat1) + (", ") + (strlon1)); // Master's sent message
Can I change the code from a float to a String should the function require Strings to pass the coordinates to display the positions on an off-line map?
flat1 = Wire.parseFloat(); // Slave's received parsed data