Problem communicating with Alicat mass flow controllers using RS485 from Mega

I thought that I would ask a general question before writing a magnum opus of detail.

I have three Alicat mass flow controllers that use RS 485 for control.

I can control them fine from the Serial Monitor directly using a USB-RS485 converter. And receive their replies.

They seem to be dead as dodos when I try to speak to them using either rs232-TTL → RS485 from the Arduino OR a MAX485 converter from the Arduino. Very occasionally I get a broken response but usually nothing.

Does this ring a bell with anybody?

If it doesn’t then I’ll give the whole nine yards of detail.

Thanks.

Does this ring a bell with anybody?

Most probably a forgotten direction control but without a wiring diagram and the used code this is just wild guessing.

Well, I hope so!

Commands as packets are sent from the main program (Free Pascal/Lazarus) over USB to the Mega 2560 which acts as the hardware interface. The Mega then speaks directly to the Alicats.

#define SerialTXControl 11 //RS485 control pin

#define RS485Transmit HIGH
#define RS485Receive  LOW 
#define ALICATSPEED   19200
#define READDELAYER   10   //Hesitate in Aerodyne read every this many chars



#include "defines.h"
#include "hilUtils.h"

void setup() {
  Serial.begin(115200);
  Serial2.begin (57600) ;  //Aerodyne - works fine
  Serial3.begin (ALICATSPEED) ; //Alicats set to 19200 Baud
  pinMode (SerialTXControl, OUTPUT) ; //to control RS485

}

 

void loop() 
//Code borrowed from Robin 2 on Arduino forum. Essentally identical to my last code
{

Code here not relevant.
It receives a packet such as @E121! or @A143456!
It then parses it and calls the executor, below.

The former pulls back a pile of data from the Aerodyne laser - command #12 - Read data
The latter - @A143456! - Call Alicat mass flow controller.  This command identified as 14.  Send to Alicat #3 C456[CR].
This should set Alicat 3 (C) to 3.56 SCCM and return a data string, such as C +014.7 +25.00 +02.004 +0.000 3.560 N2
or similar.

I know that the command controlAlicat is receiving and parsing this command.
I know because it has very occasionally got the correct response, when it does anything.
And the code is working perfectly on another system with RS232 Alicats.
     
}//end of function
  
//************** User functions ****************

.
.
.


 void controlAlicat ()
 {
  char workStr [10] ;
  char returnStr [100] ; //make sure that we don't overflow string with stored replies
  char theUnit ;
  char tempChar ;
  int  ido ;

  workStr[0] = glCommandBody[0] ;
  workStr[1] = '\0' ;
  switch (atoi (workStr))
  {
   case 1 :  {theUnit = 'A' ; break ;}
   case 2 :  {theUnit = 'B' ; break ;}
   case 3 :  {theUnit = 'C' ; break ;} 
  }//of case


  workStr[0] = theUnit ;
  for (ido=1; ido <= strlen (glCommandBody); ido++) workStr[ido] = glCommandBody[ido] ;
  workStr[ido] = '\r' ;
  workStr[ido+1] = '\0' ; //So "C456\r" in the example above.  Also tried \r\n

  

  digitalWrite (SerialTXControl, RS485Transmit) ;
  delay(1) ;
  Serial3.print (workStr) ; //No evidence that Alicats receive command.  Have sent string "C12345\r" and no response
  Serial3.flush() ;

  digitalWrite (SerialTXControl, RS485Receive) ;

  delay (10) ; //Tried various

  ido = 0 ;

  while (Serial3.available()>0) 
  {
    tempChar  = Serial3.read();
    returnStr[ido] = tempChar ;
    ido++ ;
    delay(1) ;
  } 
     
  returnStr[ido] = '\0' ;

  commandReply ( glCommandChar[0], glCommandNumber[0], glCommandNumber[1], returnStr, 0 ) ; 
 }

I’ve tried a load of setups but let’s stick with the MAX485:

I’m not sure that the diagram worked, so:
VCC - 5V from Arduino
Grd to ground on Arduino
A to A+ on Alicat line
B to B- on Alicat line
DI to TX3 on Mega
RO to RX3 on mega (but also tried other way around)
R2 & R3 both to pin 11 on Mega

Note that I have used a USB->RS485 from the serial monitor on the laptop and it communicates fine with the devices, so the A-B lines to the Alicats are good. The Alicat Mass Flow Controllers also receive a 24V input and share a ground on the Arduino.

I have tried it with and without a 120 Ohm resistor at the end of the A-B lines to the devices. Currently there is no resistor as it is probably not required on short lines.

I hope that I haven’t left out anything!

Hil

I have tried it with and without a 120 Ohm resistor at the end of the A-B lines to the devices. Currently there is no resistor as it is probably not required on short lines.

The board on the picture already has a termination resistor on-board.

Code here not relevant.

Usually the error in that part of the code that users are hiding from us. How sure are you that there is absolutely no error in that part of the code that may influence the rest of the code? I'm quite sure the error is in the part of the code you didn't post.

Get rid of all delay() calls.