Arduino Uno and HMI WeinView TK6070IQ

Hello I have an arduino uno and an HMI WeinView and I am strugling to make them communicate without succes.
For the beggining I just want to read a value from the arduino and view it in the HMI.

In Arduino I wrote this code which is working fine with the Modbus Poll software which communicates by rs232 adapter through a max232 circuit .

/**

  • Modbus slave example 1:
  • The purpose of this example is to link a data array
  • from the Arduino to an external device.
  • Recommended Modbus Master: QModbus
  • http://qmodbus.sourceforge.net/
    */

#include <ModbusRtu.h>

// data array for modbus network sharing
uint16_t au16data[16] = {
3, 1415, 9265, 4, 2, 7182, 28182, 8, 0, 0, 0, 0, 0, 0, 1, -1 };

/**

  • Modbus object declaration
  • u8id : node id = 0 for master, = 1..247 for slave
  • u8serno : serial port (use 0 for Serial)
  • u8txenpin : 0 for RS-232 and USB-FTDI
  • or any pin number > 1 for RS-485
    */
    Modbus slave(1,0,0); // this is slave @1 and RS-232 or USB-FTDI

void setup() {
slave.begin( 19200 ); // baud-rate at 19200
}

void loop() {
slave.poll( au16data, 16 );
}

When I connect the circuit to HMI, I have "PLC no response" and Tx Rx not functioning.

  1. Is it enough to connect the max 232 to the TxD and RxD or also there is neded for RTS and CTS?
  2. What type of Modbus should be selected in HMI?

Thank you

communication.png

Modbus poll.png

In your third picture you're driving your HMI with 9600 baud using 8E1 but in your sketch your using 19200 baud with 8N1. So that's either not the same device or the Arduino version won't work.

  1. Is it enough to connect the max 232 to the TxD and RxD or also there is neded for RTS and CTS?
  2. What type of Modbus should be selected in HMI?

Post a link to the manual of that device! Without a manual we cannot tell you.

Also post a wiring diagram of how you connected it.

Hello,

thank you for your answer and sorry for the delay. I have received an ttl rs485 converter:

As connections , I have connected Rx(arduino) to R0 ( RS485 converter)
Tx(arduino) to DI (RS485 converter)
PIN2(arduino) to DE&RE (RS485 converter)

Data- (PIN1 HMI) to A (RS485 converter)
Data+ (PIN2 HMI) to B (RS485 converter)

The only manual I could find for the chinese HMi TK6070IQ is this one:

How should be this declaration for RS 485 2 wires?

/**

  • Modbus object declaration
  • u8id : node id = 0 for master, = 1..247 for slave
  • u8serno : serial port (use 0 for Serial)
  • u8txenpin : 0 for RS-232 and USB-FTDI
  • or any pin number > 1 for RS-485
    */
    Modbus slave(1,0,0); // this is slave @1 and RS-232 or USB-FTDI

thank you

Hello, i managed to make it work.
I have changed baud rate to both of them to be 9600, 8,N,1, and also changed Data+ with Data- .
And raised the timeout to 5s.

Thank you.

Hello I have now a coding issue in arduino:

I can read 3x functions, which are 16bit word, but how do I read a single coil, for example 0X_1 for changing PIN6 state?

this is my actual code from the ModbusRtu example:

/**
*  Modbus slave example 1:
*  The purpose of this example is to link a data array
*  from the Arduino to an external device.
*
*  Recommended Modbus Master: QModbus
*  http://qmodbus.sourceforge.net/
*/

#include <ModbusRtu.h>

// data array for modbus network sharing
uint16_t au16data[16] = {
 3, 1, 1, 1, 1, 1, 1, 8, 0, 0, 0, 0, 0, 0, 1, -1 };

/**
*  Modbus object declaration
*  u8id : node id = 0 for master, = 1..247 for slave
*  u8serno : serial port (use 0 for Serial)
*  u8txenpin : 0 for RS-232 and USB-FTDI 
*               or any pin number > 1 for RS-485
*/
Modbus slave(1,0,2); // this is slave @1 and RS-232 or USB-FTDI
const int ledPin =  LED_BUILTIN;// the number of the LED pin
#define  Rel1 3
#define  Rel2 4
#define  Rel3 5
#define  Rel4 6
#define  Rel5 7
#define  Rel6 8

void setup() {
 pinMode(ledPin, OUTPUT);
 pinMode(Rel1, OUTPUT);
 pinMode(Rel2, OUTPUT);
 pinMode(Rel3, OUTPUT);
 pinMode(Rel4, OUTPUT);
 pinMode(Rel5, OUTPUT);
 pinMode(Rel6, OUTPUT);
 slave.begin( 9600 ); // baud-rate at 9600
}

void loop() {
 slave.poll( au16data,16 );
 
 digitalWrite( ledPin,(au16data[0] == 1) );
 digitalWrite( Rel1, (au16data[1] == 1) );
 digitalWrite( Rel2, (au16data[2] == 1) );
 digitalWrite( Rel3, (au16data[3] == 1) );
 digitalWrite( Rel4, (au16data[4] == 1) );
 digitalWrite( Rel5, (au16data[5] == 1) );
 digitalWrite( Rel6, (au16data[6] == 1) ); 
}

Edit your post and insert code tags!

What I mean is that in the HMI I designed a " Set Word " object with 3X hold registers function which works very well with this uint16 array. For example Relay1 is 3x_1.

// data array for modbus network sharing
uint16_t au16data[16] = {
 3, 1, 1, 1, 1, 1, 1, 8, 0, 0, 0, 0, 0, 0, 1, -1 };

*/
Modbus slave(1,0,2); // this is slave @1 and RS-232 or USB-FTDI
const int ledPin =  LED_BUILTIN;// the number of the LED pin
#define  Rel1 3
#define  Rel2 4
#define  Rel3 5
#define  Rel4 6
#define  Rel5 7
#define  Rel6 8

void setup() {
 pinMode(ledPin, OUTPUT);
 pinMode(Rel1, OUTPUT);
 pinMode(Rel2, OUTPUT);
 pinMode(Rel3, OUTPUT);
 pinMode(Rel4, OUTPUT);
 pinMode(Rel5, OUTPUT);
 pinMode(Rel6, OUTPUT);
 slave.begin( 9600 ); // baud-rate at 9600
}

void loop() {
 slave.poll( au16data,16 );
 
 digitalWrite( ledPin,(au16data[0] == 1) );
 digitalWrite( Rel1, (au16data[1] == 1) );
 digitalWrite( Rel2, (au16data[2] == 1) );
 digitalWrite( Rel3, (au16data[3] == 1) );
 digitalWrite( Rel4, (au16data[4] == 1) );
 digitalWrite( Rel5, (au16data[5] == 1) );
 digitalWrite( Rel6, (au16data[6] == 1) ); 
}

[/quote]

If i want to declare a "set Bit " object which can only have the 0X (write coil) address, for example Relay 1 to have 0X_1 address, how would it look the code?

Thank you

It seems to work like in the Modbus advanced slave example.

/**
 *  Modbus slave example 1:
 *  The purpose of this example is to link a data array
 *  from the Arduino to an external device.
 *
 *  Recommended Modbus Master: QModbus
 *  http://qmodbus.sourceforge.net/
 */

#include <ModbusRtu.h>

// data array for modbus network sharing
uint16_t au16data[16] = {
  1, 1, 1, 1, 1, 1, 1, 8, 0, 0, 0, 0, 0, 0, 1, -1 };

/**
 *  Modbus object declaration
 *  u8id : node id = 0 for master, = 1..247 for slave
 *  u8serno : serial port (use 0 for Serial)
 *  u8txenpin : 0 for RS-232 and USB-FTDI 
 *               or any pin number > 1 for RS-485
 */
Modbus slave(1,0,2); // this is slave @1 and RS-232 or USB-FTDI
const int ledPin =  LED_BUILTIN;// the number of the LED pin
#define  Rel1 3
#define  Rel2 4
#define  Rel3 5
#define  Rel4 6
#define  Rel5 7
#define  Rel6 8

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(Rel1, OUTPUT);
  pinMode(Rel2, OUTPUT);
  pinMode(Rel3, OUTPUT);
  pinMode(Rel4, OUTPUT);
  pinMode(Rel5, OUTPUT);
  pinMode(Rel6, OUTPUT);
  slave.begin( 9600 ); // baud-rate at 19200
   bitWrite( au16data[0], 0, 1);
   bitWrite( au16data[0], 1, 1);
   bitWrite( au16data[0], 2, 1);
   bitWrite( au16data[0], 3, 1);
   bitWrite( au16data[0], 4, 1);
   bitWrite( au16data[0], 5, 1);
   bitWrite( au16data[0], 6, 1);
}

void loop() {
  slave.poll( au16data,16 );
  
 
   
   digitalWrite( Rel1, bitRead( au16data[0], 0 )); 
   digitalWrite( Rel2, bitRead( au16data[0], 1 )); 
   digitalWrite( Rel3, bitRead( au16data[0], 2 )); 
   digitalWrite( Rel4, bitRead( au16data[0], 3 )); 
   digitalWrite( Rel5, bitRead( au16data[0], 4 )); 
   digitalWrite( Rel6, bitRead( au16data[0], 5 )); 

  //digitalWrite( Rel5, (au16data[5] == 1) );
  //digitalWrite( ledPin, (au16data[0] == 1) );
  //digitalWrite( Rel1, (au16data[1] == 1) ); 
  //digitalWrite( Rel2, (au16data[2] == 1) );
  //digitalWrite( Rel3, (au16data[3] == 1) );
  //digitalWrite( Rel6, (au16data[6] == 1) );
  
}