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);
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.
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.
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.
AWOL:
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.
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.