amperka / urm37 Goto Github PK
View Code? Open in Web Editor NEWArduino-library to communicate with URM37 ultrasound sensor
Arduino-library to communicate with URM37 ultrasound sensor
При подключении нескольких устройств URM37 на одном из устройств(последнее проинициализированное устройство будет работать) при чтении появляется ошибка timeout.
ide: arduino 1.0, на старых версиях 2 urm37 работали нормально.
Скетч
{code}
// LEFT sensor
// Right sensor
URMSerial urmLeft;
URMSerial urmRight;
int value; // This value will be populated
void setup()
{
delay(100);
Serial.begin(9600); // Sets the baud rate to 9600
urmLeft.begin(URM_RIGHT_TXD_PIN, URM_RIGHT_RXD_PIN,9600); // TX Pin, RX Pin, Baud
delay(100);
urmRight.begin(URM_LEFT_TXD_PIN, URM_LEFT_RXD_PIN,9600); // RX Pin, TX Pin, Baud Rate
}
void loop()
{
delay(500);
Serial.print("Measurement left: ");
Serial.println(getMeasurement(urmLeft));
Serial.print("Measurement right: ");
Serial.println(getMeasurement(urmRight));
}
int getMeasurement(URMSerial urm)
{
switch(urm.requestMeasurementOrTimeout(DISTANCE, value)) // Find out the type of request
{
case DISTANCE: // Double check the reading we recieve is of DISTANCE type
return value;
break;
case TEMPERATURE:
return value;
break;
case ERROR:
Serial.println("Error");
break;
case NOTREADY:
Serial.println("Not Ready");
break;
case TIMEOUT:
Serial.println("Timeout");
break;
}
return -1;
}
{/code}
Если имелся ввиду сдвиг на 8, то умножать следует на 256:
(gdb) p/x 0xbe * 255 + 0xef
$17 = 0xbe31
(gdb) p/x 0xbe * 256 + 0xef
$18 = 0xbeef
byte URMSerial::processDistance(int& value)
{
....
// 1x16bit value wrapped over two bytes
// HighByte must be multiplied by 255 to represent the correct byte
// Both are added together to calculate the value in Centimeters (I believe)
value = serialData[HighByte]*255+serialData[LowByte];
return DISTANCE;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.