I have GPS, SONAR and two BLDC motors connected. I have to send data to my PC. I have radio-link. How can I send this data?

Thread Starter

umerrai1

Joined Mar 29, 2021
233
OT: If we ever meet I expect one of these: Ülker Çikolatalı Gofret. ;)
Sorry for the late reply Sir. I was out of town and didn't see your reply. Now I have downloaded your program will see it.
Chocolates are no problem. I can send it by cargo. But I am impatiently willing to meet you. I don't know where you are in which country. But wherever you are you are the kind person I have ever met in my entire life.
 

Thread Starter

umerrai1

Joined Mar 29, 2021
233
//Add this to the end of the set up

// flush serial inp buffer
while(Serial1.available() > 0) {
char t = Serial1.read();
}
}


// Modify all the Serial Ports to this method, note where clear
// the string is located

Can You please explain this part. Serial ports are modified according to your setup.
 

ericgibbs

Joined Jan 29, 2010
13,273
hi,
For the Clear query.
For the Serial 2,3 Add the GREEN text
Change the Clear text in Serial 2,3 to that as Shown in Serial1 . Marked in RED

Do you follow OK.?
E

if (stringComplete1){
strID=(dataString1.substring(0,1));
// Serial.println(strID);
if (strID == "$"){

Serial.print(dataString1);
File dataFile = SD.open("datalog.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.print(dt);
dataFile.print(" ");
dataFile.print(tm);
dataFile.print(msec);
dataFile.print(",");
dataFile.print(dataString1);
dataFile.close();
} else {
Serial.println("error opening datalog.txt");
} }
// clear the string:
dataString1 = "";
stringComplete1 = false;
strID="";
}

// Serial 2
if (stringComplete2) {
strID=(dataString2.substring(0,1));
// Serial.println(strID);
if (strID == "$"){

Serial.print(dataString2);
File dataFile = SD.open("datalog.txt", FILE_WRITE);
// if the file is available, write to it:

if (dataFile) {
dataFile.print(dt);
dataFile.print(" ");
dataFile.print(tm);
dataFile.print(msec);
dataFile.print(",");
dataFile.println(dataString2);
dataFile.close();
} else {
Serial.println("error opening datalog.txt");
} }
// clear the string:
dataString
2 = "";
stringComplete
2 = false;
strID="";
}
 

Thread Starter

umerrai1

Joined Mar 29, 2021
233
I was only asking about this:

// flush serial inp buffer
while(Serial1.available() > 0) {
char t = Serial1.read();
}
}

Where should I add this?
In the loop or serialevent?
 

ericgibbs

Joined Jan 29, 2010
13,273
hi,
As I said at the end of the void setup

void setup() {
while (!Serial) { }// wait for serial port to connect
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(baud);
Serial1.begin(baud);
Serial2.begin(baud);
Serial3.begin(baud);

Serial.println("Initializing SD card...");

// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("SD card Ready");

if (!rtc.begin())
{
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}

if (!rtc.isrunning()) {
Serial.println("RTC is NOT running, let's set the time!");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
attachInterrupt (0, handleInt, FALLING);
setSQW(0x10);
delay (2000);
pinMode(ledPin, OUTPUT);

// flush serial1 inp buffer
while(Serial1.available() > 0) {
char t = Serial1.read();
}
// flush serial2 inp buffer
while(Serial2.available() > 0) {
char t = Serial2.read();
}
// flush serial3 inp buffer
while(Serial3.available() > 0) {
char t = Serial3.read();

}

}

void loop() {
 

ericgibbs

Joined Jan 29, 2010
13,273
hi,
To avoid any problems, I would advise you use a unique if (strID == "$"){ for each serial port.
eg:
if (strID1== "$"){
if (strID2== "$"){
if (strID3== "$"){

If you do this, don't forget to update ALL the instances of strID

E
 

Thread Starter

umerrai1

Joined Mar 29, 2021
233
Sir tell me one more thing, According to my observations RX0 is not suitable for data logging. Because sometimes it does not log data.
 

ericgibbs

Joined Jan 29, 2010
13,273
hi,
Post a print out of the SD missing RX0 data, so I can see the problem.

BTW: Look at the datalog.txt I have just posted all the Ser1,2 & 3 are saved OK.
E
 

ericgibbs

Joined Jan 29, 2010
13,273
hi,
I have now added Ser0 and so all 4 serial ports are used..OK.

E

Update:
Remember that the Ser0 port is used by the Arduino IDE, so a conflict could occur depending on how you connect and use it.


EESP_ Jun. 14 12.47.png
 
Last edited:

Thread Starter

umerrai1

Joined Mar 29, 2021
233
Yes, it is because of conflict. Sometimes it starts logging data but sometimes it won't. You are not sure whether it is logging data or not when it is not connected to a serial monitor. When I use it nothing is going to save on my SD card.
 

ericgibbs

Joined Jan 29, 2010
13,273
hi,
What is connected to Serial 0 and what is the data message, I need to see a sample of the messages.

Also what is now connected to Ser 1,2,3.??
E
 

ericgibbs

Joined Jan 29, 2010
13,273
hi.
I have it running with all 4 ports OK.

Try to find what is causing your problem in the Sketch or the Arduino, if possible write a fix in the Sketch Code,
E
 
Top