[Solved] Help Reading Serial Data

I am at my wits end. I am almost positive this is the result of something stupid that I’m doing, but I just cannot figure it out and it’s making me go nuts!!!

As detailed in posts #150-164 in this thread, I was having issues receiving data from a sensor via RS232 serial interface. I eventually figured out that a null modem adapter was necessary.

I had since moved onto various other parts of the project and finally arrived at the stage where I had to marry all of the hardware components together into one beautiful, integrated application. This is when I realized that I could no longer read data from my sensor via the serial connection. The symptoms were similar to those I noticed before I began using the null modem adapter.

This is absolutely infuriating. Everything is setup exactly how it was when I first successfully read data from the sensor using my RS232 shield and the null modem adapter.

The sensor is sending data just like it always has been, and it is formatted in the exact same way. I can see it in a terminal window when I connect the sensor directly to my computer. Now, however, I can't even get sensorStream.available() to return true in my code. I removed the available() check and read characters from the stream and wrote them to the console. All I am seeing is negative ones.

It was almost like the null modem adapter had gone bad, but that’s virtually impossible. Even so, I tested another null modem adapter with the same results.

I have tried everything I can think of. I have tried the most basic of code (the same code I originally used to successfully read data from this serial stream) and the most basic of circuits (nothing connected except the RS232 shield/module).

I have tried the following combinations (all tried with and without null modem adapter and jumpered to various pins for rx/tx):

Uno + RS232 shield Uno + RS232 module (not a shield) Mega + RS232 shield Mega + RS232 module (not a shield)

I have also tried multiple different baud rates (to no avail), though 9600 was working just fine before the universe became devoid of logic.

I have no other ideas. This has stopped my progress dead in its tracks, and it’s so discouraging.

Please help!

RS-232 requires a ground wire as well as the two data wires. Is the ground wire still hooked up? Have you looked at the voltages on both ends of both data wires?

Paul

Paul_KD7HB: RS-232 requires a ground wire as well as the two data wires. Is the ground wire still hooked up? Have you looked at the voltages on both ends of both data wires?

Using the RS232 shield, I'm assuming it grounds itself to the arduino; I never needed any sort of ground wire when it was previously working.

The RS232 module has four pins: VCC, gnd, tx, and rx. I connected all of them during my testing.

I have not yet tested any voltages. Honestly, I've been too discouraged to do so.

Hi, I think you will find shield(protective gnd) is different from signal gnd.

Tom... :)

hawleycj: Using the RS232 shield, I'm assuming it grounds itself to the arduino; I never needed any sort of ground wire when it was previously working.

The RS232 module has four pins: VCC, gnd, tx, and rx. I connected all of them during my testing.

I have not yet tested any voltages. Honestly, I've been too discouraged to do so.

Discouraged? You should try doing this for a living and have to drive 20 miles to see if your RS-232 is working.

Paul

I just cannot figure out why it is not working in the same exact configuration that it was before.

If the sensor sends data correctly to your computer then I would question the approach of using only a factory made null modem cable with absolutely no idea how it is wired. The fact that it worked before doesn't relieve of the responsibility to actually know how tge null modem cable is wired. If it is wired correctly then fine, but we need to know how it is wired. Put your meter in beep mode and beep out the cable using male to male jumpers to connect to the female pins. Post a link for the RS232 module that is not a shield. Make a wiring list that shows sensor pin numbers to arduino pin numbers with null modem pin numbers in between so we can see the connection path from one end to the other. Also, tear apart any wiring you had previously connected and beep out any jumper wire befire using it again. Post a scrrenshot of your serial monitor window that shows your baud rate setting and a screenhot of your IDE that shows your code ( with and without Serial.available() ) (I don't know what "Sensorstream.available" is) (never heard of that) You are effectively starting at the beginning.

I GOT IT WORKING!!

