Pages: [1]   Go Down
Author Topic: Interfacing an Altimeter that has Serial Output  (Read 1437 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

I have a question, I have no experience with inputing data from hardware. So, in the user manual of the PerfectFlite Stratto Logger Altimeter, under the 'Telemetry output' section:

The StratoLogger has an on-board data connector that is used for real time data output during flight using the telemetry feature

Serial port settings should be configured for 9,600BPS, 8 data bits, no parity, and 1 stop bit.  Output data format from the altimeter is ASCII text based, with a <CR> and <LF> character appended to the end of each line.

When telemetry data is selected to start “OnLaunch”, all data will be AGL (above ground level) altitudes:
198<CR><LF>   {all data points are AGL altitude}
248<CR><LF>
300<CR><LF>
349<CR><LF>
398<CR><LF>
447<CR><LF>
497<CR><LF>

So I was hoping that some of you could kinda guide me on the part of getting the data into the altimeter. Specially on the part of 9600BPS and 8 data bits, no party and 1 stop bit. What does this all mean

I also don't quite understand that 'the format of the altimeter is ASCII text based'. According to http://www.arduino.cc/en/Reference/ASCIIchart , ASCII is used to encode text into numerical values, but an altimeter does not measure in letters, it measures in numbers (feet or meters)...

If you are reading this and can help in anything of the above it will be greatly appreciated. Thank you.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 525
Posts: 26551
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Insert
Serial.begin(9600);
in void setup.  Default settings are 8 data bits, 1 stop  bit, no parity. Check out RS232 at wikipedia.com for an explanation of serial data transfers.

Check out asciitable.com

If you were to look at the data actually transmitted, you would see 5 bytes of hex code for every line above. The 1, 9, 8, <CR>, <LF> all
have a hex equivelent,  your arduino will receive and those and make decisions as to what to do with the data.
198<CR><LF> would come out as 0x31 0x39 0x38 0x0D 0x0A, where 0x signifies hex data.

So you would have your code look for data, something like this
Code:
if (Serial.available()>0){ // did at least 6 bytes come in?
incomingByte = Serial.read; // read the first character
   if (incomingByte == 0x0A){  // ignore bytes that aren't end of a block of 5 to get in sync
      while (Serial.available <4){ //saw good LF, wait for 5 bytes to come in
      // 5 bytes are in, read them:
        byte0 = Serial.read();  //read hundreds digit
        byte1 = Serial.read();  // read tens digit
        byte2 = Serial.read(); // read ones digit
        byte3  = Serial.read();  // CR
        byte4 = Serial.read(); // LF
       } // end while
      // do something with the data
    } // end 0x0A check
}  // end serial.available check
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

0
Offline Offline
Faraday Member
**
Karma: 8
Posts: 2526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

CrossRoads' code is a good start, but it won't work.  The data isn't a fixed 3 column field; you'll need to be able to deal with varying length numbers.

Here's some code I wrote that reads positive integers.

Code:
#define isdigit(X) (((X) >= '0') && ((X) <= '9')

int read_int()
{
  static byte c;
  static int i;

  i = 0;
  while (1)
  {
    while (!Serial.available())
    {;}
 
    c = Serial.read();
    Serial.print(c, BYTE);
 
    if (c == '\r')
    {
      return i;
    }
    if (isdigit(c))
    {
      i = i * 10 + c - '0';
    }
    else
    {
      Serial.print("\r\nERROR: \"");
      Serial.print(c, BYTE);
      Serial.print("\" is not a digit\r\n");
      return -1;
    }
  }
}

Hopefully the stratologger doesn't throw commas in there when you get >10,000'...

-j
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Note that the manual also states that it is a 3.3V interface.
Logged

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

I was wondering if anyone ever figured out the code for reading the data from a stratologger device in a way that recognizes it as integers so  you can apply some math to the values being transmitted.  I've tried a number of things using the great input posted on Aduino Forum but I'm too much of a newbie to figure it out.  Any thoughts and I'll keep trying!
Logged

Offline Offline
God Member
*****
Karma: 7
Posts: 647
"In this house, we obey the Laws of Thermodynamics" Homer J. Simpson
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
9600BPS and 8 data bits, no party and 1 stop bit
The 9600BPS is the speed (baud rate) at which data is sent, i.e. 9,600 bits per second.
Each data character is made up of a number of bits in this case 8 plus a stop bit makes 9, so 9600 means it could send about 1067 characters every second if it sent data continuously.
The stop bit helps tell where one character ends and the next begins.
Parity is a means of helping detect if a character has been corrupted, in this case parity is not being used.

In general you just setup the transmitter and the receiver to use the same settings and you don't need to worry about the bits. Whole characters are written at the transmitter and read at the receiver, the fact that the were sent as bits is normally invisible to you.

Providing the receiver is able to read the characters faster than the transmitter sends them all is well.
Things get more complicated if your receiver is busy doing other things.

Using serial data is relatively slow so you need to think about how fast your altitude will change and that the interface speed will let you take readings fast enough to get the accuracy you want. No problem in a balloon, but worth checking in a rocket.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 525
Posts: 26551
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

" 9600 means it could send about 1067 characters every second"
Little bit less, you forgot the start bit too. I think you usually see 1 space bit to0 (1 high space after the stop bit), so effectively 11 bits/character.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3639
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Combining the code already supplied gives you this:
Code:
int foo; // Useless declaration to molify the IDE
#define isdigit(X) (((X) >= '0') && ((X) <= '9'))

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

void loop()
{
int AGL=read_int();
// Do math
}


int read_int()
{
static byte c;
static int i;

i = 0;
while (1)
  {
  while (!Serial.available())
    {;}
 
  c = Serial.read();
 
  if (c == '\r')
    {
    return i;
    }
  if (isdigit(c))
    {
    i = i * 10 + c - '0';
    }
  else
    {
    Serial.print("\r\nERROR: \"");
    Serial.print(c);
    Serial.println("\" is not a digit\r\n");
    return -1;
    }
  }
}
Compiled, not tested
Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The "buffering input" code below on Nick's page below would seem to do what you are looking for (assuming the altimeter values are sent as characters). You could add the atoi function if needed.

http://www.gammon.com.au/forum/?id=11425
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Pages: [1]   Go Up
Jump to: