Domino <–> Sensor
UEXT4 (RXD) <–> 9 (TXD) rxd/txd crossed
UEXT3 (TXD) <–> 8 (RXD)
VCC or Port Pin <–> 7 (PWR_ON) the module is activated with a high level
GND <–> 2
VCC <–> 1 have in mind the module needs 5V
Success. It’s working…
My simple class for URM37 sensor:
/*++
Copyright (c) 2011 Dmitry Golubkov. All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Module Name:
FEZ.Sensors.URM37
Abstract:
Implementation basic functions of URM37 V3.2 Ultrasonic Sensor for using with FEZ Domino.
TTL serial interface connection:
+VCC (Domino) <- Pin 1 (URM37)
GND (Domino) <- Pin 2 (URM37)
Pin12 (Domino) <- Pin 7 (URM37)
UEXT4 (RX, COM2) (Domino) <- Pin 9 (URM37)
UEXT3 (TX, COM2) (Domino) <- Pin 8 (URM37)
Units: distance - cm, temperature - Celsius
--*/
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using System.IO.Ports;
namespace FEZ.Sensors
{
class URM37: IDisposable
{
private SerialPort _sensorPort;
private OutputPort _enablePin;
private byte[] _getDistanceCommand = new byte[] { 0x22, 0x00, 0x00, 0x22 };
private byte[] _getTemperatureCommand = new byte[] { 0x11, 0x00, 0x00, 0x11 };
public void Dispose()
{
_sensorPort.Dispose();
}
public URM37(string serialPortName, Cpu.Pin EnablePin)
{
_sensorPort = new SerialPort(serialPortName, 9600);
// open TTL connection
_sensorPort.Open();
_enablePin = new OutputPort(EnablePin, false);
// enable the sensor
_enablePin.Write(true);
}
public int GetDistance()
{
_sensorPort.Write(_getDistanceCommand, 0, _getDistanceCommand.Length);
byte[] resultBuffer = new byte[4];
_sensorPort.Read(resultBuffer, 0, resultBuffer.Length);
byte commandByte = resultBuffer[0];
byte highByte = resultBuffer[1];
byte lowByte = resultBuffer[2];
byte sumByte = resultBuffer[3];
int value = 0;
if (highByte == 0xff)
{
return 0;
}
else
{
value = highByte * 0xff + lowByte;
}
return value;
}
public double GetTemperature()
{
_sensorPort.Write(_getTemperatureCommand, 0, _getTemperatureCommand.Length);
byte[] resultBuffer = new byte[4];
_sensorPort.Read(resultBuffer, 0, resultBuffer.Length);
byte commandByte = resultBuffer[0];
byte highByte = resultBuffer[1];
byte lowByte = resultBuffer[2];
byte sumByte = resultBuffer[3];
double value = 0;
if (highByte >= 0xf0)
{
value = (double)(((double)highByte - 0xf0) * 0xff + (double)lowByte) / 10;
}
else
{
value = (double)((double)highByte * 0xff + (double)lowByte) / 10;
}
return value;
}
}
}