Please help on TX

Hello,

I have a Arduino Uno. Wrote code to use with the LSM303 and using the USB cable, I get a nice number of NMEA sentences. However, the data needs to go into a serial port on my (old) computer, or go into the multiplexer. This needs to be tty logic.

I spent hours searching for a solution on how to get the TX pin working, and did not find a fix, only many people searching for a similar solution.

The code I'm using:

#include <Wire.h>
#include <LSM303.h>
#include <AverageList.h>
#include <SoftwareSerial.h>
LSM303 compass;
SoftwareSerial mySerial(2, 3); // RX, TX

const byte MAX_NUMBER_OF_READINGS = 10;
int storage[MAX_NUMBER_OF_READINGS] = {0};
AverageList<int> list = AverageList<int>( storage, MAX_NUMBER_OF_READINGS );

void setup() {
  Serial.begin(9600);
  pinMode(2, INPUT);
  Wire.begin();
  compass.init();
  compass.enableDefault();
  
  // Calibration values. Use the Calibrate example program to get the values for
  // your compass.
  compass.m_min.x = -550;  compass.m_min.y = -357;  compass.m_min.z = -460;
  compass.m_max.x = 223;  compass.m_max.y = 378;  compass.m_max.z = 300;
}


/*----------------------------------------------------------------------------
        1   2   3 4   5 6
        |   |   | |   | |
 $--HDG,x.x,x.x,a,x.x,a*hh<CR><LF>
------------------------------------------------------------------------------

Field Number: 
1. Magnetic Sensor heading in degrees
2. Magnetic Deviation, degrees
3. Magnetic Deviation direction, E = Easterly, W = Westerly
4. Magnetic Variation degrees
5. Magnetic Variation direction, E = Easterly, W = Westerly
6. Checksum */

char nmeastr[17]; // HCHDG,000.00,,,,*
int checksum;
char hs[6]; // 000.00

void loop() {
  
  strcpy(nmeastr,"HCHDG,");
  //dtostrf(FLOAT,WIDTH,PRECSISION,BUFFER);
  compass.read();
  
  int heading = compass.heading((LSM303::vector){0,-1,0}); //1,0,0 will allign North with SFE silkscreen
  
  //int rand = compass.heading((LSM303::vector){0,-1,0});
  //Serial.print("Heading list : ");
  //Serial.println(heading);
  list.addValue(heading);

  //list.debug("list",Serial); //print contents to serial console
  //Serial.print("Average: ");
  //Serial.println(list.getAverage());
  
  //dtostrf(compass.heading((LSM303::vector){0,-1,0}), 5, 2, hs);
  dtostrf(list.getAverage(), 5, 2, hs);
  //dtostrf(heading, 5, 2, hs);
  //Serial.print("hs ");
  //Serial.print(hs);
  //Serial.println();  
  
  strcat(nmeastr,hs);
  strcat(nmeastr,",,,,");
  
  //add a checksum
  checksum=0;
  for (int n=0; n < strlen(nmeastr); n++) {
    checksum ^= nmeastr[n];
  }
  
  Serial.print("$");
  Serial.print(nmeastr);
  Serial.print("*");
  Serial.print(checksum, HEX);
  Serial.print("\t");
  Serial.println();
  
  /* 5hz == 200 */
  delay(100);
}

For the tty logic I built a board as found here: http://prosje.be/CO/Schemas/RS232-to-TTL3.png The mentioned rs232 in the schema is connected to the TX pin 1.

Any help is highly appraciated on how to solve this issue. Am I working in the right direction??

Many thanks in advance!

Thanks Nick. Do I understand you correct if you say that in my current comfiguration it is not possible to get an output that I can either use vor rs232 or to have tty-logic for my multiplexer?

Many thanks for your time.

Well RS232 as I recall is (around) +15 or -15V. Your circuit is not going to generate -15V, so your device may not work.

The MAX232 generates the required voltages using capacitors and charge pumps.

I'm not saying that will fix it, but it might help.

Ok, thanks so far. If I skip the rs232 and only want tty logic, can you please tell what is required in that case?

Thanks again!

What is tty logic? I know TTL but a tty is a terminal on my computer. If you mean TTL, you already have that on your Arduino, so you can just connect your TX pin and a GND pin to your TTL device.

oops, TTL :wink:

To give the output to my laptop, it needs to be an rs232 signal. I just read through the manual of the mulitplexer and that one can also read a rs232 signal. But, as far as I understand, the TX can not be fed to the rs232 port

Correct, use a MAX232 (or a smiliar chip) as Nick Gammon suggested earlier.