# 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?

#### umerrai1

Joined Mar 29, 2021
233
OT: If we ever meet I expect one of these: Ülker Çikolatalı Gofret.
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.

#### umerrai1

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

// flush serial inp buffer
while(Serial1.available() > 0) {
}
}

// 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

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="";
}

#### umerrai1

Joined Mar 29, 2021
233

// flush serial inp buffer
while(Serial1.available() > 0) {
}
}

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;
}

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!");
}
attachInterrupt (0, handleInt, FALLING);
setSQW(0x10);
delay (2000);
pinMode(ledPin, OUTPUT);

// flush serial1 inp buffer
while(Serial1.available() > 0) {
}
// flush serial2 inp buffer
while(Serial2.available() > 0) {
}
// flush serial3 inp buffer
while(Serial3.available() > 0) {

}

}

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

#### umerrai1

Joined Mar 29, 2021
233
Respected Sir, The logger is working absolutely fine. Thaaaannnnnkkkk youuuu so much.

#### ericgibbs

Joined Jan 29, 2010
13,273
hi ume,
This Sketch is complete, linked the 3 serial inputs together in order to check the Sketch,
As a check it prints the Serial No:
Also checked the SD all OK.

E

#### Attachments

• 45 KB Views: 2
• 7.3 KB Views: 4
• 9.7 KB Views: 3

#### 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.

E

Last edited:

#### 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.

#### umerrai1

Joined Mar 29, 2021
233
I am not using Serial 0. as it is not giving me good results.

#### 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

#### umerrai1

Joined Mar 29, 2021
233
For just checking I am connecting the echo sounder to all ports.

#### 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

#### umerrai1

Joined Mar 29, 2021
233
I think I am using max232 that is why my Arduino does not work with serial port 0. But sometimes it works. The program is the same as yours.

#### Attachments

• 7.5 KB Views: 3

#### ericgibbs

Joined Jan 29, 2010
13,273
hi,
Show me how the MAX is conneected to Mega and the wiring on the outside of the MAX, what is connected to the MAX. input?
E

#### umerrai1

Joined Mar 29, 2021
233
These are my circuit diagrams. All capacitors are 25v 10uF. I just removed the fourth serial port. So, please ignore it.

#### Attachments

• 80.3 KB Views: 3
• 73.7 KB Views: 3

#### ericgibbs

Joined Jan 29, 2010
13,273
hi,
You have not modified Ser0 correctly, look at this difference!
E