Main Site Documentation

URM37 Ultrasonic Sensor and FEZ Domino


#1

Hello all! need help!

Sensor: http://www.dfrobot.com/index.php?route=product/product&path=36_55&product_id=53

How to connect URM37 range sensor to Domino for using Serial mode?

I need some sample C# source code to getting distance value from sensor via serial.

thank u very much!


#2

I couldn’t find its manual but the description says it has a TTL output…you need to connect that to any of the UART RX pins on FEZ


#3

Yes , the manual link is broken ::slight_smile:

But I found it here

http://www.dfrobot.com/wiki/index.php?title=URM37_V3.2_Ultrasonic_Sensor_Manual%28SKU:SEN0001%29


#4

ok, thank u.

There are sensor pins:

1 +VCC
2 GND
3 RST
4 PWM
5 MOTO
6 COMP/TRIG
7 COMP
8 TRIG
9 PWR_ON - Enable pin – WHAT IS IT?
8 RXD
9 TXD

So, I connected:

Domino <–> Sensor
UEXT4 <–> 8
UEXT3 <–> 9
GND <–> 2
+3.3 <–> 1

Correct?

Code:

SerialPort sensor = new SerialPort(“COM2”, 9600);
sensor.Open();

sensor.Read(…) – waiting…and nothing?

what do i do wrong? thank u!


#5

Did you set the jumpers in ttl mode?


#6

yes. TTL mode is on.

And I connected sensor pin7 to Di3.

My code now:


SerialPort urm = new SerialPort("COM2", 9600);
urm.Open();

OutputPort nic = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.Di3, false);
nic.Write(true);

Thread.Sleep(200);

byte[] cmd = { 0x22, 0x00, 0x00, 0x22}; //distance measure command

urm.Write(cmd, 0, 4);

Thread.Sleep(75);

while (true)
{
    byte[] buf = new byte[4];
    urm.Read(buf, 0, 4); <--- wait..and wait..

    ....
}

not working! please help!


#7

Hi retmas ,

you have to wire the sensor to the following pins

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


#8

thank you. i will try it.


#9

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;
        }
    }
}


#10

Hi retmas ,

nice work :clap:

Now you can post it on fezzer.com


#11

cool. how to post it to fezzer.com?


#12

After logging in to Fezzer.com click on “Create” in the main navigation at the top. After that just fill in the information.