Pages: [1]   Go Down
Author Topic: How to use URM04 v2 sensor with Arduino  (Read 792 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello everyone,

As I am  new at Arduino, I have been having some problems with using URM04 sensor with Arduino . I have Arduino Uno and  I/O Expansion V5.0 . I'm using  the code which i got from   http://www.dfrobot.com/wiki/index.php?title=URM04_V2.0_%28SKU:SEN0002%29

However I can't read anything from the serial monitor. I tried different bauds (19200 and 115200 ) but still I'm reading strange letters like " Uª".

Can anyone help about using this sensor. I'm not good at programing and just I want to use it simply. I dont need to read temparature, just wanna read the distance.

Thank you
Tugsan





Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 180
Posts: 8108
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The sample code is using your hardware serial port to talk binary to the range sensors.  You can't also use the same hardware serial port to talk to the USB cable to the PC.  That is why the output lines of the example are commented out:
Code:

        switch (cmdrd[num])
        {
          case 0x11:
          URM[0]=cmdrd[num+3]*256+cmdrd[num+4];
          //Serial.print("0x11:");
          //Serial.println(URM[0]);
          break;
       
          case 0x12:
          URM[1]=cmdrd[num+3]*256+cmdrd[num+4];
          //Serial.print("0x12:");
          //Serial.println(URM[1]);
          break;

I suspect you are out of luck unless the "I/O Expansion V5.0" provides another RS485 serial port on a different pair of pins.  You can't move the USB connection to different pins without mangling your Arduino board.
You can use the NewSoftSerial library to talk to
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12487
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


I think there is a fundamental flaw in the example program, it only test once if there is data available ... This should be tested for every byte read back; OR ; tested if there are 6 or 7 available

Code:
void serial_read()
{
  if(Serial.available()) <<<<<<    BETTER  use  if (Serial.available() >= 7) then the whole answer is in the buffer ...
  {
    int sum=0;
    int i=0;
    //int j=0;
    boolean flag=true;
    while(flag)   <<<<<<<
    {
      cmdrd[i]=Serial.read();     <<<<
      if(cmdrd[i]==0xaa&&cmdrd[i-1]==0x55)
      {
        S_comd[0]=i;
        //j++;
      }
      if(cmdrd[i]!=0xff)
      {
        //Serial.print(cmdrd[i]);
        i++;
      }
      if(i>7)
      flag=false;
    }
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

johnwasser and robtillaart thank you for helping me solve the problem. It looks like I'm not able to do it at present. I better put it away and purchase a new one until I gain some experience.

johnwasser: I'm a bit confused about serial port using, I looked at the NewSoftSerial library but could't figure it out.

robtillaart: I tried to use the code block you posted and  I recieved the same letters. ( I changed only void serial_read block in orginial code. )

Could you recommend me any range finder sensor to use with Arduino. I'm thinking about getting Parallax Ping sensor http://www.parallax.com/tabid/768/ProductID/92/Default.aspx.

What are your opinions about this sensor? Also I'm open to recommendations.

Thank you very much.
Tugsan
Logged

Pages: [1]   Go Up
Jump to: