Pages: [1]   Go Down
Author Topic: RS232 to Arduino Mega  (Read 2326 times)
0 Members and 1 Guest are viewing this topic.
Padova
Offline Offline
Full Member
***
Karma: 0
Posts: 197
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi to everyone,
I'm trying to connect an instrument to my Arduino Mega but I can't. I did all the trials of this world, but no way!

This is the instrument I need to connect:
http://www.hannainst.com/manuals/manHI_93530_531_532.pdf
As you can see at page 17 you can connect it with his cable (5 pin to female DB) and this is the protocol:

Quote
The communication is unidirectional (meter to receiving unit only) and
the transmissions consist in a 32-character ASCII string, compatible
with our optional HI 92000 software.
The 32-character data string is structured as follows:
Main portion of the LCD
• byte 0 probe type: K-thermocouple (k)
• bytes 1, 2 measurement channel: T1, T2, T1-T2 (Td)
• byte 3 measurement mode: Normal (blank), Relative (R),
Average (A), Average done (a)
• byte 4 operating mode: Hold (H), Memory recall (M)
• byte 5 blank character
• bytes 6-10 measurement: reading (XXX.X or blank XXXX),
over-range (OVRG blank), no data (blank ----)
• byte 11 temperature unit: C, F
• byte 12 blank character
S e c o n d a r y   L C D ,   l e f t   p o r t i o n
• bytes 13, 14 info description: low temperature (Lo), T1 (T1)
• byte 15 blank character
• bytes 16-20 measurement: reading (XXX.X or blank XXXX),
over-range (5 blanks), no data (blank ----)
• byte 21 blank character
S e c o n d a r y   L C D ,   r i g h t   p o r t i o n
• bytes 22, 23 info description: high temperature (Hi), T2 (T2)
• byte 24 blank character
• bytes 25-29 measurement: reading (XXX.X or blank XXXX),
over-range (5 blanks), no data (blank ----)
• byte 30 <CR>
• byte 31 line feed

I used the below schematic to connect intrument -> max232 ->arduino mega
and this sketch to read the input on Arduino 1.0 IDE:
Code:
void setup() {
  // initialize both serial ports:
  Serial.begin(1200);
  Serial1.begin(1200); //the instrument's baud rate is 1200
}

void loop() {
  // read from port 1, send to port 0:
  if (Serial1.available()) {
    int inByte = Serial1.read();
    Serial.write(inByte);
  }
}

These are the connections of the 5 pin RS232:
1 - CTS
2 - DTR
3 - GND
4 - Rx
5 - Tx

And these are the connections on the female DB9 connector:
1 - NC
2 - Rx grey
3 - Tx yellow
4 - (Data termina ready) brown connetced with pin 6
5 - white GND
6 - (Data set ready) see pin 4
7 - Request to Send connected with pin 8
8 - Clear to send green
9 - NC

Connecting the instrumets with the pc by hyperterminal it works properly, every seconds it gives me a 32-character ASCII string but if I connect with Arduino nothing happens!

Can anyone help me and teach me what I'm wrong?
Thanks to those who want help me,
Alberto


* max232.png (19.99 KB, 696x792 - viewed 42 times.)
« Last Edit: May 18, 2012, 08:33:51 am by 9six4 » Logged

Online Online
Edison Member
*
Karma: 56
Posts: 2186
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
These are the connections of the 5 pin RS232:
1 - CTS
2 - DTR
3 - GND
4 - Rx
5 - Tx
Is that the pin-out of a converter that you are using? 
Please provide details.

Do you have an oscilloscope or a voltmeter?

If you connect an LED with a 1K resistor in series, between TX and GND, does the LED blink?
If you connect an LED with a 1K resistor in series, between RX and GND, does the LED blink?
[It may not be easy to see, but at 1200 baud some LED fluctuation should be noticeable.]
That will tell you which/whether a line is "alive".
Logged

"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

Padova
Offline Offline
Full Member
***
Karma: 0
Posts: 197
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is that the pin-out of a converter that you are using? 
This is the output from my instrument. The jack is a 5 pin RS232 and it goes to a DB9 with a cable like this:

http://www.comeau.ca/index.php?main_page=product_info&cPath=70_136_154_457&products_id=1448

There are no converters inside. The DB9 is connected in the above way to the 5 pin jack.

