0

I'm using the DYP-ME007TX sensor with arduino uno. The output from this sensor comes in packets of 4-bytes:

Data[0]= 0xFF: Packet Header
Data[1]= 0x0-0xFF: Data Most Significant Byte (MSB)
Data[2]= 0x0-0xFF: Data Least Significant Byte (LSB)
Data[3]= 0x0-0xFF: Data Checksum: = (0XFF + MSB + LSB) & 0xFF

Data is in MILLIMETERS

16 bit value in mm = Data[1] << 8 | Data[2]

How can exctract this packet in arduino sketch and extract millimeter number?

Ricardo
3,3902 gold badges26 silver badges55 bronze badges
asked Jun 16, 2015 at 11:53
2
  • This is a serial data stream. Connect the device's OUT to your Arduino's RX, then read the documentation on the Serial library. Commented Jun 16, 2015 at 12:00
  • I want to use two and more this kind of sensors, so I think I just can't use Arduino's TX. I used SoftwareSerial library: arduino.cc/en/Tutorial/TwoPortReceive Commented Jun 17, 2015 at 1:49

1 Answer 1

1

I found the answer from forum.arduino.cc There is a sketch

#include <SoftwareSerial.h>
// TX_PIN is not used by the sensor, since that the it only transmits!
#define PING_RX_PIN 6
#define PING_TX_PIN 7
SoftwareSerial mySerial(PING_RX_PIN, PING_TX_PIN);
long inches = 0, mili = 0;
byte mybuffer[4] = {0};
byte bitpos = 0;
void setup() {
 Serial.begin(9600);
 mySerial.begin(9600);
}
void loop() {
 bitpos = 0;
 while (mySerial.available()) {
 // the first byte is ALWAYS 0xFF and I'm not using the checksum (last byte)
 // if your print the mySerial.read() data as HEX until it is not available, you will get several measures for the distance (FF-XX-XX-XX-FF-YY-YY-YY-FF-...). I think that is some kind of internal buffer, so I'm only considering the first 4 bytes in the sequence (which I hope that are the most recent! :D )
 if (bitpos < 4) {
 mybuffer[bitpos++] = mySerial.read();
 } else break;
 }
 mySerial.flush(); // discard older values in the next read
 mili = mybuffer[1]<<8 | mybuffer[2]; // 0x-- : 0xb3b2 : 0xb1b0 : 0x--
 Serial.print("PING: ");
 Serial.print(mili/10);
 Serial.println("sm");
 delay(500);
}
answered Jun 16, 2015 at 12:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.