====== Interfacing with an Arduino UNO ====== This project illustrates how to use the ComfileHMI to monitor and control an Arduino Uno. {{ :comfilehmi:hmi_connection_uno:unowithhmi.png?nolink |}} Simply add ''#include '' to include the Modbus RTU slave features to the Arduino Uno project. {{ :comfilehmi:hmi_connection_uno: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 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); }
{{ :comfilehmi:hmi_connection_uno:simplemodbusrtu_uno.zip | Download Arduino Source Code}}\\ {{ :comfilehmi:hmi_connection_uno:comfilehmi-arduino.zip | Download ComfileHMI Project}} The example above can be used in FADUINO-18TA as it is. ARDUINO UNO and FADUINO-18ta use the same MCU. {{ :comfilehmi:hmi_connection_uno:faduino18ta.png?nolink |}} [[comfilehmi:index#ComfileHMI_Connectivity| Back to ComfileHMI]]