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
246
So that is why he is changing every day. I am the only electronics worker here so need every time some help. I am good in circuit designing but my codding is a lot weaker. I am trying to get over it.
 

ericgibbs

Joined Jan 29, 2010
18,766
hi umer,
One hard lesson lesson I learned many years ago, is never accept the responsibility for a project or product development/design , when the client/boss does not give you a written specification.

You have done well so far in producing this project, but if you do not stop adding/changing the specification, you are going to fail, which would be sad.

E
 

Thread Starter

umerrai1

Joined Mar 29, 2021
246
It's all because of your support Sir. Okay, Sir you already told me about this situation. Next time I will be very careful about it. I know I have to face a lot of problems while changing program every time. But the problem is that I cannot say anything to my boss.
 

ericgibbs

Joined Jan 29, 2010
18,766
hi,
When data logging you must consider how you are going use and analyse the raw data.

For example,
tagging every Depth data message with the Date and Time is not necessary.

To know the position where the depth data was recorded is important.

You are using a GPS device which sends out a $GPS position message every precise 1 second.
So you have a very accurate timing signal for the position, the $GPS string is recorded to the SD card.
The 10 or so Depth messages that are recorded to SD must have been logged during that 1 second GPS period. It does not make any sense to tag them with a Date.Time to mSeconds.

Also if you record the GPS position message and Depths to the same datafile, it makes sense when you start to plot and analyse the logged data.

E
 

Thread Starter

umerrai1

Joined Mar 29, 2021
246
Sir, I really appreciate the efforts you are doing for me. But I have to change everything according to Boss orders. Can I ask you some personal question?
 

Ya’akov

Joined Jan 27, 2019
9,070
hi,
When data logging you must consider how you are going use and analyse the raw data.

For example,
tagging every Depth data message with the Date and Time is not necessary.

To know the position where the depth data was recorded is important.

You are using a GPS device which sends out a $GPS position message every precise 1 second.
So you have a very accurate timing signal for the position, the $GPS string is recorded to the SD card.
The 10 or so Depth messages that are recorded to SD must have been logged during that 1 second GPS period. It does not make any sense to tag them with a Date.Time to mSeconds.

Also if you record the GPS position message and Depths to the same datafile, it makes sense when you start to plot and analyse the logged data.

E
Some logging strategies use a specific heartbeat message that can be used to correlate the timing of other log entries.

Arbitrary precision of time stamps doesn’t come free, and careful analysis will show that at some point it becomes false precision.

The design must incorporate the application to make the appropriate engineering trade offs for a functional, efficient, effective outcome.
 

Thread Starter

umerrai1

Joined Mar 29, 2021
246
If I come to UK is there chances to get a job there?
Because here in Turkey we are working 11 hours a day and 6 days a week. our salary is also not good.
I have experience in power electronics, solar manufacturing, and installation and repairing services. also good in circuit designing.
 

ericgibbs

Joined Jan 29, 2010
18,766
hi,
It would depend upon your experience and qualifications.

Have you tried using the AAC Forum for overseas job advice.? Jobs & Career Advising

I
would suggest you post your query on that Forum.

E
 

Thread Starter

umerrai1

Joined Mar 29, 2021
246
Hello Sir, How are you? Hope you are doing great.
I have a little issue with my project.
I made a data logger using mega2560 because I need 3 serial ports. It works very well up to the 9600 baud rate but if you attach something which has a baud rate above 9600 it does not log data clearly. I know I can change the baud rate of GPS but I am wondering why it is not logging data above 9600.
 

ericgibbs

Joined Jan 29, 2010
18,766
hi umer,
We need a sample of the corrupted data print out and the mega .ino file.
E
OT.
All ok here, pleased to hear all is ok with you.
 

Thread Starter

umerrai1

Joined Mar 29, 2021
246
Code:
/*
  ** MEGA MINI **
  ** MOSI - pin 51
  ** MISO - pin 50
  ** CLK - pin 52
  ** CS - pin 53 (for MKRZero SD: SDCARD_SS_PIN)
  ** SDA - pin 20
  ** SCL - pin 21
*/
#include <Wire.h>
#include <EEPROM.h>
#include "math.h"
#include <SPI.h>
#include <SD.h>
#include "RTClib.h"
#define DS1307_CTRL_ID 0x68
RTC_DS1307 rtc;
bool flag = false;
String GPSmessage = "";
const int chipSelect = 53;
String dataString = "";
String dataString1 = "";
String dataString2 = "";
String dataString3 = "";
String strID = "";
String strID1 = "";
String strID2 = "";
String strID3 = "";
bool stringComplete = false;
bool stringComplete1 = false;
bool stringComplete2 = false;
bool stringComplete3 = false;
unsigned long msec;
const int ledPin =  LED_BUILTIN;
int ledState = LOW;
const long interval = 500;


unsigned long CurrentBaudRate = 19200;

unsigned long x = 0;


void setup() {
  //============= SD Card ===============//
  Serial.println("Initializing SD card...");

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

  //============= RTC ===============//
  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, RISING);
  //  setSQW(0x10);
  //  //delay (2000);

  //============= flush serial input buffer ===============//
  while (Serial.available() > 0) {
    char t = Serial.read();
  }
  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();
  }

  while (!Serial) { }// wait for serial port to connect
  Serial.begin(CurrentBaudRate);
  Serial1.begin(CurrentBaudRate);
  Serial2.begin(CurrentBaudRate);
  Serial3.begin(CurrentBaudRate);
  Serial.println(CurrentBaudRate);
}
byte i, second, minute, hour;

void loop() {
  // ===== Reading Date and Time from RTC ============//
  DateTime now = rtc.now();
  char dt[16];
  char tm[16];
  uint8_t thisSec, thisMin, thisHour;
  thisSec = now.second();
  thisMin = now.minute();
  thisHour = now.hour();
  sprintf(dt, "%02d-%02d-%02d", now.year(), now.month(), now.day());
  sprintf(tm, "%02d%02d%02d", now.hour(), now.minute(), now.second());

  //=============== Serial0======================//
  if (stringComplete) {
    strID = (dataString.substring(0, 2));
    if (strID == "$G") {
      Serial.print(dataString);

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

      if (dataFile) {
        dataFile.print(dt);
        dataFile.print(" ");
        dataFile.print(tm);
        dataFile.print(",");
        dataFile.print(dataString);
        dataFile.close();
      }
    }
    else {
      Serial.print(dataString);
      File dataFile = SD.open("s0eslog.txt", FILE_WRITE);
      // if the file is available, write to it:

      if (dataFile) {
        dataFile.print(dt);
        dataFile.print(" ");
        dataFile.print(tm);
        dataFile.print(",");
        dataFile.print(dataString);
        dataFile.close();
      }
    }
    dataString = ""; // clear the string:
    stringComplete = false;
    strID = "";
  }
  //================Serial 1=======================//
  if (stringComplete1) {
    strID1 = (dataString1.substring(0, 2));
    if (strID1 == "$G")
    {
      Serial.print(dataString1);

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

      if (dataFile) {
        dataFile.print(dt);
        dataFile.print(" ");
        dataFile.print(tm);
        dataFile.print(",");
        dataFile.print(dataString1);
        dataFile.close();
      }
      else {
        File dataFile = SD.open("s1eslog.txt", FILE_WRITE);
        // if the file is available, write to it:

        if (dataFile) {
          dataFile.print(dt);
          dataFile.print(" ");
          dataFile.print(tm);
          dataFile.print(",");
          dataFile.print(dataString1);
          dataFile.close();
        }
      }
      dataString1 = ""; // clear the string:
      stringComplete1 = false;
      strID1 = "";
    }
    //==============Serial 2======================//
    if (stringComplete2) {
      strID2 = (dataString2.substring(0, 2));
      if (strID2 == "$G") {
        Serial.print(dataString2);

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

        if (dataFile) {
          dataFile.print(dt);
          dataFile.print(" ");
          dataFile.print(tm);
          dataFile.print(",");
          dataFile.println(dataString2);
          dataFile.close();
        }
      }
      else {
        File dataFile = SD.open("s2eslog.txt", FILE_WRITE);
        // if the file is available, write to it:

        if (dataFile) {
          dataFile.print(dt);
          dataFile.print(" ");
          dataFile.print(tm);
          dataFile.print(",");
          dataFile.print(dataString2);
          dataFile.close();
        }
      }
      dataString2 = ""; // clear the string:
      stringComplete2 = false;
      strID2 = "";
    }
    //===================Serial 3========================//
    if (stringComplete3) {
      strID3 = (dataString3.substring(0, 2));
      if (strID3 == "$G") {
        Serial.print(dataString3);

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

        if (dataFile) {
          dataFile.print(dt);
          dataFile.print(" ");
          dataFile.print(tm);
          dataFile.print(",");
          dataFile.print(dataString3);
          dataFile.close();
        }
      }
      else {
        Serial.print(dataString3);

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

        if (dataFile) {
          dataFile.print(dt);
          dataFile.print(" ");
          dataFile.print(tm);
          dataFile.print(",");
          dataFile.print(dataString3);
          dataFile.close();
        }
      }
      dataString3 = ""; // clear the string:
      stringComplete3 = false;
      strID3 = "";
    }
  }

}
void serialEvent() {
  //  if (flag == false) {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    // add it to the dataString:
    dataString += inChar;
    // if the incoming character is a newline, set a flag so the main loop can
    // do something about it:
    if (inChar == '\n') {
      stringComplete = true;
    }
  }
}
//}
void serialEvent1() {
  while (Serial1.available()) {
    // get the new byte:
    char inChar = (char)Serial1.read();
    // add it to the dataString:
    dataString1 += inChar;
    // if the incoming character is a newline, set a flag so the main loop can
    // do something about it:
    if (inChar == '\n' || '\r') {
      stringComplete1 = true;
    }
  }
}
void serialEvent2() {
  //  if (flag == false) {
  while (Serial2.available()) {
    // get the new byte:
    char inChar = (char)Serial2.read();
    // add it to the dataString:
    dataString2 += inChar;
    // if the incoming character is a newline, set a flag so the main loop can
    // do something about it:
    if (inChar == '\n') {
      stringComplete2 = true;
      //        Serial.print(dataString2);
    }
  }
}
//}

