Go Down

Topic: Filtering Data (Read 1 time) previous topic - next topic

0JavierContreras1

Apr 18, 2017, 06:13 pm Last Edit: Apr 18, 2017, 06:55 pm by 0JavierContreras1
Hello
I'm trying to export data from sensor connected to a Indicator (and its manual), this one, is connected to arduino Mega 2560 using RS-485 protocol with the Max 485 module.
Using this smple code:
Code: [Select]
#define transmitir 2

void setup(){
  Serial3.begin(9600,SERIAL_8O1);     
  Serial.begin(9600,SERIAL_8O1);
  pinMode(transmitir,OUTPUT);
  digitalWrite(transmitir,LOW);
}

void loop(){
  if(Serial3.available() > 0){
    char recibido;
    recibido = Serial3.read();
   Serial.print(recibido);
  }
}


Receive strange characters and the real measurement.
i want to filtering that just to have the measurement, but cant find the way
I'm receiving this:

Code: [Select]
011@H     496
011@H     698
011@H     698
011@H     800
011@H     800
011@H    1009
011@H    1009
011@H    1009
011@H    1211
011@H    1211
011@H    1211
011@H    1211
011@H    1211
011@H    1211
011@H    1413
011@H    1413
011@H    1413
011@H    1413
011@H    1211
011@H    1211
011@H    1211
011@H    1211
011@H    1211
011@H    1009
011@H    1009
011@H    1009
011@H     800
011@H     800
011@H     800
011@H     698
011@H     698
011@H     496
011@H     496
011@H     294
011@H     294
011@H     294
011@D     088


Sending the Data to excel using PLX-DAQ
whith this code:
Code: [Select]


#define transmitir 2
float potpin = A0;    //  Variable que define puerto del potenciometro
int ndato = 0;        // Variable "Numeró de dato" del potenciometro en excel
int LABEL = 1;   
int angulo = 0;       // variable que guarda el valor del dato recibido del potenciometro (0 - 1023)
char recibido;

void setup() {

  // open serial connection
    Serial3.begin(9600,SERIAL_8O1);   
    Serial.begin(9600,SERIAL_8O1);
    pinMode(transmitir,OUTPUT);
    digitalWrite(transmitir,LOW);

    //Serial.println("CLEARDATA"); // clears starting at row 2
    Serial.println("CLEARSHEET"); // clears starting at row 1
   
    //Define columns name
    Serial.println("LABEL,N.Dato,Angulo[°],Torque[N/m]");

  // set the names for the 3 checkboxes
    //Serial.println("CUSTOMBOX1,LABEL,Stop logging at 250?");
    //Serial.println("CUSTOMBOX2,LABEL,Resume log at 350?");
    //Serial.println("CUSTOMBOX3,LABEL,Quit at 450?");

  // check 2 of the 3 checkboxes (first two to true, third to false)
    //Serial.println("CUSTOMBOX1,SET,1");
    //Serial.println("CUSTOMBOX2,SET,1");
    //Serial.println("CUSTOMBOX3,SET,0");
}

void loop(){
   
    potenciometro();
   
    Serial3.print("DATA"); //Inicio de impresión de datos
    Serial3.print(",");
    Serial3.print(ndato);
    Serial3.print(",");
    Serial3.println(angulo);
    Serial3.print(",");
    Serial3.println(torque());
}

int potenciometro(){

  angulo = analogRead(potpin);   // Lee el valor del potenciometro y lo guarda en la variable angulo.
  ndato++; // incrementa en 1 el número de dato
}

int torque(){
  while(Serial3.available() > 0){
    recibido = Serial3.read();
        Serial3.print(recibido);
    }
}


I receive a strange mesuremnt from the torque sensor in the excel spreadsheet
i just need the measurement

Thanks



pylon

It's very interesting that you get this data because according to the documentation that device uses the ModBus protocol over RS-485 to communicate. ModBus devices don't send any data that wasn't requested by the bus master.

Which type of that device do you own? FPTA or FPTC?

0JavierContreras1

FPTC but i thing i'm not using the ModBus setting, if yo see in the Manual,in the setup i pick the option that says Continious mode, not the modbus one.

In the manual that configuration is in the page 5, option F2.3.

or which one should i pick?

THANK YOU

pylon

Unfortunately the continuous mode is not documented in the manual. According to the output you received it looks like the integer value at the end of the line is the measurement value but without a documentation about that format that's just guessing.

Did you really configured 8O1 in F2.4? The default is 8E1 (which is also the ModBus default BTW). Please check that. You should at least remove the 8O1 for the serial to the PC because there you probably use 8N1.

0JavierContreras1

Using the modbus rtu mode and let the configuracion of F2.4 option in 8E1 in the serial monitor i dont receive anything.
i Continious mode, i have the same.

I connected the arduino and the indicator like this


But using the arduino Mega 2560 in the pin the TX3/RX3 (pin14/pin15)

I thing i need a modbus library, but i don't know which one and how to use that.



pylon

Does the value in your output correspond in some way to the force you put to the sensor?

0JavierContreras1

Yes, in the continious mode, The numeric values correspond with the value in the sensor.

MorganS

So just use those values.

You need to use a method something like Serial Input Basics which will detect the "H" as the start of the useful portion of the message and the carriage-return or linefeed as the end of the useful message. The rest of it can be ignored by the message receiver.
"The problem is in the code you didn't post."

0JavierContreras1

I've already tried.
That character randomly change then thats not possible, I think.

Power_Broker

#9
Apr 21, 2017, 03:53 pm Last Edit: Apr 21, 2017, 03:54 pm by Power_Broker
Fiddlesticks! Of course it's possible.

By the way, why are you configuring the serial ports with SERIAL_8O1?:
Code: [Select]

Serial3.begin(9600,SERIAL_8O1);   
Serial.begin(9600,SERIAL_8O1);


I don't think it's necessary (could be wrong, though).
"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

MorganS

I've already tried.
That character randomly change then thats not possible, I think.
Are there any chars which are constant? The line feed after the value?
"The problem is in the code you didn't post."

Go Up