I’m not quite sure how, but I got it working, nonetheless. Certain combinations of hardware just were NOT cooperating, and I'm not exactly sure why. When i was originally frustrated with this problem a few days ago (as a result of not using the null modem adapter), I thought my RS232 shield was faulty (it had been chewed on by dogs, after all), so I ordered a few more RS232 modules/interfaces. After I ordered them and before they arrived, I got things working with the null modem adapter and realized that my RS232 shield that had been chewed on by the dogs was, in fact, still very functional.

Since yesterday when I realized I could no longer read data from the sensor, I have never once gotten anything to work with that original dogtoy RS232 shield.

As mentioned in the OP, last night and earlier today I tried using one of the other RS232 modules that I purchased and still had no luck. Contrary to what I stated in my original post, I'm not 100% sure if I tried testing the RS232 module without the null modem adapter or not. I may not have... I'm just not sure. Lack of sleep definitely affects my analytical skills and memory.

Regardless, about a half hour ago I tried another one of the OTHER RS232 modules that i had purchased. I soldered the headers onto it and ran vcc to the 5 volt pin on the arduino, gnd to gnd, tx to pin D4, and rx to pin D5. This module had a male connector on it, so I did not have to use a gender changer. I simply connected the serial cable from the sensor to the null modem adapter, and connected that to the RS232 module.

I tested things once again, positive that nothing would change, and it didn't. I really was on the verge of giving up, at this point. As a last ditch effort, however, I decided to remove the null modem adapter and test it once again (serial cable directly into RS232 module, at this point). I almost didn't even look at the serial output... but out of the corner of my eye I saw REAL DATA. I didn't even think it was real, at first. I thought someone was fucking with me. After closer inspection, however, I realized that everything was working as it once was.

I then rejoiced by disrobing and dancing in the rain.

Thanks guys.

I'll expect a full report on my desk in the morning.

raschemmel: I'll expect a full report on my desk in the morning.

Hah. Hopefully by morning I will be posting tales of my liquid dispensing victories.

or crying like little girl....

raschemmel: or crying like little girl....

You know me too well. HOWEVER, if I cried, I would probably fib and tell you that I was stoic and manly, so you wouldn't think less of me.

Edit: ROFL... "beep mode?" You cheeky bastard, you. ;)

Hi,

This module had a male connector on it, so I did not have to use a gender changer.

Have you checked how the male connector shield is wired compared to the other female connector shields?

I then rejoiced by disrobing and dancing in the rain.

Sounds like you have done it before.... :o

Tom.... :)

