Non-QEC Example – Digital Input

Non-QEC Example – Digital Input

[QEC Tutorial]

For the full tutorial, see Example: Digital Input/Output on non-QEC with EtherCAT Library.

Digital Input

Using the EtherCAT digital input module, the external digital signal is received and printed out via Serial Port.

Hardware

  • QEC-M-01
  • QEC-R11D0F: EtherCAT 16 Channel Digital Output Slave Module
  • Others: Switch

Circuit

Please refer to QEC Example – Digital Input’s circuit part for circuit construction.

Code

Please refer to QEC Example – Digital Input’s code part first.

Note that the EtherCAT slave device is a non-QEC device, so the EthercatDevice_QECR11DF0D must be changed to EthercatDevice_Generic when setting the slave object names.

EthercatMaster master;
EthercatDevice_Generic slave1;

In the main loop, the 1-byte data will be read from the PDO memory address using pdoRead8.
Since we are reading pin8 data in this example, we need to offset a 1-byte bit as follows.

slave1.pdoRead8(1)

Among them, pdoRead8(offset) has one parameter, which is described as follows.

  • offset: The ProcessData memory address.

The value read in pdoRead8 is 8-bit data. If you need to view this data, you need to set the format of the data in Serial.println(val, format).

Serial.println(slave1.pdoRead8(1), HEX);

Example

#include "Ethercat.h"

EthercatMaster master;
EthercatDevice_Generic slave1;
bool din=0,dinOld=0;
void setup() {
    Serial.begin(115200); while (!Serial);
    master.begin();
    slave.attach(0, master);
    master.start();
}
void loop() {
    din = slave.pdoRead8(1);
    if (din != dinOld) {
        Serial.println(din);
        dinOld = din;
    }
}

Learn More

You can find more information about the basic QEC applications in the EtherCAT application.

You can also explore Language or Libraries for a more detailed collection of 86Duino IDE programming.

Leave a Comment

Scroll to Top