http://www.hannainst.com/manuals/manHI_93530_531_532.pdf

At pag 11 you can see the jack.

I've also measured the volts coming inside my instrument when it stands alone and when it's sending data to hyperterminal:

Intrument turned on, measuring but not connected via RS232:
Pin on DB9:-
4-6(connected together) 0V
5 0V
3 0V
2 0V

Instrument connected via RS232 but not sending data to hyperterminal:
4-6(connected together)  -9V
5 GND
3  -9V
2  -8V
The strange thing is that, when I connect the cable to the PC pins 5,3 and 2 results connected together!

Instrument connected via RS232 and sending data to hyperterminal:
4-6 -9V
5 GND
3  -8,9 -> -9,1V switch at each transmission!
2  goes to -7V to 0V and switch at each transmission!

Now I'll do the LED test,
thank  for the reply



Logged

Online Online
Edison Member
*
Karma: 56
Posts: 2186
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

When you have it operating with Hyperterminal, are you using hardware flow control (or None)?

OK.  I see that you have a MAX232.  I didn't see that circuit before, because it's an attachment and I was not logged in (and could not see that it was there.)
With the 'TTL' pins at GND, the DTR and CTS will be +.
Separate them on the TTL side, so that you can change them - and then try that (DTR HI, CTS HI ; DTR HI, CTS LO ; DTR LO, CTS HI ; DTR LO, CTS LO)

Quote
4-6(connected together)  -9V
Is that pin4 and pin6 of the 9-pin connector?

Have you "pinned-out" the Comeau/Hanna connector?
I hate not knowing what is going where.  I could assume/guess, but that always leads to trouble.
It looks like you can take apart the 'clam-shell' on the 9-pin side.  Are there any pins connected together in there?  Can you take apart the Comeau connector?

It takes a lot of time, stuff like this usually does, but.. get the ohmmeter and measure everything to everything else.  Find out what is going where.  Comeau-Hanna didn't provide a diagram in either of those links (so that you will have to buy their "$40 wonder".)
Start with the Comeau connector, pin1 to 2, to 3, to 4, to 5; then pin2 to 3, to 4, to 5, and so on.  Then do all of that with the 9-pin side.  Then ohm-out the pins on the Comeau connector to the 9pin.
« Last Edit: May 19, 2012, 08:14:17 am by Runaway Pancake » Logged

"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

Padova
Offline Offline
Full Member
***
Karma: 0
Posts: 197
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
When you have it operating with Hyperterminal, are you using hardware flow control (or None)?
Yes I do

Quote
Is that pin4 and pin6 of the 9-pin connector?
Yes

Quote
Have you "pinned-out" the Comeau/Hanna connector?
Here you are a little schematic attached. You can notice that the pin "E" doesn't comes inside the PBC of the instrument, so RTC and CTS are not connected with the PBC.

Please notice that when I connect the DB9 to the PC pin A,B and C are connected together.


* Immagine.JPG (38.97 KB, 800x585 - viewed 42 times.)
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46113
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
When you have it operating with Hyperterminal, are you using hardware flow control (or None)?
Yes I do
The correct answer to an either/or question is not yes. Which mode are you using?
Logged

Padova
Offline Offline
Full Member
***
Karma: 0
Posts: 197
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The correct answer to an either/or question is not yes. Which mode are you using?

Bit per second: 1200
Data Bits: 8
Parity: None
Stop Bits: 1
Flow control: Hardware
Logged

Online Online
Edison Member
*
Karma: 56
Posts: 2186
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

9 Pin:
4 - DTR  (C)
6 - DSR  (C)
7 - RTS  (E)
8 - CTS  (E)