void serialEvent3() {
  while (Serial3.available()) {
    // get the new byte:
    char inChar = (char)Serial3.read();
    // add it to the dataString:
    dataString3 += inChar;
    // if the incoming character is a newline, set a flag so the main loop can
    // do something about it:
    if (inChar == '\n') {
      stringComplete3 = true;
    }
  }
}
 

Attachments

Ya’akov

Joined Jan 27, 2019
9,070
The DS1307s I have been testing have also been extremely inaccurate gaining five minutes in a few weeks. In practice I will have to use the GPS to reset them regularly.
 

Thread Starter

umerrai1

Joined Mar 29, 2021
246
Hello Sir, I have to ask a question.
I made this program for a data logger. If the frequency of all the messages coming from GPS is the same, it logs data perfectly even up to 32Hz. But if the frequency is not the same it got some glitches in the data. Program and sample files are attached to this message.
Code:
/*
  ** MEGA MINI **
  ** MOSI - pin 51
  ** MISO - pin 50
  ** CLK - pin 52
  ** CS - pin 53 (for MKRZero SD: SDCARD_SS_PIN)
  ** SDA - pin 20
  ** SCL - pin 21
*/
#include <Wire.h>
#include <EEPROM.h>
#include "math.h"
#include <SPI.h>
#include <SD.h>
#include "RTClib.h"
#define DS1307_CTRL_ID 0x68
RTC_DS1307 rtc;
unsigned long msec;
#include <TimerOne.h>
#define RxTimeOut 5

String String1;
String inputString1 = "";         // a String to hold incoming data
boolean NewDataFlag1=0;
unsigned int Serial1TimeOut=0;
bool string1Complete = false;
String String2;
String inputString2 = "";         // a String to hold incoming data
boolean NewDataFlag2=0;
unsigned int Serial2TimeOut=0;

const int chipSelect = 53;
String strID = "";

void timerIsr()
{
 serial1Event();

 
 if(Serial1TimeOut>0)Serial1TimeOut--;
 if(Serial1TimeOut==0 && NewDataFlag1==1)
 {
  String1=inputString1;
  inputString1="";
  NewDataFlag1=0;  
  } 

 if(Serial2TimeOut>0)Serial2TimeOut--;
 if(Serial2TimeOut==0 && NewDataFlag2==1)
 {
  String2=inputString2;
  inputString2="";
  NewDataFlag2=0;  
  } 


}


void setup() {


  Serial.begin(115200);
  Serial1.begin(19200);
  Serial2.begin(19200);
  
  inputString1.reserve(200);
  inputString2.reserve(200);
  
  Timer1.initialize(10000); // Timer event time 
  Timer1.attachInterrupt( timerIsr );
  
  Serial.println("READY");

  //========================================= SD Card =======================================================//
  //  Serial.println("Initializing SD card...");

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

  //====================================================== RTC =============================================//
  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__)));
  }
 
}

String String1A,String1B,String1C,String1D,String1E;
int CR1A, CR1B, CR1C, CR1D;
int CR2;
int CR3;
int CR4;
int CR5;
//---------------------------------------------
void loop() {

DateTime now = rtc.now();
  char dt[16];
  char tm[16];
  char buffer [16];
  uint8_t thisSec, thisMin, thisHour;
  thisSec = now.second();
  thisMin = now.minute();
  thisHour = now.hour();
  sprintf(dt, "%02d-%02d-%02d", now.year(), now.month(), now.day());
  sprintf(tm, "%02d%02d%02d", now.hour(), now.minute(), now.second());
  sprintf (buffer, "%02d:%02d:%02d", thisHour, thisMin, thisSec);
  msec = millis() % 1000; //TO USE LAST 3 DIGITS OF MILLIS OF ARDUINO


  //SERIAL_PORT_1

  if (string1Complete == true)
  {
    CR1A = String1.indexOf(13);  //finds location of first
    String1A = String1.substring(0, CR1A);   //captures first data String
    CR1B = String1.indexOf(13, CR1A + 2 ); //finds location of second ,
    String1B = String1.substring(CR1A + 2, CR1B); //captures second data String
    CR1C = String1.indexOf(13, CR1B + 2 );
    String1C = String1.substring(CR1B + 2, CR1C);
    CR1D = String1.indexOf(13, CR1C + 2 );
    String1D = String1.substring(CR1C + 2, CR1D);
    //    CR1E = String1.indexOf(13, CR1D + 2 );
    //    String1E = String1.substring(CR1D + 2, CR1E);
    //    CR1F = String1.indexOf(13, CR1E + 2 );
    //    String1F = String1.substring(CR1E + 2, CR1F);
    //    CR1G = String1.indexOf(13, CR1F + 2 );
    //    String1G = String1.substring(CR1F + 2, CR1G);

    //      Serial.println(" ----------- GROUP 1--------------");
    Serial.println(String1A);
    Serial.println(String1B);
    Serial.println(String1C);
    Serial.println(String1D);
    //    Serial.println(String1E);
    //    Serial.println(String1F);
    //    Serial.println(String1G);

    strID = (String1.substring(0, 2));
    if (strID == "$G") {
      File dataFile = SD.open("SERIAL_1.txt", FILE_WRITE);
      // if the file is available, write to it:
      dataFile.print(dt);
      dataFile.print(" ");
      dataFile.print(tm);
      dataFile.println(msec);
      dataFile.println(String1A);
      dataFile.println(String1B);
      //    if (strID == "$G") {
      dataFile.println(String1C);
      dataFile.close();
    }
    string1Complete = false;
      }
}
//-----------------------------------------------------------------------------------------------------------------

void serial1Event() {
    while (Serial1.available()) {
      char inChar1 = (char)Serial1.read();
      inputString1 += inChar1;
      Serial1TimeOut = RxTimeOut;
      NewDataFlag1 = 1;

      if (NewDataFlag1 == 1) {
        string1Complete = true;
      }

    }
  }
 

Attachments

ericgibbs

Joined Jan 29, 2010
18,766
hi umer,
Are you saying if the Baud rates are different for the devices, you get a problem.?

What does this mean: it logs data perfectly even up to 32Hz.

E
 

Thread Starter

umerrai1

Joined Mar 29, 2021
246
$GPGGA @ 5Hz
$GPVTG @ 4Hz
$GPZDA @ 2Hz

Now the problem arises in saving data on card. A blank space comes and we are saving one message without a $ sign. But on the other hand, if the frequency is the same of these 3 messages i.e;

$GPGGA @ 5Hz
$GPVTG @ 5Hz
$GPZDA @ 5Hz

Then there is no issue.

What does this mean: it logs data perfectly even up to 32Hz.
It means I am getting 6 messages at a frequency of 5Hz and 1 message at a 2Hz frequency. So the total will be 32Hz. Please keep in my that I am only using 1 port (Rx1 of atmega2560) and getting messages from one GPS.
 
Top