ArduinoGeneral

URM37 - Temperature sensor - How to work itwith DFRobot Romeo V2?

userHead pratyadi 2013-04-07 22:52:27 5970 Views5 Replies
Hi All,

Im trying the URM37 with its provided library, and I got confused on dfrobot (0) and TX1 (1) pins on Romeo V2, which dont give me any response.

URM37 works with normal PWM and COM port to measure distance. How do I get it to measure the temperature?

2013-04-12 19:20:49 What version of DFRobot Romeo are you using?
Sorry, just realized that the Romeo V2 its using serial1 for pins 0 and 1

so the code will change to:

// # Editor    : Lauren from DFRobot
// # Date      : 08.05.2012

// # Product name: URM V3.2 ultrasonic sensor TTL connection with Arduino
// # Product SKU : SEN0001
// # Version    : 1.0
// # Update the library to make it compatible with the Arduino IDE 1.0 or the latest version

// # Description:
// # The sketch for using the URM37 from DFRobot to read values (0-300) from an ultrasound sensor (3m sensor)
// #  and writes the values to the serialport

// # Connection:
// #      Pin12 (Arduino) -> Pin 1 VCC (URM V3.2)
// #      GND (Arduino)  -> Pin 2 GND (URM V3.2)
// #      Pin 0 (Arduino) -> Pin 9 TXD (URM V3.2)
// #      Pin 1 (Arduino) -> Pin 8 RXD (URM V3.2)
// #

int URPower = 12; // Ultrasound power pin
int val = 0;
int USValue = 0;
int timecount = 0; // Echo counter
boolean flag=true;
uint8_t DMcmd[4] = {
  0x22, 0x00, 0x00, 0x22}; //distance measure command

void setup() {
  Serial.begin(9600);                  // Sets the baud rate to 9600
  Serial1.begin(9600);                  // Sets the baud rate to 9600
  Serial.println("Init the sensor");
  pinMode(URPower, OUTPUT);
  digitalWrite(URPower, HIGH); // Set to High
  delay(200); //Give sensor some time to start up --Added By crystal  from Singapo, Thanks Crystal.
}

void loop()
{
  flag = true;
  //Sending distance measure command :  0x22, 0x00, 0x00, 0x22 ;

  for(int i=0;i<4;i++)
  {
    Serial1.write(DMcmd[i]);
  }

  delay(40); //delay for 75 ms
  unsigned long timer = millis();
  while(millis() - timer < 30)
  {
    if(Serial1.available()>0)
    {
      int header=Serial1.read(); //0x22
      int highbyte=Serial1.read();
      int lowbyte=Serial1.read();
      int sum=Serial1.read();//sum

      if(header == 0x22){
        if(highbyte==255)
        {
          USValue=65525;  //if highbyte =255 , the reading is invalid.
        }
        else
        {
          USValue = highbyte*255+lowbyte;
        }

        Serial.print("Distance=");
        Serial.println(USValue);

        flag=false;
      }
      else{
        while(Serial1.available())  byte bufferClear = Serial1.read();
        break;
      }
    }
  }
  delay(20);
}
userHeadPic Jose
2013-04-11 22:06:53 Thank you for the code, but as expected it doesnt work with DFRobot Romeo.

Question is where do you specify the pins to be RX and TX? Is it always 0 and 1 by default?

Problem is then, maybe not because of URM37, but because DFRobot Romeo does not provide instruction on activating the serial pins RX and TX.

Can you help?
userHeadPic pratyadi
2013-04-10 18:13:43 Try this code example, don't forget to check the pin jumpers!

// #
// # Editor    : Lauren from DFRobot
// # Date      : 08.05.2012

// # Product name: URM V3.2 ultrasonic sensor TTL connection with Arduino
// # Product SKU : SEN0001
// # Version    : 1.0
// # Update the library to make it compatible with the Arduino IDE 1.0 or the latest version

// # Description:
// # The sketch for using the URM37 from DFRobot to read values (0-300) from an ultrasound sensor (3m sensor)
// #  and writes the values to the serialport

// # Connection:
// #      Pin12 (Arduino) -> Pin 1 VCC (URM V3.2)
// #      GND (Arduino)  -> Pin 2 GND (URM V3.2)
// #      Pin 0 (Arduino) -> Pin 9 TXD (URM V3.2)
// #      Pin 1 (Arduino) -> Pin 8 RXD (URM V3.2)
// #


int URPower = 12; // Ultrasound power pin
int val = 0;
int USValue = 0;
int timecount = 0; // Echo counter
boolean flag=true;
uint8_t DMcmd[4] = {
  0x22, 0x00, 0x00, 0x22}; //distance measure command

