Serial input on an Arduino Mega

Hello,

I am trying to take in data from the Recorder/TTL port of an IL1700 radiometer, and log it to an SD card. (IL1700 Manual: http://www.intl-lighttech.com/support/manual/IL1700.pdf) It is connected to the rx1 line and the request to send pin is connected to a data pin. Everything works fine and data is coming out as expected with 1 start bit, 8 data bits, and 1 stop bit, except that the data is gibberish and unusable. It remains constant when the light reading is constant and changes when the light reading changes but there is no way to use the data. I have tried converting it to ascii but that doesn’t help. I assume that it is a problem with translation but I don’t know what to do or how to fix that. Here is a simple sketch I wrote to just read the serial port and print out the data.

#define rx 19           // connected to the inverted data line on the radiometer
#define tx 13           // connected to the (inverted) Request To Send pin on the radiometer 
                          // LOW = Initiate transmission, HIGH = cut

byte incomingByte = 0;                                        // for incoming serial data

void setup() 
{
  Serial1.begin(1200);               // Initializes the serial port 1 (rx1 pin 19 & tx1 pin 18) to 1200 baud
  Serial.begin(1200);                 // Initializes the serial port 0 (serial monitor on my mac) to 1200 baud


  pinMode(tx,OUTPUT);            // set the tx pin (13) to be a digital output
  delay(1000);                           // delay 1 second 
}



void loop()
 {

  digitalWrite(tx,LOW);      // Initiate transmission of data string
  
  if(Serial1.available() > 0)    // if serial data is available
     {
      incomingByte = Serial1.read();       // read a byte off of the serial port 1

      Serial.println(incomingByte);           // print this byte out on the serial monitor
      digitalWrite(tx,HIGH);           // cut transmission
      }

}

Here is some sample output I get: (I am looking for something like " 7.71e -9")

j
2
4
2
3
M
i
c
y
=
j
Ì
ó
&
¦
R
Ó
Ê
=
j
d
4
3
3
M
i
c
y
=
j
d
4
3
g
M
i
c
y
=
j
d
4
3
g
M
i
c
y
=
j
d
4
3
¦
R
Ó
Ê
=
j
d
4
3
¦
R
Ó
Ê

The manual says that it is an inverted data line so I’ve tried using the line (incomingByte = incomingByte ^ 0xFF;) to change it back but it’s still garbage… Any help would be appreciated =)

Thanks
~ Andy

This is a common error. You want the numeric value of the byte but when you print out a 'byte'-typed variable then Serial.println() prints its ASCII character value.

Use the following:

Serial.println((unsigned) incomingByte);

That will interpret the value as an integer rather than an ASCII character.

-- Check out our new shield: http://www.ruggedcircuits.com/html/gadget_shield.html

Ok,

I changed that but now I am just getting strings of numbers that don't correspond to what the output should be...

The output should be +2.08e-9 but instead I got these sets of numbers

Not inverted: Inverted: 106 149 51 204 52 203 230 25 76 179 147 108 154 101 76 179 30 225 61 194

I tried converting it to ascii but got nothing =/

The output should be +2.08e-9 but instead I got these sets of numbers

Well, are you're going to get are 8-bit bytes, or numbers in the range 0-255. How those are constructed by the IL1700 to represent actual readings is described in the manual (section 4.3.4). You will have to write a fair bit of code to take the data stream byte-by-byte and interpret it as real numbers, according to the manual.

Also, reading through the manual it looks like the serial port is actually an RS-232C serial port meaning the output voltage swings from +8V to -8V. You cannot connect this directly to your Arduino else you may damage it. You need a RS232-to-logic converter like a MAX232 or MC1489.

-- Check out our new shield: http://www.ruggedcircuits.com/html/gadget_shield.html

Do I need a RS232-to-logic converter if I'm connecting with a telephone cable coming out of the TTL port of the IL1700? It says "The output voltage level on pin 5 of the RJ11c jack, is produced by a CMOS peripheral interface chip, which is capable of driving one TTL load. This means that the voltage swing will be the full 5 volts instead of the typical TTL voltage of +4 volts"

And also would you know where I could find out how to convert it byte by byte? I've tried looking for a pattern but I assume its a code written somewhere...

Do I need a RS232-to-logic converter if I'm connecting with a telephone cable coming out of the TTL port of the IL1700? It says "The output voltage level on pin 5 of the RJ11c jack, is produced by a CMOS peripheral interface chip, which is capable of driving one TTL load. This means that the voltage swing will be the full 5 volts instead of the typical TTL voltage of +4 volts"

Good point! I didn't read that far. You're right, you won't need a converter when using this TTL port.

And also would you know where I could find out how to convert it byte by byte? I've tried looking for a pattern but I assume its a code written somewhere...

Yes, the code is written in Section 4.3.4 of the manual :)

-- Check out our new shield: http://www.ruggedcircuits.com/html/gadget_shield.html