Show Posts
Pages: [1]
1  Using Arduino / Interfacing w/ Software on the Computer / Arduino -> Sensor Result plotting with PLX-DAQ on: November 12, 2012, 06:41:55 pm
Hi
i use a SRF02 Sensor on my Arduino. The result is coming to the serial monitor. That works fine.
That is my Code

Code:
#include <Wire.h>

#define srfAddress1 (0x70)                            // Address of the SRF02

void setup()
{
   Serial.begin(9600);
   Wire.begin();                               
 }

int reading = 0;

void loop()
{
 
//Sensor 1
  Wire.beginTransmission(srfAddress1);            // Start communticating with SRF02
  Wire.write(0x00);                                                    // Send Command Byte
  Wire.write(0x51);                                                   // Send 0x51 to start a ranging takes place
  Wire.endTransmission(); 


 delay(70);                                                                  // Wait for ranging to be complete


//instruct sensor to return a particular echo reading, Sensor1
  Wire.beginTransmission(srfAddress1);        // Start communticating with SRF02
  Wire.write(0x02);                                                // Call register for start of ranging data
  Wire.endTransmission();                                  // stop transmitting


//request reading from sensor, Sensor1
  Wire.requestFrom(srfAddress1, 2);              // request 2 bytes from slave device Sensor1


//receive reading from sensor
  if (2 <= Wire.available())                                  // if two bytes were received
  {
   reading = Wire.read();                           // receive high byte (overwrites previous reading)
   reading = reading << 8;                         // shift high byte to be high 8 bits
   reading = Wire.read();                          // receive low byte as lower 8 bits
   Serial.print("Entfernung1:");
   Serial.println(reading);                        // print the reading
  }

  delay(500);                                      // wait a bit to read the output

}

Now i want to plot the result with PLX-DAQ software in a graph.
The PLX-DAQ software shows me that it is connected to the Arduino (green C) and it shows me that it received some data (red R).
But there is no data transmission (green T).

How can i receive data from my Arduino?? Do i have to correct my Arduino-code??
2  Using Arduino / Sensors / Re: Arduino -> SRF02 (Fake-Mode Problems) on: October 30, 2012, 10:43:15 am
I changed a bit the code. I call "Sensor2" (receive the signal) before "Sensor1" (transmit the signal).

If i call Sensor2 after Sensor1 it could be that the Signal is just gone. That was my intention.


Code:
#include <Wire.h>

#define srfAddress1 0x70                               // Address of the SRF02
#define srfAddress2 0x72                              // Address of the SRF02

#define cmdByte 0x00                                 // Command byte
#define rangeByte 0x02                             // Byte for start of ranging data

byte highByte = 0x00;                                // Stores high byte from ranging
byte lowByte = 0x00;                                // Stored low byte from ranging
int range = 0;
int rangeData;


void setup()
{
   Serial.begin(9600);
   Wire.begin();                              
 }


void loop()
{
  rangeData=getRange();  
}


int getRange()                                                      // This function gets a ranging from the SRF02
{                                                
  //Sensor 2 –Empfänger-

  Wire.beginTransmission(srfAddress2);             // Start communticating with SRF02
  Wire.write((uint8_t)cmdByte);                         // Send Command Byte
  Wire.write((uint8_t)0x57);                               // Fake Ranging Mode - Result in centimeters
  Wire.endTransmission();

  
//Sensor 1 –Sender-

  Wire.beginTransmission(srfAddress1);             // Start communticating with SRF02
  Wire.write((uint8_t)cmdByte);                         // Send Command Byte
  Wire.write((uint8_t)0x5C);        // Transmit an 8 cycle 40khz burst - no ranging takes place
  Wire.endTransmission();  
  
    
  //Sensor 2 –Empfänger-
 
  delay(100);                                                           // Wait for ranging to be complete
  
  Wire.beginTransmission(srfAddress2);       // start communicating with SRFmodule
  Wire.write((uint8_t)rangeByte);                 // Call the register for start of ranging data
  Wire.endTransmission();
  
  Wire.requestFrom(srfAddress2, 2);            // Request 2 bytes from SRF module
  
  while(Wire.available() < 2);                    // Wait for data to arrive
  highByte = Wire.read();                           // Get high byte
  lowByte = Wire.read();                           // Get low byte
  
  range = (highByte << 8 ) + lowByte;              // Put them together
  
  //print it
  Serial.print("Entfernung zwischen 1&2: ");
  Serial.println(range, DEC);  
  delay(1500);


  return(range);                                                    // Returns Range

}