void setup() {
  Serial.begin(9600);                  // Sets the baud rate to 9600
  Serial.println("Init the sensor");
  pinMode(URPower, OUTPUT);
  digitalWrite(URPower, HIGH); // Set to High
  delay(200); //Give sensor some time to start up --Added By crystal  from Singapo, Thanks Crystal.
}

void loop()
{
  flag = true;
  //Sending distance measure command :  0x22, 0x00, 0x00, 0x22 ;

  for(int i=0;i<4;i++)
  {
    Serial.write(DMcmd[i]);
  }

  delay(40); //delay for 75 ms
  unsigned long timer = millis();
  while(millis() - timer < 30)
  {
    if(Serial.available()>0)
    {
      int header=Serial.read(); //0x22
      int highbyte=Serial.read();
      int lowbyte=Serial.read();
      int sum=Serial.read();//sum

      if(header == 0x22){
        if(highbyte==255)
        {
          USValue=65525;  //if highbyte =255 , the reading is invalid.
        }
        else
        {
          USValue = highbyte*255+lowbyte;
        }

        Serial.print("Distance=");
        Serial.println(USValue);

        flag=false;
      }
      else{
        while(Serial.available())  byte bufferClear = Serial.read();
        break;
      }
    }
  }
  delay(20);
}
userHeadPic Jose
2013-04-10 17:32:19 [quote="pratyadi"]
Hi All,

Im trying the URM37 with its provided library, and I got confused on dfrobot (0) and TX1 (1) pins on Romeo V2, which dont give me any response.

URM37 works with normal PWM and COM port to measure distance. How do I get it to measure the temperature?
[/quote]

did you try to set the pin jumpers?

[url=http://www.dfrobot.com/wiki/index.php?title=URM37_V3.2_Ultrasonic_Sensor_(SKU:SEN0001)#Mode_1:_Serial_passive_control_mode]http://www.dfrobot.com/wiki/index.php?title=URM37_V3.2_Ultrasonic_Sensor_(SKU:SEN0001)#Mode_1:_Serial_passive_control_mode[/url]
userHeadPic Jose
2013-04-08 18:33:54 I really cant figure out whats wrong with this. This script dont work with my Romeo

/*
DistanceBySoftwareSerial.pde - URM 37 Control Library Version 2.0.0
Author: Miles Burton, [email protected]
Copyright (c) 2009 Miles Burton All Rights Reserved

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or dfrobot FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

*/

// # This library is a improvement version of URM 37 Control Library Version 2.0.0 from Miles Burton
// # Original Author: Miles Burton, [email protected]
// #
// # Editor    : Lauren from DFRobot
// # Date      : 08.05.2012

// # Product name: URM V3.2 ultrasonic sensor TTL connection with Arduino
// # Product SKU : SEN0001
// # Version    : 1.0
// # Update the library to make it compatible with the Arduino IDE 1.0 or the latest version

// # Description:
// # The sketch for using the URM37 from DFRobot based on the Software Serial library
// # You could drive the URM37 with 2 digital pins on your Arduino board, and it works stable.

// # Connection:
// #      VCC (Arduino)  -> Pin 1 VCC (URM37 V3.2)
// #      GND (Arduino)  -> Pin 2 GND (URM37 V3.2)
// #      Pin 6 (Arduino) -> Pin 9 TXD (URM37 V3.2)
// #      Pin 7 (Arduino) -> Pin 8 RXD (URM37 V3.2)
// #

#include "URMSerial.h"

// The measurement we're taking
#define DISTANCE 1
#define TEMPERATURE 2
#define ERROR 3
#define NOTREADY 4
#define TIMEOUT 5

URMSerial urm;

void setup() {

  Serial.begin(9600);                  // Sets the baud rate to 9600
  urm.begin(6,7,9600);                // RX Pin, TX Pin, Baud Rate
  Serial.println("URM37 Library by Miles Burton");  // Shameless plug
 
}

void loop()
{
  Serial.print("Measurement: ");
  Serial.println(getMeasurement());  // Output measurement
  delay(50);
}


int value; // This value will be populated
int getMeasurement()
{
  // Request a distance reading from the URM37
  switch(urm.requestMeasurementOrTimeout(DISTANCE, value)) // Find out the type of request
  {
  case DISTANCE: // Double check the reading we recieve is of DISTANCE type
    //    Serial.println(value); // Fetch the distance in centimeters from the URM37
    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;
}
userHeadPic pratyadi