"Beep Mode": Continuity test mode . ( meter dial to position that shows the audible anunciator symbol thst looks like a volume symbol. "cry like a little girl": Express discouragement and frustration due to failure to take notes and make wiring lists that document how things are wired. "I don't remember if I was using the null modem cable or the shield the dogs chewed because it was late and I was tired." Translation: Keep a lab journal and take notes. ( less crying)

My point is that if we chalk up your success to blind luck and analyze the methods you used to persue your project we can only conclude that it was hap hazard and unoraganized or systematic:

1- you never posted a list of your equipment , so we could never have suggested that you try one of the OTHER RS232 modules since you never told us about them or listed or linked them. 2- you obviously didn't take notes 3- you don't know how the null modem cable is wired 4- You don't know why the "dog toy shield" didn't work (the second time) 5- you don't know why the OTHER module worked (at the end).

Had you proceeded in a systematic fashion you would have tried ALL the modules at the start to ascertain which ones work and which ones don't and why. Your haste to "get your project working" led you to skip many steps that are part of the prototyping method, like taking notes, making wiring lists , understanding WHY things are working and why they are not. Even now you can not tell us definitively whether or not it was necessary for you to purchase not one, but TWO NULL modem cables , which , if we are to believe you , did not work at the "end" . forcing you to resort to one of the OTHER (unnamed, unlisted, unposted) modules, which , acccording to your story, is the what you wound up with. You are obviously not a technician so it would not be fair to expect you to behave like one, but when you post for a project that INVOLVES electronics, you need to follow some standard electronics practices, which includes making an effort to understand how things should be wired and why they are working, which includes schematics, (which you never posted) and wiring lists (which you never posted). Your method of "I don't know why anything works and I don't care, I'll just try different stuff until it works..." is a poor approach. I would recommend that next time you make wiring lists, try to understand how things should be wired, and take notes. You got lucky this time. Next time you might not be so lucky. You get a gold star for cleaning up your wiring if it's any consolation but you get lots of points deducted for being disorganized and not documenting anything. We still don't even know what module you used to get it working or what it looks like or the vendor link. How is anything in this thread going to help anyone else in the world who might want to know something about serial data ? Did you post any schematics ? (no) Do we know (exactly) what you used to get it working ? (no)

It is not necessary to have a schematic capture program to post schematics. The recommended method on the forum is draw the schematic on a blank sheet of printer paper with a dark ball point pen and photogragh it with a cell phone and post the photo.

Sheesh, not sure what I did to deserve that lecture. Maybe you just had some time to waste. Hopefully the cheeky bastard remark didnt offend you.

Edit: I have told you multiple times that I am extremely rushed to complete this project. I don't have time to properly research everything, check the pinouts on every component, and take notes. I'm sure you think it would be a lot faster if I did everything correctly, but that just isn't the case. You've been doing things the "right" way for years, and it's second nature to you. Taking the time to do everything exactly by the book is not feasible for me right this second. In the future, I will take the time to properly research everything and be methodical and analytical and systematic, but right now I just HAVE to get this working.

I know you think I'm pretty worthless at all of this, but I don't really care. All of my friends and business partners are amazed at the progress I am making, and that's all that matters to me.

It's not personal. We're not here to stroke your ego. Think of us like a college professor. We're going to tell you what we think you need to hear, not what we think you want to hear.

Our job is to help you solve your problem and learn how to avoid problems in the future. Your problem (believe it or not) has nothing to do with serial data or scale sensors but rather to do with being disorganized and avoiding the more tedious tasks in electronics, like ohming out cables and recording wiring lists. If you knew why the RS232 module worked at the end , you would probably know why the other stuff didn't work. Your observations seemed contradictory, (ie, one minute it worked with the Null modem cable, the next minute it didn't) yet it wasn't the sensor, your computer, or the arduino so we really don't know what went down here. The only thing we know is that we never knew exactly what you had at your disposal that you weren't telling us. Telling you "congratulations " when it started working wouldn't make sense if you have no idea what you did to make it work would it ? What can anyone else take away from this thread ? If you ask me, I would say , this is how NOT to do a project. Be organize, take notes, and make an effort to understand WHY things are working by learning HOW they work, which means drawing schematics and asking questions. You came here for help but in the end there was nothing we could do to help you because we lacked all the details and once you got it working , that was the end of this post. If you want to redeem yourself you can post a link for the RS232 module that is currently working and the code you are currently using to make it work. We never knew what sensor it was but that doesn't matter any more.

raschemmel:
It’s not personal.

Eh, I don’t agree. Comments like “cry like a girl” are getting a bit personal and aren’t very beneficial to anything, in my opinion. I can take it, but it does change the tone of the conversation and makes me want to respond with similarly instigatory remarks. Again, I don’t feel that’s beneficial in the least bit.

raschemmel:
You came here for help but in the end there was nothing we could do to help you because we lacked all the details and once you got it working , that was the end of this post. If you want to redeem yourself you can post a link for the RS232 module that is currently working and the code you are currently using to make it work. We never knew what sensor it was but that doesn’t matter any more.

I used the female version of this RS232 to TTL converter.

Here is the test code I wrote…

#include <SoftwareSerial.h>

// Arduino hardware pin mappings
#define rxPin 10   // arduino pin connected to the RX lead from the RS232/TTL converter
#define txPin 11   // arduino pin connected to the TX lead from the RS232/TTL converter

double currentSensorValue;

// Instantiate our serial stream from the sensor
SoftwareSerial sensorSerialStream = SoftwareSerial(rxPin, txPin);

void setup()
{
  // Set our pin modes
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);

  // Open the stream to receive data from the sensor
  sensorSerialStream.begin(9600);

  // Open standard serial stream for viewing outputting data and debugging info to the serial monitor
  Serial.begin(19200);
}

// Returns one line of serial data from the sensor (ending with \r or \n)
String getLineFromSerial()
{
  String serialString = "";
  char charFromStream;

  // Read characters and concatenate them to the string we will return.
  // Stop reading when a newline or carraige return is read.
  while (!serialString.endsWith("\r") && !serialString.endsWith("\n"))
  {
    charFromStream = (char)sensorSerialStream.read();
    serialString += charFromStream;
  }

  return serialString;
}

// Reads serial data from the sensor, line by line, until a value is received, then returns it
double getCurrentSensorValue()
{
  double currentSensorValue = -1;
  String lineFromSerial = "";

  // Make sure the stream is available
  if(sensorSerialStream.available() > 0)
  {
    // Get a new line from the sensor serial stream until one is found that starts with "VALUE"
    while (!lineFromSerial.startsWith("VALUE"))
      lineFromSerial = getLineFromSerial();

    // Parse the line of data, pulling out the actual value
    currentSensorValue = lineFromSerial.substring(6,11).toFloat();
  }
  else
    Serial.println("Serial stream was not accessible");

  return currentSensorValue;
}

void loop()
{
  // Get the value from the sensor and print it if it's greater than 50.0
  currentSensorValue = getCurrentSensorValue();
  
  if (currentSensorValue > 50.0)
    Serial.println("Current sensor value = " + (String)currentSensorValue);
}

Edit: Oh, and I am fully aware of continuity mode on a DMM. I have used it plenty of times. The cheeky bastard comment was indicating that I realized u were dumbing it down for me by calling it “beep mode,” in an attempt to be condescending. I think that went over your head, though.

hawleycj: I know you think I'm pretty worthless at all of this, but I don't really care. All of my friends and business partners are amazed at the progress I am making, and that's all that matters to me.

You didn't make much progress. You got lucky. If you only needed to do this one time, then "woot". But if you plan to do more of this kind of thing, it would behoove you to consider Raschemmel's comments. He's not criticizing your skill. This is pretty much a beginner forum. It's your approach. You won't get very far unless you change it.

The part that will hurt you the most in places like this, is that people will tire of you wasting their time, and lose interest in helping you.

aarg: You didn't make much progress. You got lucky.

Okay, I got lucky; whatever you say. All of these parts just magically assembled themselves and it worked out of pure randomness. Look, I realize I have my faults and that my process throughout this whole thing was less than "proper," but saying I got lucky is insulting.

As for not making much progress: well, it might not seem like much progress to you, but I assure you that it is. I have written almost one thousand lines of code that you all haven't seen and my proof of concept for my invention is almost complete.

aarg: If you only needed to do this one time, then "woot". But if you plan to do more of this kind of thing, it would behoove you to consider Raschemmel's comments. He's not criticizing your skill. This is pretty much a beginner forum. It's your approach. You won't get very far unless you change it.

I am not ignoring Rasch's comments. I never implied that I was and I even said I would use proper process on future projects. Yes, I only have to do THIS one time. How hard is it to realize that I'm rushed and don't have to time to do everything the absolute right way for this project? I guess I will just stop posting until I have time to be more methodical and less scatter-brained.

aarg: The part that will hurt you the most in places like this, is that people will tire of you wasting their time, and lose interest in helping you.

I am not wasting anyone's time. Respond if you want, or don't. I'm not telling anyone to do anything for me. I'm simply asking for advice/help. This is a forum. I'm sorry if you don't think I'm asking for help in the exact right manner.

Just one point. It is definitely possible to waste the time of a volunteer. When someone offers free help, it's true that it's not binding in the way that a job or an assignment is. But the willingness to give comes from the reward of seeing the advice actually improve something or someone. Of course there is no obligation for the recipient. The involvement in an extended dialogue increases the investment that the helper has. So of course, it is a correspondingly increased disappointment if they see that the advice or assistance that they have offered has been ignored or misused. Even the most mature person will feel some resentment. You should realize that you will create those kind of reactions even if people don't reveal them to you.