Data Filtering

Good day

I have a question regarding data filtering.

I receive the following HEX string at the serial port of the Adruino 050D3800792D10

I want to use only the 2 bytes in red. These 2 bytes will change with each new message. What procedure can I use to do this?

The only thing I can think of is to multiply this string with 000000000000000011110000

Any suggestions would be very helpful, I am stuck

Regards

You can use one of those functions:

if (Serial) available() begin() end() find() findUntil() flush() parseFloat() parseInt() peek() print() println() read() readBytes() readBytesUntil() setTimeout() write() serialEvent()

http://arduino.cc/en/Reference/Serial

Thanks, I will go and study these functions

I receive the following HEX string at the serial port of the Adruino 050D3800792D10

Are you receiving a string or a collection of values that you print in HEX?

The only thing I can think of is to multiply this string with 000000000000000011110000

Better think again. You can't multiply a string by anything. What is "frog" * pi?

You should read your serial data into a byte array. Then retrieve the data at (in your example) the 5th and 6th positions of the array. : E.g., if you read your data into a byte array named "array":

word myData = word(array[4],array[5]);

simple servo test code that shows a simple way to capture a string of characters and extract the ones of interest.

// zoomkat 12-13-11 serial servo (2) test
// for writeMicroseconds, use a value like 1500
// for IDE 1.0
// Powering a servo from the arduino usually DOES NOT WORK.
// two servo setup with two servo commands
// send eight character string like 15001500 or 14501550
// use serial monitor to test

#include <Servo.h> 
String readString, servo1, servo2;
Servo myservo1;  // create servo object to control a servo 
Servo myservo2;

void setup() {
  Serial.begin(9600);
  myservo1.attach(6);  //the pin for the servo control 
  myservo2.attach(7);
  Serial.println("two-servo-test-1.0"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    delay(3);  //delay to allow buffer to fill 
    if (Serial.available() >0) {
      char c = Serial.read();  //gets one byte from serial buffer
      readString += c; //makes the string readString
    } 
  }

  if (readString.length() >0) {
      Serial.println(readString); //see what was received
      
      // expect a string like 07002100 containing the two servo positions      
      servo1 = readString.substring(0, 4); //get the first four characters
      servo2 = readString.substring(4, 8); //get the next four characters 
      
      Serial.println(servo1);  //print to serial monitor to see parsed results
      Serial.println(servo2);

      int n1 = servo1.toInt();
      int n2 = servo2.toInt();

      Serial.println("the numbers are :");
      Serial.println(n1);  //print to serial monitor to see number results
      Serial.println(n2);
            
      myservo1.writeMicroseconds(n1); //set servo position 
      myservo2.writeMicroseconds(n2);
    readString="";
  } 
}

Thank you very much :), at last something that looks like it will work. Let me go to work and try this out

Cheers

PaulS: What is "frog" * pi?

A delicacy in some rural parts of France.

Thanks Zoomkat and Professor Chaos, got it working