3  Using Arduino / Sensors / Re: Arduino -> SRF02 (Fake-Mode Problems) on: October 30, 2012, 10:33:47 am
I tested it and the problem is that the result is not constant wrong.

for example: the right length is 37cm -> result of srf02: 27cm
                                                   27cm -> result of srf02: 25cm
4  Using Arduino / Sensors / Re: Arduino -> SRF02 (Fake-Mode Problems) on: October 30, 2012, 09:19:32 am
"use code tags for your code parts, else the tag parsing on the server may omit some code."
-> Ok next time i will use it.

"May I guess: your result is about 10-15cm wrong?
The transmission of the range command takes approximately 300us which translates to about 10cm. If there's another delay in the communication that I've missed it may be more. The datasheet explicitly states that you are responsible for the synchronization of the two sensors if used this way."

-> Ok thanks. I will check if the result is constant wrong. (for example every time about 10cm) Then i will reduce every time the result about 10cm. So i guess i get the right result. 

5  Using Arduino / Sensors / Arduino -> SRF02 (Fake-Mode Problems) on: October 29, 2012, 11:27:50 am

Hi everyone,
I have been trying to measure the distance between two SRF02 sensors (in Fake Mode).
I have connected two SRF02 sensors on my Arduino by I2C Bus system.

The idea is that one SRF02 should send a signal and the second SRF02 should be waiting for the signal.

The problem is that I get wrong distances as result.
Here is my Code....



#include <Wire.h>

#define srfAddress1 0x70                               // Address of the SRF02
#define srfAddress2 0x72                              // Address of the SRF02

#define cmdByte 0x00                                 // Command byte
#define rangeByte 0x02                             // Byte for start of ranging data

byte highByte = 0x00;                                // Stores high byte from ranging
byte lowByte = 0x00;                                // Stored low byte from ranging
int range = 0;
int rangeData;


void setup()
{
   Serial.begin(9600);
   Wire.begin();                               
 }


void loop()
{
  rangeData=getRange(); 
}


int getRange()
{                                               
 
 
//Sensor 1 –Sender-

  Wire.beginTransmission(srfAddress1);             // Start communticating with SRF02
  Wire.write((uint8_t)cmdByte);                         // Send Command Byte
  Wire.write((uint8_t)0x5C);        // Transmit an 8 cycle 40khz burst - no ranging takes place
  Wire.endTransmission(); 
 
   
  //Sensor 2 –Empfänger-
 
  Wire.beginTransmission(srfAddress2);             // Start communticating with SRF02
  Wire.write((uint8_t)cmdByte);                         // Send Command Byte
  Wire.write((uint8_t)0x57);                               // Fake Ranging Mode - Result in centimeters
  Wire.endTransmission(); 
 
  delay(100);                                                           
 
  Wire.beginTransmission(srfAddress2);       // start communicating with SRFmodule
  Wire.write((uint8_t)rangeByte);                 // Call the register for start of ranging data
  Wire.endTransmission();
 
  Wire.requestFrom(srfAddress2, 2);            // Request 2 bytes from SRF module
 
  while(Wire.available() < 2);                    // Wait for data to arrive
  highByte = Wire.read();                           // Get high byte
  lowByte = Wire.read();                           // Get low byte
 
  range = (highByte << 8 ) + lowByte;              // Put them together
 
  //print it
  Serial.print("Entfernung zwischen 1&2: ");
  Serial.println(range, DEC);   
  delay(1500);


  return(range);                                                    // Returns Range

}
6  Using Arduino / Sensors / Re: Arduino -> mehrere SRF02 Sensoren on: October 28, 2012, 06:34:22 pm
Thanks for your advice. 

I have replaced

range = (highByte << 8 ) + lowByte;              // Put them together
 
  //print it
  Serial.print("                Entfernung2: ");
  Serial.println(rangeData, DEC);   
  delay(500);