As I posted (Reply #3), there must be a combination of E and D that will trigger the instrument to output data.
You would have to work out the handshaking later, but if you "trick" it first that would be progress.

It's unusual to find anything that is handshake dependent.
Can you confirm that if you configure Hyperterminal's Flow Control for "None" there is no data?
Logged

"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

Padova
Offline Offline
Full Member
***
Karma: 0
Posts: 197
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello! Here you are some test results:

Quote
Do you have an oscilloscope or a voltmeter?
voltmeter FLUKE 187

Quote
If you connect an LED with a 1K resistor in series, between TX and GND, does the LED blink?
If you connect an LED with a 1K resistor in series, between RX and GND, does the LED blink?

Yes both, but only with the RS232 connected to pc. If the RS232 is not connected there are no volts between GND and Rx or GND and Tx.

Quote
Have you "pinned-out" the Comeau/Hanna connector?
I attach some pics. I confirm you the schematic I attached in my last message.

Quote
As I posted (Reply #3), there must be a combination of E and D that will trigger the instrument to output data.
You would have to work out the handshaking later, but if you "trick" it first that would be progress.
I checked many times, E seems not to enter on my PCB, and doesn't seems to be connected with anything else.

Quote
Can you confirm that if you configure Hyperterminal's Flow Control for "None" there is no data?
I tried both solutions. I have incoming data in hyperterminal with "hardware" flow control and also with "none" flow control.


* DSC00057.JPG (1058.96 KB, 1920x1080 - viewed 19 times.)

* DSC00058.JPG (874.67 KB, 1920x1080 - viewed 17 times.)

* DSC00059.JPG (859.93 KB, 1920x1080 - viewed 21 times.)
Logged

Online Online
Edison Member
*
Karma: 56
Posts: 2186
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
As I posted (Reply #3), there must be a combination of E and D that will trigger the instrument to output data.
You would have to work out the handshaking later, but if you "trick" it first that would be progress.
I checked many times, E seems not to enter on my PCB, and doesn't seems to be connected with anything else.

Quote
Can you confirm that if you configure Hyperterminal's Flow Control for "None" there is no data?
I tried both solutions. I have incoming data in hyperterminal with "hardware" flow control and also with "none" flow control.

It seems to me that the device should be transmitting data, the handshaking has no effect.  When you have it connected to your MAX232 circuit there should be "activity" at its pin_13 (RS232 in) and its pin_12 (TTL converted).  
Is that not so?

Have you tried a simple capture / UART test (Hanna_data out -- MAX232 pin13, MAX232 pin12 to D0/RX)?

* * * *
You have
Code:
void setup() {
  // initialize both serial ports:
  Serial.begin(1200);
  Serial1.begin(1200); //the instrument's baud rate is 1200
}

void loop() {
  // read from port 1, send to port 0:
  if (Serial1.available()) {
    int inByte = Serial1.read();
    Serial.write(inByte);
  }
}
I don't know what that "Serial1" is for.
If you're just using digital pin 1 (and Serial Monitor) then
Code:
void setup()
{
  Serial.begin(1200);    // init UART, pin1 data_in, pin0 data_out
}

void loop()
{
  if (Serial.available())
  {
    inByte = Serial.read();  // declare as variable before SETUP
    Serial.write(inByte);     // repeats data_in to Serial Monitor
  }
}
is all that's needed (in a rudimentary sense.)
« Last Edit: May 21, 2012, 07:33:27 pm by Runaway Pancake » Logged

"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

Padova
Offline Offline
Full Member
***
Karma: 0
Posts: 197
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah! I win!  smiley-mr-green
I connected pin 7 of the max to pin 3 of the DB9 and tried to trigger pin 10 and pin 11 like you told me. I saw the led blinking like the instrument transmission. This is the right schematic to use.
Thank you very much for your help, I appreciated.



* max232.png (33.42 KB, 696x792 - viewed 32 times.)
« Last Edit: May 22, 2012, 01:36:39 am by 9six4 » Logged

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

Hi

I am a beginner too

I was able to connect to connect to my xbee usb module by using X-CTU..
Then I have made a change of the XB24 model and use the the function XBEE 803.15.4 RS232 Power harvester.
Now I can not connect to the modem… any idee or settings I should use . change to get access with X-CTU again ?

Txs in advance, yann
Logged

Online Online
Edison Member
*
Karma: 56
Posts: 2186
Now, More Than Ever
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah! I win!  smiley-mr-green
I connected pin 7 of the max to pin 3 of the DB9 and tried to trigger pin 10 and pin 11 like you told me. I saw the led blinking like the instrument transmission. This is the right schematic to use.
Thank you very much for your help, I appreciated.

"DB9" pin 3?
Logged

"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

Padova
Offline Offline
Full Member
***
Karma: 0
Posts: 197
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
"DB9" pin 3?
Yes I know it's strange but now it works properly.
Logged

Pages: [1]   Go Up
Jump to: