Offline
Newbie
Karma: 0
Posts: 28
|
 |
« on: October 08, 2012, 07:52:58 am » |
Good morning all,
I'm trying to comunicate the arduino with an inclinometer (rs 232 comunication, sensor have 4 pins vcc, gnd, rx, tx so a found that the comunication should be easy) then i need to send to the sensor what i want ('X' or 88 in ascii, then 'Y' or 89 in ascii) and recive the angles. I tried with softwareserial with no results. I think hardwareserial should work but i dont realy know how to use it. I have searched for it but i just found ready examples that i didnt understand nothing. Have anyone any tutorial, or something explained in detail ? Do you have any other ideia how can i comunicate to the sensor ?
The sensor is the inclinometer 0729-1752, and one of the codes using Softwareserial that i tried to use was that:
#include <SoftwareSerial.h> SoftwareSerial portOne(2, 3); int ax = 88; int ay = 89;
void setup() {
Serial.begin(9600); portOne.begin(9600); }
void loop() {
portOne.write(ax); float x = portOne.read(); delay(100); portOne.write(ay); float y = portOne.read(); delay(100);
Serial.print(x); Serial.println(y);
}
Thanks for all, any help with be very welcome.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 143
Posts: 19367
I don't think you connected the grounds, Dave.
|
 |
« Reply #1 on: October 08, 2012, 07:54:04 am » |
What are you using for RS232 level conversion? float x = portOne.read(); The "read" method returns an "int" representing a single character, not a floating point number. You need to buffer the characters representing the float, and use an explicit method like "atof" to convert from ASCII.
|
|
|
|
« Last Edit: October 08, 2012, 07:58:27 am by AWOL »
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 28
|
 |
« Reply #2 on: October 08, 2012, 08:08:33 am » |
I dont really know if a level conversion is needed cause i guess the sensor already have a level converter, And i did comunicate the sensor with the pc using realterm (but unfortunately i cannot use a pc for the aplication) without using a level converter, thats why i think its a software problem.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 143
Posts: 19367
I don't think you connected the grounds, Dave.
|
 |
« Reply #3 on: October 08, 2012, 08:11:58 am » |
RS232 communication to an Arduino does need a signal level converter. RSR23 levels can be up to +/- 25 volts, and are inverted with respect to the TTL levels the Arduino expects.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 28
|
 |
« Reply #4 on: October 08, 2012, 08:15:09 am » |
What are you using for RS232 level conversion? float x = portOne.read(); The "read" method returns an "int" representing a single character, not a floating point number. You need to buffer the characters representing the float, and use an explicit method like "atof" to convert from ASCII. Yeah, thats problaby the problem, so do i need to recive int by int and create a buffer for that ? the signal from the sensor is 16bits for angles and 10bits for temperature.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 143
Posts: 19367
I don't think you connected the grounds, Dave.
|
 |
« Reply #5 on: October 08, 2012, 08:22:24 am » |
the signal from the sensor is 16bits for angles and 10bits for temperature. In which case, I don't see why you're trying to read a float. Do you have a link to this device?
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 143
Posts: 19367
I don't think you connected the grounds, Dave.
|
 |
« Reply #7 on: October 08, 2012, 08:35:36 am » |
OK, so it is RS232, so you do need level conversion. It doesn't say whether the result is big- or little-endian, you'll need to figure that out. You just read two bytes and either shift the most-significant left by 8 bits, or multiply by 256.
No floats involved.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 28
|
 |
« Reply #8 on: October 08, 2012, 08:41:10 am » |
Ok i will try that, working or not i will post it here then, thanks a lot.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 143
Posts: 19367
I don't think you connected the grounds, Dave.
|
 |
« Reply #9 on: October 08, 2012, 08:44:23 am » |
BTW int ax = 88; int ay = 89; is much easier to read as char xCommand = 'X'; char yCommand = 'Y'; (or whatever "Command" translates to in Portugese)
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 28
|
 |
« Reply #10 on: October 08, 2012, 09:03:47 am » |
BTW int ax = 88; int ay = 89; is much easier to read as char xCommand = 'X'; char yCommand = 'Y'; (or whatever "Command" translates to in Portugese) yeah this i already tried ^^
|
|
|
|
|
Logged
|
|
|
|
|
|