urm37 ultrasonic serial reading problem


hello

i trying distance reading urm37 ultrasonic sensor.

here code:

code: [select]
#include <urmserial.h>

/*
distancebysoftwareserial.pde - urm 37 control library version 2.0.0
author: miles burton, miles@mnetcs.com
copyright (c) 2009 miles burton rights reserved

this library free software; can redistribute and/or
modify under terms of gnu lesser general public
license published free software foundation; either
version 2.1 of license, or (at option) later version.

this library distributed in hope useful,
but without warranty; without implied warranty of
merchantability or fitness particular purpose.  see gnu
lesser general public license more details.

you should have received copy of gnu lesser general public
license along library; if not, write free software
foundation, inc., 51 franklin st, fifth floor, boston, ma  02110-1301  usa

*/

#include <softwareserial.h>


#include "urmserial.h"


// 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 baud rate 9600
  urm.begin(0,1,9600);                 // rx pin, tx pin, baud rate
  serial.println("faaaaak");   // shameless plug
}
 
void loop()
{
  serial.println("measurement: ");
  serial.println(getmeasurement());  // output measurement
}


int value; // value populated
int getmeasurement()
{
  // request distance reading urm37
  switch(urm.requestmeasurementortimeout(distance, value)) // find out type of request
  {
  case distance: // double check reading recieve of distance type
    //    serial.println(value); // fetch distance in centimeters 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;
}



though when upload , watch serial monitor, prints "measurement: timeout" instead of distance value.

can me?


thank you

hi siemenlec

which type of arduino running on?

on uno, pins 0 , 1 used serial monitor.  code cause clash:

code: [select]
urm.begin(0,1,9600);                 // rx pin, tx pin, baud rate

regards

ray



Arduino Forum > Using Arduino > Sensors > urm37 ultrasonic serial reading problem


arduino

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support