Pages: [1]   Go Down
Author Topic: RS485 to PC/Hyperterminal  (Read 5891 times)
0 Members and 1 Guest are viewing this topic.
Heisenberg won't tell me.
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arrrrrgghh!!!! Duino.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello!

I want to control an Arduino down a long cable in a noisy RF enviroment, so I figured RS485 is best (balanced and long cables).

So I'll used an RS232 to 485 converter on the PC, then as far as I can tell, I connect my cable to a 120Ω terminating resistor and MAX485 chip, then connect the TTL side of this to my arduino serial pins. I'll then use MS hyperterminal (until I write some better software) to send it a multi-character string. The arduino then acknowledges the command, works out the command and performs it, then replies to say it's complete.

Will that work? Do the hyperterminal serial messages via RS232, then converted to RS485 signal make sense to the Arduino or does it have other characters/handshaking stuff that'll confuse my Arduino sketch, or does it "just work!"?

If I do need data interpretation are there any C/Arduino libraries etc I can use (been randomly looking at modbus libraries and anything that mentions 485 in the description, without it making much sense)? Still a bit confused about the interfacing from a data point of view! In at the deep end with this project at the mo'!   smiley-sad-blue

Thanks!


* Project.jpeg (20.03 KB, 600x300 - viewed 146 times.)
Logged

Heisenberg won't tell me.
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arrrrrgghh!!!! Duino.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

P.S. Read this, but didn't follow all the code. http://real2electronics.blogspot.com/2009/09/arduino-and-rs485-english-version.html

 Would I really need all that bit to do handshaking?
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13705
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'll then use MS hyperterminal (until I write some better software)

There are much better terminal programs than hyperT. e.g putty - http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Heisenberg won't tell me.
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arrrrrgghh!!!! Duino.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Putty will do! Will it work by just typing a command into putty? Obviously I can turn flow control, XON/XOFF, etc off if required.

I just know hyperterminal better!  smiley-confuse
Logged

0
Offline Offline
Edison Member
*
Karma: 16
Posts: 1579
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

You can use a terminal soft to test your comms. It´s not a problem.
The RS485 only defines a physical layer (voltages), because of that, you need to create a protocol (rules, messages, etc). The code which you can follow in my blog is an example based on a professional product. It´s just an example, but you can create your own. I mean, if you send an "a", you are going to receive an "a" in your Arduino. You don´t need to do anything special... But for sure, create a protocol is the best thing to do.
Another example of protocol is modbus over rs485.(http://www.modbus.org/docs/Modbus_over_serial_line_V1.pdf)

If you use CAN bus in stead of RS485, the controller is going to do all the "dirty" job (messages, rules, CRC, ...) for you. You can follow some examples here (http://secuduino.blogspot.com/). I´m afraid, at the moment it´s only in spanish.

Regards,  smiley-wink


Igor
« Last Edit: April 02, 2011, 11:49:45 am by Igor R » Logged


nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 127
Posts: 8517
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The hardware you've drawn should work. As Igor says you really should design a protocol to make the comms reliable. The complexity of said protocol depends on the nature of the application and mostly boils down to how critical the Arduino's job is.

The example usually put forward here is something like

<data>

where the <> are delimiters that allow the Arduino to sync on the data. That's about all you need if the Arduino is just doing a LED display for fun. If it's controlling a heart lung machine I'd add a checksum smiley
______
Rob
« Last Edit: April 02, 2011, 07:20:41 pm by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

0
Offline Offline
Edison Member
*
Karma: 16
Posts: 1579
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

As Graynomad says, you can start something as easy as:
  • "S"= START
  • "1" or "0" => command 1=ON, 0=OFF
  • "E" => END (in my chart is F, because end in spanish is FIN...he,he,he)
It´s an easy example that I did to switch ON and OFF a led (http://real2electronics.blogspot.com/2009/10/linksys-arduino.html)




Code:
//Mini protocolo serie
//Igor Real

int luz1= 13;
int el1;
int estado=0;
byte dato_recibido;

void setup() {
   pinMode(luz1, OUTPUT);
   pinMode(12, OUTPUT);
   digitalWrite(12,LOW);
   Serial.begin(9600);
}

void loop()
{
  //trama a recibir --> S1F o S0F
  //S inicio
  //1 ENCENDIDO Y 0 APAGADO
  //F fin
  while (Serial.available() > 0)
  {
    //Significa que has recibido algo y lees el primer byte
    dato_recibido=Serial.read();
    if (dato_recibido=='S' && estado==0){
      estado=1;
    }
    if (((dato_recibido=='1')||(dato_recibido=='0')) && estado==1){
      estado=2;
      if (dato_recibido=='1')  el1=1;
      if (dato_recibido=='0')  el1=0;
    }
    if (dato_recibido=='F' && estado==2){
      estado=0;
      digitalWrite(luz1,el1);
      if (el1==0)  Serial.println("APAGADO");
      if (el1==1)  Serial.println("ENCENDIDO");
    }
    
  }
}


You can continue adding more features to your messages, for example, the slave address, timeouts if you don´t receive the next char of the message, checksum,....

As I said before, if you use CAN bus, you are going to have a very sophisticated messages and rules that it´s "transparent" for the user (the CAN controller do everything for you).

Regards,



Igor
« Last Edit: April 03, 2011, 05:47:00 am by Igor R » Logged


Heisenberg won't tell me.
Offline Offline
Newbie
*
Karma: 0
Posts: 26
Arrrrrgghh!!!! Duino.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah, great news! I'm putting plenty of error checking into my code already. If it goes wrong then it'll probably lose 2.5kW of RF into the wrong place and set fire to things! I'll make sure it's damn good before then though, and it's more likely that the thing I'm controlling I haven't build yet will catch fire through no fault of the arduino!

Just didn't know if there was other stuff going on in the data, so it would work perfectly fine using the on-board USB and its associated chip, but once trying RS485 via the pins on the chip and a MAX485 if it would seem to be gobbledegook! If that was the case suicide might be one of my better options at this point!  smiley-lol

Thanks for the help!
Logged

Pages: [1]   Go Up
Jump to: