Print CSV to Serial

3 years 7 months ago #29534736 by giantpt
Print CSV to Serial was created by giantpt
Hello all,

I am controlling my RoboteQ already with the help of an arduino but now I would like to receive some telemetry data from the motor controller.
I know that I can Query it and receive the data as an answer but I would prefer to simplify and force the RoboteQ to continuously send the data I need through the Serial port without being asked by the arduino.
So, as my serial communication knowledge is very limited and I am used to work with CSV arrangement and then parse it I would like to know if its possible to write an internal script to print out the "string" I need that looks like this:
(BatVolt,MotorVolt,BatAmps,Temp\n)
Of course that the names inside the parenthesis are only examples, it is just for you to have an example of what I need to be sent.

Thanks in advance

Please Log in or Create an account to join the conversation.

3 years 7 months ago - 3 years 7 months ago #29534738 by giantpt
Replied by giantpt on topic Print CSV to Serial
Well, after some hours reading more carefully I found the way to do it the way I need and I'll post here the script I made for it that can be used for those who might need to do the same.
In may case the RoboteQ will send some telemetry data in a CSV format to the serial port, it is read and parse by an Arduino Mega (because it has multiple serial ports) on Serial port 2 and than printed on Serial port 1 to the serial monitor for debug.
the script for the motor controller is attached on a zip

File Attachment:

File Name: Query_prin...ript.zip
File Size:0 KB
r file
Enjoy... all codes are working as is.

Arduino code:
/*   Parse Receive Test code

Data from RoboteQ:
- Battery Volts
- Motor 1 Amps
- Motor 2 Amps
- MCU Temperature

   Createdde by Nuno Fernandes | nunodlfernandes@gmail.com | 2019
*/

//================================================ VOID SETUP ========== 
void setup(){  
  
  Serial.begin(115200);
  Serial2.begin(115200);
  
}
//================================================ VOID LOOP ========== 
void loop(){
  
  if(Serial2.available() > 0) {    
    float Volts = (char)Serial2.parseInt();
    float Amps1 = (char)Serial2.parseInt();
    float Amps2 = (char)Serial2.parseInt();
    int Temp = (char)Serial2.parseInt();
    //int Status = (char)Serial2.parseInt();
    //int Fault = (char)Serial2.parseInt();
    
    Serial.print(Volts/10,1);
    Serial.print("  ");
    Serial.print(Amps1,1);
    Serial.print("  ");
    Serial.print(Amps2,1);
    Serial.print("  ");
    Serial.println(Temp);
    }
    
}
Attachments:

Please Log in or Create an account to join the conversation.

Time to create page: 0.068 seconds