Offline
Newbie
Karma: 0
Posts: 15
|
 |
« on: March 22, 2013, 09:14:29 pm » |
Hello, I am trying to use an Ulrasonic range finder, SRF01, with SoftwareSerial, but I cannot seem to get it to work. Here is the product, http://www.robot-electronics.co.uk/htm/srf01tech.htmI get this error when I try to upload this code to my Arduino 2560. c:/users/MYNAME/desktop/stuff/arduino-1.0.1/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr6/crtm2560.o: In function `__vector_default': (.vectors+0xcc): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_51' defined in .text.__vector_51 section in core.a(HardwareSerial.cpp.o)
I am running Windows 7 (64 bit) and here is my code. From this page http://arduino.cc/forum/index.php?topic=131592.0// Code modified and developed by Will Myers and Justin Miller
#include <SoftwareSerial.h>
#define txrxPin 10 // Defines Pin 10 to be used as both rx and tx for the SRF01 #define srfAddress 0x01 // Address of the SFR01 #define getSoft 0x5D // Byte to tell SRF01 we wish to read software version #define getRange 0x53 // Byte used to get range from SRF01 in inches #define getStatus 0x5F // Byte used to get the status of the transducer
SoftwareSerial UltrasonicBus(txrxPin, txrxPin); // Sets up the SoftwareSerial with Digital Pin 10 and sets the name to "UltrasonicBus"
void setup(){ Serial.begin(19200);
UltrasonicBus.begin(9600); delay(200); // Waits some time to make sure that SRF01 is powered up Serial.println("SRF01 Test"); SRF01_Cmd(srfAddress, getSoft); // Calls a function to get the SRF01 software version while (UltrasonicBus.available() < 1); // Waits to get good data int softVer = UltrasonicBus.read(); // Read software version from SRF01 Serial.print("V:"); Serial.println(softVer); // Prints the software version to LCD03 delay(200);
Serial.println("Initialization Complete"); // After inititalization is complete you should see the correct version of your device printed to the serial monitor }
void loop(){
int max = 1; // Setup so that you can averaqe readings int sum = 0; // Currently I am not taking an average.. Max = 1 for (int count = 0; count < max; count++) { sum = sum + doRange(); // Calls a function to get range from SRF01 and sums the ranges up so that you can take an avg }
int range = sum / max;
Serial.print("Range avg = "); Serial.print(range); // Print range result to the screen Serial.println(" "); // Print some spaces to the screen to make sure space direcly after the result is clear checkLock(); // Calls a function to check if the transducer is locked or unlocked }
void SRF01_Cmd(byte Address, byte cmd){ // Function to send commands to the SRF01 pinMode(txrxPin, OUTPUT); // Set pin to output and send break by sending pin low, waiting 2ms and sending it high again for 1
digitalWrite(txrxPin, LOW); delay(2); digitalWrite(txrxPin, HIGH); delay(1); UltrasonicBus.write(Address); // Send the address of the SRF01 UltrasonicBus.write(cmd); // Send commnd byte to SRF01 pinMode(txrxPin, INPUT); // Make input ready for Rx int availableJunk = UltrasonicBus.available(); // Filter out the junk data for(int x = 0; x < availableJunk; x++){ byte junk = UltrasonicBus.read(); } }
void checkLock() { SRF01_Cmd(srfAddress, getStatus); // Call to a function that checks if the trancducer is locked or unlocked byte statusByte = UltrasonicBus.read(); // Reads the SRF01 status, The least significant bit tells us if it is locked or unlocked int status = statusByte & 0x01; // Get status of lease significan bit if(status == 0) { Serial.println("Unlocked"); // Prints the word unlocked followd by a couple of spaces to make sure space after has nothing in } else { Serial.println("Locked "); // Prints the word locked followd by a couple of spaces to make sure that the space after has nothing in } }
int doRange() { SRF01_Cmd(srfAddress, getRange); // Calls a function to get range from SRF01 while (UltrasonicBus.available() < 2); // Waits to get good data byte highByte = UltrasonicBus.read(); // Get high byte byte lowByte = UltrasonicBus.read(); // Get low byte int dist = ((highByte<<8)+lowByte); // Put them together return dist; }
All it says is error compiling, I have checked for syntax, or undefined variables, and I have all the required code. All my other sketches upload fine. Any help is GREATLY appreciated! Thanks
|
|
|
|
« Last Edit: March 23, 2013, 02:44:52 pm by hrhtml99 »
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Online
Shannon Member
Karma: 219
Posts: 13896
Lua rocks!
|
 |
« Reply #1 on: March 22, 2013, 09:21:06 pm » |
What version of the IDE do you have? That compiled without errors for me using 1.0.4.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
God Member
Karma: 9
Posts: 836
|
 |
« Reply #2 on: March 22, 2013, 09:31:26 pm » |
All it says is error compiling, What does this bogus statement mean ? How do you expect us to give you good advice, if you don't disclose what the compilation error message is ?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 15
|
 |
« Reply #3 on: March 22, 2013, 09:33:11 pm » |
Sorry, I was referring to the main heading, I attached the full error text in my original post.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
God Member
Karma: 9
Posts: 836
|
 |
« Reply #4 on: March 22, 2013, 09:45:18 pm » |
OK, I did not notice that error message there before.
Well that error does not appear to relate to anything which is in your actual sketch.
If I had this problem, I'd try the following.
(1) I'd try putting #include <Arduino.h> at the top, just in case there is some illogical condition with the dependency of some #define'd constant somewhere.
(2) I'd locate and check the file Hardwareserial.h, and check it isn't missing or corrupted.
(3) I'd reinstall the Arduino IDE.
When I first started using Arduino, I did have some problems related to having multiple java installations on my computer. I don't know if this problem could be similar, or not. I don't have those issues any more.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 15
|
 |
« Reply #5 on: March 22, 2013, 09:48:04 pm » |
Thank you Nick, I updated, and it compiles, but all the serial communication returns is "ÓwÌ"
Any ideas?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 15
|
 |
« Reply #6 on: March 22, 2013, 09:50:22 pm » |
Thanks michinyon, I did all three, and now it compiles and uploads, but the serial monitor just returns bogus characters...
This is getting odd,
Thanks everyone for being so helpful!
|
|
|
|
|
Logged
|
|
|
|
|
Offline
God Member
Karma: 9
Posts: 836
|
 |
« Reply #7 on: March 22, 2013, 10:21:07 pm » |
Bogus characters is nearly always serial speed mismatch.
Check the speed of the serial and the speed setting of the serial monitor.
I also don't understand how you started your ultrasonic bus with only one pin.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 15
|
 |
« Reply #8 on: March 22, 2013, 10:34:18 pm » |
Okay, so now with the serial monitor set to 19200 baud, serial prints in "SRF01 Test" and then does nothing. According to the manufacturer, rx and tx are using the same software serial pin. Obviously not at the same time.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Online
Shannon Member
Karma: 219
Posts: 13896
Lua rocks!
|
 |
« Reply #9 on: March 23, 2013, 03:22:18 am » |
I can't think how sending and receiving on the same pin would work.
|
|
|
|
|
Logged
|
|
|
|
|
DELHI
Offline
Full Member
Karma: 0
Posts: 135
|
 |
« Reply #10 on: March 23, 2013, 04:16:22 am » |
This code wont because. you being configured tx and rx pin for same port Hello, I am trying to use an Ulrasonic range finder, SRF01, with SoftwareSerial, but I cannot seem to get it to work. Here is the product, http://www.robot-electronics.co.uk/htm/srf01tech.htmI get this error when I try to upload this code to my Arduino 2560. c:/users/MYNAME/desktop/stuff/arduino-1.0.1/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr6/crtm2560.o: In function `__vector_default': (.vectors+0xcc): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_51' defined in .text.__vector_51 section in core.a(HardwareSerial.cpp.o)
I am running Windows 7 (64 bit) and here is my code. From this page http://arduino.cc/forum/index.php?topic=131592.0// Code modified and developed by Will Myers and Justin Miller
#include <SoftwareSerial.h>
#define txrxPin 10 // Defines Pin 10 to be used as both rx and tx for the SRF01 #define srfAddress 0x01 // Address of the SFR01 #define getSoft 0x5D // Byte to tell SRF01 we wish to read software version #define getRange 0x53 // Byte used to get range from SRF01 in inches #define getStatus 0x5F // Byte used to get the status of the transducer
SoftwareSerial UltrasonicBus(txrxPin, txrxPin); // Sets up the SoftwareSerial with Digital Pin 10 and sets the name to "UltrasonicBus"
void setup(){ Serial.begin(19200);
UltrasonicBus.begin(9600); delay(200); // Waits some time to make sure that SRF01 is powered up Serial.println("SRF01 Test"); SRF01_Cmd(srfAddress, getSoft); // Calls a function to get the SRF01 software version while (UltrasonicBus.available() < 1); // Waits to get good data int softVer = UltrasonicBus.read(); // Read software version from SRF01 Serial.print("V:"); Serial.println(softVer); // Prints the software version to LCD03 delay(200);
Serial.println("Initialization Complete"); // After inititalization is complete you should see the correct version of your device printed to the serial monitor }
void loop(){
int max = 1; // Setup so that you can averaqe readings int sum = 0; // Currently I am not taking an average.. Max = 1 for (int count = 0; count < max; count++) { sum = sum + doRange(); // Calls a function to get range from SRF01 and sums the ranges up so that you can take an avg }
int range = sum / max;
Serial.print("Range avg = "); Serial.print(range); // Print range result to the screen Serial.println(" "); // Print some spaces to the screen to make sure space direcly after the result is clear checkLock(); // Calls a function to check if the transducer is locked or unlocked }
void SRF01_Cmd(byte Address, byte cmd){ // Function to send commands to the SRF01 pinMode(txrxPin, OUTPUT); // Set pin to output and send break by sending pin low, waiting 2ms and sending it high again for 1
digitalWrite(txrxPin, LOW); delay(2); digitalWrite(txrxPin, HIGH); delay(1); UltrasonicBus.write(Address); // Send the address of the SRF01 UltrasonicBus.write(cmd); // Send commnd byte to SRF01 pinMode(txrxPin, INPUT); // Make input ready for Rx int availableJunk = UltrasonicBus.available(); // Filter out the junk data for(int x = 0; x < availableJunk; x++){ byte junk = UltrasonicBus.read(); } }
void checkLock() { SRF01_Cmd(srfAddress, getStatus); // Call to a function that checks if the trancducer is locked or unlocked byte statusByte = UltrasonicBus.read(); // Reads the SRF01 status, The least significant bit tells us if it is locked or unlocked int status = statusByte & 0x01; // Get status of lease significan bit if(status == 0) { Serial.println("Unlocked"); // Prints the word unlocked followd by a couple of spaces to make sure space after has nothing in } else { Serial.println("Locked "); // Prints the word locked followd by a couple of spaces to make sure that the space after has nothing in } }
int doRange() { SRF01_Cmd(srfAddress, getRange); // Calls a function to get range from SRF01 while (UltrasonicBus.available() < 2); // Waits to get good data byte highByte = UltrasonicBus.read(); // Get high byte byte lowByte = UltrasonicBus.read(); // Get low byte int dist = ((highByte<<8)+lowByte); // Put them together return dist; }
All it says is error compiling, I have checked for syntax, or undefined variables, and I have all the required code. All my other sketches upload fine. Any help is GREATLY appreciated! Thanks
|
|
|
|
|
Logged
|
AMPS
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 15
|
 |
« Reply #11 on: March 23, 2013, 01:20:59 pm » |
This code wont because. you being configured tx and rx pin for same port AMPS-N, Here is a quote from the manufacturer, Single Pin Serial Communication Serial data is 1 start, 1 stop and no parity bits. Serial data is a TTL level signal - It is NOT RS232. Do not connect the SRF01 to an RS232 port - you will destroy the module! Communication with the SRF01 is with both serial input and serial output on a single pin. The SRF01 will be listening at all times except when it is actually sending data, and will go back to listening as soon as its finished. To communicate with the SRF01, you simply need to send a "break", followed by two bytes, the address of the SRF01 (factory default is 1) and the command. A "break" is just a low level for 12 bit times or longer. 1.5mS or more will be fine. It is used to synchronize transfers on the 1-wire serial bus. If anyone can help me get this running, I would be immensely appreciative
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 15
|
 |
« Reply #12 on: March 23, 2013, 02:47:08 pm » |
Okay, so now the problem is that the SRF01 does not return any range data to the serial monitor. Here is the code I am using. // Code modified and developed by Will Myers and Justin Miller
#include <SoftwareSerial.h>
#define txrxPin 10 // Defines Pin 10 to be used as both rx and tx for the SRF01 #define srfAddress 0x01 // Address of the SFR01 #define getSoft 0x5D // Byte to tell SRF01 we wish to read software version #define getRange 0x53 // Byte used to get range from SRF01 in inches #define getStatus 0x5F // Byte used to get the status of the transducer
SoftwareSerial UltrasonicBus(txrxPin, txrxPin); // Sets up the SoftwareSerial with Digital Pin 10 and sets the name to "UltrasonicBus"
void setup(){ Serial.begin(19200);
UltrasonicBus.begin(9600); delay(200); // Waits some time to make sure that SRF01 is powered up Serial.println("SRF01 Test"); SRF01_Cmd(srfAddress, getSoft); // Calls a function to get the SRF01 software version while (UltrasonicBus.available() < 1); // Waits to get good data int softVer = UltrasonicBus.read(); // Read software version from SRF01 Serial.print("V:"); Serial.println(softVer); // Prints the software version to LCD03 delay(200);
Serial.println("Initialization Complete"); // After inititalization is complete you should see the correct version of your device printed to the serial monitor }
void loop(){
int max = 1; // Setup so that you can averaqe readings int sum = 0; // Currently I am not taking an average.. Max = 1 for (int count = 0; count < max; count++) { sum = sum + doRange(); // Calls a function to get range from SRF01 and sums the ranges up so that you can take an avg }
int range = sum / max;
Serial.print("Range avg = "); Serial.print(range); // Print range result to the screen Serial.println(" "); // Print some spaces to the screen to make sure space direcly after the result is clear checkLock(); // Calls a function to check if the transducer is locked or unlocked }
void SRF01_Cmd(byte Address, byte cmd){ // Function to send commands to the SRF01 pinMode(txrxPin, OUTPUT); // Set pin to output and send break by sending pin low, waiting 2ms and sending it high again for 1
digitalWrite(txrxPin, LOW); delay(2); digitalWrite(txrxPin, HIGH); delay(1); UltrasonicBus.write(Address); // Send the address of the SRF01 UltrasonicBus.write(cmd); // Send commnd byte to SRF01 pinMode(txrxPin, INPUT); // Make input ready for Rx int availableJunk = UltrasonicBus.available(); // Filter out the junk data for(int x = 0; x < availableJunk; x++){ byte junk = UltrasonicBus.read(); } }
void checkLock() { SRF01_Cmd(srfAddress, getStatus); // Call to a function that checks if the trancducer is locked or unlocked byte statusByte = UltrasonicBus.read(); // Reads the SRF01 status, The least significant bit tells us if it is locked or unlocked int status = statusByte & 0x01; // Get status of lease significan bit if(status == 0) { Serial.println("Unlocked"); // Prints the word unlocked followd by a couple of spaces to make sure space after has nothing in } else { Serial.println("Locked "); // Prints the word locked followd by a couple of spaces to make sure that the space after has nothing in } }
int doRange() { SRF01_Cmd(srfAddress, getRange); // Calls a function to get range from SRF01 while (UltrasonicBus.available() < 2); // Waits to get good data byte highByte = UltrasonicBus.read(); // Get high byte byte lowByte = UltrasonicBus.read(); // Get low byte int dist = ((highByte<<8)+lowByte); // Put them together return dist; }
|
|
|
|
|
Logged
|
|
|
|
|
|