====== Arduino IDE · Connecting an HMI with LS Electric Cnet ====== [[:en-us_guide:hmi_connection|HMI Connection overview]] · [[:en-us_guide:hmi_connection:arduino|Arduino IDE setup]] In LS Electric Cnet, the HMI sends Cnet serial requests and the product answers as the Slave. In LS Electric, M2I, and EasyView HMI editors, enter M and D memory names such as ''D000'' and ''M000''. In a Cnet request, ''%DW0'' corresponds to the product's ''D0'', and ''%MX00000'' corresponds to ''M0''. The example on this page uses **MPINO-8A4R-S · RS-232 ''Serial1'' · station 1 · 9600 bps · 8N1**. Check [[:en-us_guide:hmi_connection:wiring|channels and wiring]] and [[:en-us_guide:hmi_connection:arduino|SDK installation and board selection]]. You do not need to complete the Modbus example first. ===== 1. Addresses for the HMI screen ===== ^ Screen element ^ SDK internal memory ^ HMI entry example ^ Operation ^ | Communication check number | ''D0'' | ''D000'' | 16-bit word read, repeats 0~99 | | Number input | ''D1'' | ''D001'' | 16-bit word write, 0~9999 | | Returned value | ''D2'' | ''D002'' | 16-bit word read, same as D1 | | Test switch and lamp | ''M0'' | ''M000'' | Bit toggle write and read | The HMI entry examples apply to LS Electric, M2I, and EasyView HMIs. For other HMIs, check the address format of the selected Cnet driver. **The Modbus address conversion table does not apply to Cnet.** Number format, switch, and lamp settings are covered in [[:en-us_guide:hmi_connection:screen|Building the HMI Screen]]. ===== 2. Enter the complete code in a new sketch ===== This simple example exchanges internal memory values through the Cnet variables above. It does not use any real input or relay output pins. #include unsigned long lastTick = 0; void setup() { ICnetMem(16, 16, 0); // Includes M0 and D0~D2; R area not used ICnetAdr(0, 0, 0); // External addresses also start at 0 ICnetInit(Serial1, 1, 9600); lastTick = millis(); } void loop() { if (M == nullptr || D == nullptr) return; ICnet(); unsigned long now = millis(); if (now - lastTick >= 1000UL) { lastTick = now; D[0] = (D[0] >= 99) ? 0 : D[0] + 1; } if (D[1] > 9999) D[1] = 9999; D[2] = D[1]; } ''ICnetMem()'' allocates the memory at startup, and ''ICnet()'' handles HMI requests on every loop. ===== 3. Verify, upload, and build the HMI screen ===== After uploading the sketch, place the HMI elements using the screen example below and the address table above. ''D0'', ''D1'', ''D2'', and ''M0'' in the figure are product memory names. In the HMI editor, enter ''D000'', ''D001'', ''D002'', and ''M000'' from the table. {{ :en-us_guide:hmi_connection:practice-screen.svg?420 |D0 communication check number, D1 input, D2 returned value, M0 test switch and lamp }} - Save the sketch and run **Verify** in Arduino IDE. - Check **Tools → Board** and the upload COM port, then select **Upload**. See [[:en-us_guide:getting_started|Getting Started with Arduino IDE]]. - In [[:en-us_guide:hmi_connection:screen|Building the HMI Screen]], assign ''D000''~''D002'' and ''M000'' from the table above, then transfer the HMI project. - Turn on the product and the HMI, then test read → write → bit in [[:en-us_guide:hmi_connection:check|Checking Operation and Troubleshooting]]. {{ :en-us_guide:hmi_connection:write-read-flow.svg?420 |The HMI writes D1 and M0, then reads back the product's D2 and M0 to check the result }} Confirm that your HMI driver sends Cnet ''%DW'' and ''%MX'' requests. Expected results and where to look for each symptom are listed in [[:en-us_guide:hmi_connection:check|Checking Operation and Troubleshooting]].