Hi everyone,
This is my first post on a Arduino Forum,I have a problem.
I want to use nano and max485 read FY-700 Digital Temperature Controller
PV & SV
connections are:
DI to nano Tx
RO to nano Rx
DE to digital pins to nano D3
RE to digital pins to nano D2
A goes to pin (DX +) of the FY700
B goes to pin (DX-) of FY700
FY700 DIGITAL PID CONTROLLER
https://www.fa-taie.com.tw/admin/download_en/file/2015-02-04/54d1b66ec08a5.pdf
rs485-8.ino (1.5 KB)
輸入或貼上代碼
// ModbusMaster
#include <ModbusMaster.h>
#include<SoftwareSerial.h>
// RS485
#define MAX485_DE 3
#define MAX485_RE_NEG 2
// instantiate ModbusMaster object
ModbusMaster node;
SoftwareSerial Serial2(4, 5);//(Rx,Tx)
// RS485
void preTransmission()
{
digitalWrite(MAX485_RE_NEG, 1);
digitalWrite(MAX485_DE, 1);
}
// RS485
void postTransmission()
{
digitalWrite(MAX485_RE_NEG, 0);
digitalWrite(MAX485_DE, 0);
}
unsigned char cmd[8] = {0x01 ,0x03 ,0x00 ,0x01 ,0x00 ,0x01, 0xD5 ,0xCA} ; //
uint16_t au16data[16] = {};
void setup()
{
Serial.begin(9600) ; //Arduino baud-rate
Serial2.begin(9600) ; //Modbus RTU baud-rate
Serial.println("RS485 Test Start …..") ;
}
void loop()
{
for(int i = 0 ; i <8; i++)
{
Serial2.write(cmd[i]) ;
}
Serial.println("——Detection start——") ;
if (Serial2.available() >0)
{
for(int j = 0 ; j <21; j++)
while (Serial2.available() >0)
{
au16data[j] = Serial2.read();
Serial.println(au16data[j],HEX) ;
}
}
delay(1000);
}