Hello All!
I am working with a sensor that has an 8-pin mini-DIN connection, sending RS232 signals. The wire I am using is an 8-pin mini-din with an open ended other side, see pictures. So I soldered the connections onto a rs232 to TTL board. If I plug the rs232 end directly into a computer via a rs232 to usb, I get this as a result. This is the correct format so the soldering is good.
However, when I attach my photon, I get no response at all. This is my code, it is simple, just publish the data when it receives 48 characters:
char incomingByte = 0; // for incoming serial data
char inData[57]; // Allocate some space for the string
char inChar; // Where to store the character read incoming byte
Index = 0; // Index into array; where to store the character
void setup()
{
Serial1.begin(2400, SERIAL_8N1);
}
void loop()
{
delay(500);
while (Serial1.available() > 0)
{
// read the incoming byte:
//incomingByte = Serial1.read();
if(Index < 56) // One less than the size of the array
{
inChar = Serial1.read(); // Read a character
inData[Index] = inChar; // Store it
Index++; // Increment where to write next
inData[Index] = '\0'; // Null terminate the string
}
if (Index >48)
{
Particle.publish("It Went!",inData);
Index = 0;
delay(600);
break;
}
}
}
So the interesting part is that if I cross my serial input and serial output lines, it works with a few quirks here and there (found this out by accident haha)
Obviously I should not have to cross my lines to get it to work, as it works just fine using the usb to RS232 cable (first two pictures) without crossing the lines. This leads me to believe the problem is within the converter itself maybe? However, when I use the usb-RS232 cable and putty to send the photon data, it works just fine
So, does anyone have any ideas on how to remedy this? Why do all the pieces work separately but not together? Also, I am fairly new to this language so coding tips are always appreciated! Thank You! Attached are some more pics of my set up:
That crossing lines actually is supposed to be done.
The reason why that is not the case for your reference setup is that the crossing is (sort of) happening in the converter.
In a standard serial communication setup the transmitting line (TX) needs to be connected to the receiving line (RX) of the other device and the same in the opposite direction.
BTW, real RS232 signal levels aren’t appreciated by the Photon, make sure the actual voltages fall into the TTL range 0V…5.0V.
Also all these non-insulated wires and solder blobs don’t fill me with much confidence either.
2 Likes
Hey ScruffR
Sorry buddy, switching the lines is not the fix. I tried it again today, still no dice. I currently do have it set up such that the TX goes to the RX and vice versa. The deal is that either way if the lines are held separately I get no results. But, when I take the two soldered connections and touch them together, like in the 4th picture, then I get results. It’s weird. It might be a voltage thing, I’ll look into that tomorrow. Thanks for your suggestion
To help you properly, you’d need to give us the model/type of your RS232/TTL converter and the sensor along with the exact wiring you tried (working and not working) with the pin names on the individual boards - the pics are not enough as we can’t see the pin names or the relation between pin names and wire colours.
Okay, here it is. My board can be found here, the uxcell DB9 RS232 Serial Female Port to TTL Converter Module Adapter DC 3.3-5V: https://www.amazon.com/Serial-Female-Converter-Module-Adapter/dp/B00R1LYEPS/ref=sr_1_8?ie=UTF8&qid=1500563647&sr=8-8&keywords=uxcell+RS232+to+ttl
The sensor is the AliCAT Whisper, manual here
And here is the wiring diagram of what I tried. This set up, when attached to a usb-rs232 converter, will give the correct output on putty. However, I see no response from my photon. If I switch the wires labeled “RS232 Input” and “RS232 Output” I still see nothing on my Photon and I also get no results when I attach a usb-rs232 converter
The only times it has worked is when I accidentally touched the lines of the “RS232 Input” and “RS232 Output” like this:
Let me know if that is more clear. Thank you for your interest
@dpstring, the Gas Flow Controller manual says:
To use the RS-232 or RS-485 input signal, connect the RS-232 / RS‑485 Output Signal (Pin 5), the RS-232 / RS‑485 Input Signal (Pin 3), and Ground (Pin 8)
The RS232 input and output pin numbers are swapped between the 9-pin D connector vs the 8-pin MiniDin connector. Can you confirm the following:
- RS232 Serial Output is pin 5 (Transmit) of the MiniDin connector
- RS232 Serial Inputs is pin 3 (Receive|) of the MiniDini connector
- Gnd is pin 8 of the MiniDin connector
I don't know what this means because your pictures seem to suggest you are bypassing the RS232-to-TTL level shifter on the board! Can you elaborate on your hookup?
Hey peekay123,
Yes, that is the correct location of the pins, here is the pinout:
And you are correct that I am bypassing the shifter on the board when I am using it to send data to putty. Because the wire is open ended, I wanted to just use the female RS232 end of the board as a means to create a direct connection from the sensor to my computer, just to ensure that the senor is streaming data correctly and to see what format it is coming out as. Essentially for that test I was just creating a female rs232 end to my wire.
So thinking about it now, if this set up (for bypassing the shifter) works then data is streaming into pin 2 on the female end as outgoing data and being received on pin 2 on the male end (as it is supposed to, right?). But then if I need data to be streaming into my female pin 3 for the shifter to work, I would have to cross the wires as @ScruffR suggested. My bad ScruffR, took me a while to get my head wrapped around this one.
But this still doesn’t give me the correct (or any) results. I will try checking voltages today and getting some cleaner solders going. Let me know if you all have any more suggestions!
Thanks
Also, a male RS232 for reference
A few more odd quirks. I re-soldered such that the green line “RS232 Serial Output” from the sensor goes to pin 3. But I still don’t get any response until I touch the “RS232 Input” and “RS232 Output” together. Then I get a response like this (I changed my code so it publishes at 8 characters)
Any ideas on why it always starts out with a “null” then gives garbage characters before actually giving a good reading?
Fresh update: I checked the voltages and it is at about 0.130V which should be good, right? Also, I soldered a connection from the “RS232 Input” to the “RS232 Output” like so:
and my results come out clean:
Now this is just a learning experience, why would this happen and why would connecting those lines solve the problem?
The logical explanation is you are connecting the two wires works because by soldering them together you are connecting the wire transmitting the data from the meter to the pin it actually wants to go to on the MAX3232.
Also what voltage is 0.130V and why do you think that is good?
Yellow is data SENT from your device, that means the RS232 RECEIVES it, Pin3 on the DB9, the 232 then transmits that to the photon which then receives it.
RS232 adaptors and drivers in PCs can do other sneaky things that some devices have wanted historically, that can include things like echoing every byte back to the transmitting device.
1 Like
It would seem the issue lies with the RS232 adapter doing some strange stuff.
I found the data sheet for the chip that should be on it for you.
I would suggest tracing the connectors and see if its wired correctly.
It might even be easier to get your own MAX232 or similar and build your own if its still doing strange things
1 Like
Hello @Viscacha!
So I think I understand what you are saying and that was my first though as well. If the wires were crossed it wouldn’t work but then if you solder the wires together, because the photon isn’t transmitting data, you are essentially “uncrossing” the wires so the data gets to the correct pin. However, I have tried both set-ups, with my yellow line connected to pin 3 and with yellow to pin 2 and neither work. But, interestingly, both ways work if you put a connecting line between the transmit and receive lines to my sensor. Funky, right?
Also, can you elaborate on the echoing and how it relates to this scenario? The 0.13V is the voltage coming out of the TX pin on the RS232 board, and that is within the photons “readable” range, correct?
@AdmiralTH Hello! I think I agree with you that it may just be my board doing some odd stuff. I traced the lines and all seems okay, but to be fair I’m not completely sure what I’m looking for or if I traced the lines correctly. And yeah, these were kind of the cheapo version off amazon so you never know. It’s just odd to me that it works so nicely, like no garbage characters or odd delays at all with this set up.
I’m guessing here, but could it be that the crossing between the Photon and the TTL/RS232 converter is not the same thing as crossing between the RS232 connector and the sensor?
If the converter isn’t bi-directional for RX & TX you can’t cross the lines between the Photon and the driver since both lines would then be “blocked” be the uni-directional properties of the converter.
You could try a null-modem to have two DTEs (sensor & Photon plus converter) communicate.
That was an interesting thought and I tried it out, but it did not work. It didn’t even send me garbage characters, just nothing. Could you @ScruffR elaborate on what a null modem is and how it would be set up? I am very new to coding and hardware set ups, sorry if that’s a simple question.
Using this diagram as an example, http://www.geeetech.com/wiki/index.php/MAX232_Breakout would imply the op has all his wires crossed if his schematic is correct.
@dpstring echoing is a feature you can enable on the driver page of some serial adaptors, when enabled every byte you transmit is also received by the sending device. I have no idea why the feature exists but I have encountered it, primarily on RS485 adaptors. Don’t forget the TX line is a data line, you can’t get measure anything useful on it with a multimeter you’d need to watch the data with a scope. You would expect data signals between the photon and the RS3232 to be 3.3V, thats kinda why its there…
The question is not only whether the lines are crossed or not but also where
As I said, crossing between the Photon and the TTL (to RS232) converter would probably not work while crossing between the RS232 side of the converter and the sensor should.
Also crossing twice would not work.
While it might be true that the MAX232 board you linked to does the crossing, I’d not deduce from this board that the board used above has the same pinout as it might be used for a different purpose. e.g if this was meant as connection between a DTE device and a DCE device it would not be allowed to do the crossing.
@dpstring, a null modem is nothing other than a RX/TX cross-out connector