{
if(SerialPort.available()){
cmdrd[i]= SerialPort.read();
// printByte(cmdrd[i]);
if(i > 7){
flag=false;
// printByte(0xEE);
// printByte(0xFF);
SerialPort.flush();
break;
}
if(cmdrd[i] == 0xAA){
headerNo = i;
valid = true;
}
if(valid && i == headerNo + 6){
// printByte(0xDD);
// printByte(0xFF);
flag = false;
break;
}
i ++;
RetryCounter = 0;
}
else{
RetryCounter++;
delayMicroseconds(15);
}
}
// printByte(millis() - timerPoint);
if(valid) analyzeUrmData(cmdrd);
// else SerialPort.println("Invalid feedback"); //Get an invalid error co
mmand
}
}
void analyzeUrmData(byte cmd[]){
byte sumCheck = 0;
for(int h = 0;h < 7; h ++) sumCheck += cmd[h];
if(sumCheck == cmd[7] && cmd[3] == 2 && cmd[4] == 2){
byte id = cmd[2] - startAddr;
urmData[id] = cmd[5] * 256 + cmd[6];
// SerialPort.print(id);
// SerialPort.print(":");
// SerialPort.println(urmData[id]);
}
else if(cmd[3] == 2 && cmd[4] == 2){
SerialPort.print("Sum error");
}
}
Powered By DFRobot © 2008-2017

SEN0002

Mfr. #:
Manufacturer:
DFRobot
Description:
Distance Sensor Modules URM04 v2.0 Ultrasonic Sensor
Lifecycle:
New from this manufacturer.
Delivery:
DHL FedEx Ups TNT EMS
Payment:
T/T Paypal Visa MoneyGram Western Union

Products related to this Datasheet