with

range = (highByte << 8 ) + lowByte;              // Put them together
 
  //print it
  Serial.print("                Entfernung2: ");
  Serial.println(range, DEC);   
  delay(500);

and it works now.

Can i delete some parts of the code or can i make the code a bit shorter? Do you have any idea, or is it right now?
7  Using Arduino / Sensors / Arduino -> mehrere SRF02 Sensoren on: October 27, 2012, 11:16:07 pm
Hallo
für ein Projekt möchte ich mehrere SRF02 Sensoren über ein Arduino Mikrocontroller abfragen.
Die Abfrage eines einzelnen Sensors funktioniert auch.

Ich benutze dazu diesen Code -> http://arduino.cc/forum/index.php?topic=86368.0;wap2

Soweit so gut.
Die Abfrage von mehrere SRF02 Sensoren bekomme ich leider nicht hin. Dazu habe ich versucht den oberen Code etwas zu ergänzen.

Problem: die Ausgabe für "Entfernung1" und "Entfernung2" gibt immer den gleichen Wert aus!!
Ich vermute das bevor "Entfernung2" gemessen wird ich wahrscheinlich den Speicher wieder auf Null setzen müsste. Bin allerdings neu auf dem Gebiet und noch nicht so fit in der Programmiererei.



#include <Wire.h>

#define srfAddress1 0x70                               // Address of the SRF02
#define srfAddress2 0x72                              // Address of the SRF02

#define cmdByte 0x00                                 // Command byte
#define rangeByte 0x02                             // Byte for start of ranging data

byte highByte = 0x00;                                // Stores high byte from ranging
byte lowByte = 0x00;                                // Stored low byte from ranging
int range = 0;
int rangeData;


void setup()
{
   Serial.begin(9600);
   Wire.begin();                               
 }


void loop()
{
  rangeData=getRange(); 
}


int getRange()                                                      // This function gets a ranging from the SRF02
{                                               
 
//Sensor 1

  Wire.beginTransmission(srfAddress1);             // Start communticating with SRF02
  Wire.write((uint8_t)cmdByte);                         // Send Command Byte
  Wire.write((uint8_t)0x51);                               // Send 0x51 to start a ranging
  Wire.endTransmission(); 
 
  delay(100);                                                           // Wait for ranging to be complete
 
  Wire.beginTransmission(srfAddress1);       // start communicating with SRFmodule
  Wire.write((uint8_t)rangeByte);                 // Call the register for start of ranging data
  Wire.endTransmission();
 
  Wire.requestFrom(srfAddress1, 2);            // Request 2 bytes from SRF module
 
  while(Wire.available() < 2);                    // Wait for data to arrive
  highByte = Wire.read();                           // Get high byte
  lowByte = Wire.read();                           // Get low byte
 
  range = (highByte << 8 ) + lowByte;              // Put them together
 
  //print it
  Serial.print("Entfernung1: ");
  Serial.print(rangeData, DEC);   
  delay(500);

 
  //Sensor 2
 
  Wire.beginTransmission(srfAddress2);             // Start communticating with SRF02
  Wire.write((uint8_t)cmdByte);                         // Send Command Byte
  Wire.write((uint8_t)0x51);                               // Send 0x51 to start a ranging
  Wire.endTransmission(); 
 
  delay(100);                                                           // Wait for ranging to be complete
 
  Wire.beginTransmission(srfAddress2);       // start communicating with SRFmodule
  Wire.write((uint8_t)rangeByte);                 // Call the register for start of ranging data
  Wire.endTransmission();
 
  Wire.requestFrom(srfAddress2, 2);            // Request 2 bytes from SRF module
 
  while(Wire.available() < 2);                    // Wait for data to arrive
  highByte = Wire.read();                           // Get high byte
  lowByte = Wire.read();                           // Get low byte
 
  range = (highByte << 8 ) + lowByte;              // Put them together
 
  //print it
  Serial.print("                Entfernung2: ");
  Serial.println(rangeData, DEC);   
  delay(500);


  return(range);                                                    // Returns Range

}
Pages: [1]