User Tools

Site Tools

한국어

comfilehmi:hmi_connection_uno:index

Interfacing with an Arduino UNO

This project illustrates how to use the ComfileHMI to monitor and control an Arduino Uno.

Simply add #include <SimpleModbusRtu_uno.h> to include the Modbus RTU slave features to the Arduino Uno project.

simplemodbusrtu_uno.zip

Open the USART and start the Modbus RTU slave with the following code.

usart0init(57600); // 9600, 19200, 38400, 57600 , Serial channel0.  Baud rate 115200 is not supported.
startSimpleModbus(1,au16data, au8data); // slave address, register, coil

Declare Modbus memory with the following code.

uint16_t au16data[16];
uint8_t au8data[10];

au16data is the 16-bit register memory, and au8data is the single bit coil memory. Modbus queries will read from and write to this memory.

#include <SimpleModbusRtu_uno.h>
uint16_t au16data[16];
uint8_t au8data[10];
char n;
int incomingByte = 0; 
 
void setup()
{
  pinMode(2, INPUT);
  pinMode(3, INPUT);
 
  pinMode(8, OUTPUT); 
  pinMode(9, OUTPUT); 
 
  usart0init(57600); // 9600, 19200, 38400, 57600 , Serial channel0
  startSimpleModbus(1,au16data, au8data); // slave address, register, coil
 
}
 
void loop()
{
  digitalWrite(8, bitRead(au8data[0],0) );
  digitalWrite(9, bitRead(au8data[0],1) );
 
  bitWrite( au8data[1],0, digitalRead(2) );
  bitWrite( au8data[1],1, digitalRead(3) );
  au16data[0] = analogRead(A0);
  au16data[1] = analogRead(A1);
}

Download Arduino Source Code
Download ComfileHMI Project

The example above can be used in FADUINO-18TA as it is. ARDUINO UNO and FADUINO-18ta use the same MCU.

Back to ComfileHMI

comfilehmi/hmi_connection_uno/index.txt · Last modified: 2023/06/30 05:59 by COMFILE Technology