Esmacat
Published © GPL3+

Easy Way to Build IOT System w/ Mbed Through EtherCAT

This project demonstrates how to build an IOT system quickly and easily with Mbed, an Arduino like platform, & EtherCAT shield (EASE).

IntermediateFull instructions provided2 hours2,176

Things used in this project

Hardware components

EtherCAT Arduino Shield by Esmacat (EASE)
×2
Power Source
Any power source to power the motor.
×1
Stepper Motor
Any stepper motor can be used. This specific motor has been used in this tutorial.
×1
DC Adapter
To supply power to the Power over Ethernet Injector.
×1
Mbed board
Any Mbed board with form factor of Arduino UNO. We used NUCLEO-F103RB by STMicroelectronics
×2
Ethernet POE injector
×1
Ethernet Cable, Cat6a
Ethernet Cable, Cat6a
×3
X-NUCLEO-IHM01A1
Mbed compatible Stepper motor shield (This one is by STMicroelectronics)
×1
XNUCLEO-6180XA1
Proximity and ambient light sensor expansion board based on VL6180X for STM32 Nucleo
×1
Computer
Any windows PC with Keyboard, mouse, and monitor
×1

Software apps and online services

Arm Mbed IDE
Microsoft Visual Studio 2017
IDE for building C++ Applications in Windows. Any IDE capable of building C++ applications works as well. This is required for the EtherCAT Master application.

Story

Read more

Code

my_app.cpp

C/C++
/** @file
 * @brief This file contains the declaration of the class associated with the user-defined
 * application for the Esmacat slave project */

#ifndef MY_APP_H
#define MY_APP_H

/*****************************************************************************************
 * INCLUDES
 ****************************************************************************************/
#include <iostream>
#include "application.h"
//Include the header file for the Esmacat slave you plan to use for e.g. Analog Input slave
//#include "esmacat_analog_input.h"
#include "ethercat_arduino_shield_by_esmacat.h" 
#include <windows.h>
using namespace std;
/*****************************************************************************************
 * CLASSES
 ****************************************************************************************/
/**
 * @brief Description of your custom application class
 *
 * Your custom application class my_app inherits the class 'esmacat_application'
 * Write functions to override the parent functions of 'esmacat_application'
 * Declare an object of your slave class (e.g. ecat_ai)
 * Declare any other variables you might want to add
 * Define the constructor for initialization
 */
class my_app : public esmacat_application
{
private:
    void assign_slave_sequence(); /** identify sequence of slaves and their types*/
    void configure_slaves(); /** setup the slave*/
    void init(); /** code to be executed in the first iteration of the loop */
    void loop(); /** control loop*/

    esmacat_ethercat_arduino_shield_by_esmacat  ease_2, ease_1;
   
    int proximity_sensor_value;
    signed int motor_command;   
    bool first, once_Flag, flag, end_loop, twenty_count_once;
    int count, RPM1, RPM2, MotorHardStopped;
    double start_time, end_time ;
    SYSTEMTIME st;
   
    //esmacat_analog_input_slave ecat_ai; /**< create your Esmacat slave object */
public:
    /** A constructor- sets initial values for class members */
    my_app()
    {
        proximity_sensor_value = 0;
        motor_command = 0;  
        first = TRUE;
        flag = FALSE;
        once_Flag = FALSE;
        end_loop = FALSE;
        twenty_count_once = FALSE;
        count = 0;
        RPM1 = 0;
        RPM2 = 0;
        MotorHardStopped = 0;
    }
};

#endif // MY_APP_H

my_app.h

C/C++
/** @file
 * @brief This file contains the declaration of the class associated with the user-defined
 * application for the Esmacat slave project */

#ifndef MY_APP_H
#define MY_APP_H

/*****************************************************************************************
 * INCLUDES
 ****************************************************************************************/
#include <iostream>
#include "application.h"
//Include the header file for the Esmacat slave you plan to use for e.g. Analog Input slave
//#include "esmacat_analog_input.h"
#include "ethercat_arduino_shield_by_esmacat.h" 
#include <windows.h>
using namespace std;
/*****************************************************************************************
 * CLASSES
 ****************************************************************************************/
/**
 * @brief Description of your custom application class
 *
 * Your custom application class my_app inherits the class 'esmacat_application'
 * Write functions to override the parent functions of 'esmacat_application'
 * Declare an object of your slave class (e.g. ecat_ai)
 * Declare any other variables you might want to add
 * Define the constructor for initialization
 */
class my_app : public esmacat_application
{
private:
    void assign_slave_sequence(); /** identify sequence of slaves and their types*/
    void configure_slaves(); /** setup the slave*/
    void init(); /** code to be executed in the first iteration of the loop */
    void loop(); /** control loop*/

    esmacat_ethercat_arduino_shield_by_esmacat  ease_2, ease_1;
   
    int proximity_sensor_value;
    signed int motor_command;   
    bool first, once_Flag, flag, end_loop, twenty_count_once;
    int count, RPM1, RPM2, MotorHardStopped;
    double start_time, end_time ;
    SYSTEMTIME st;
   
    //esmacat_analog_input_slave ecat_ai; /**< create your Esmacat slave object */
public:
    /** A constructor- sets initial values for class members */
    my_app()
    {
        proximity_sensor_value = 0;
        motor_command = 0;  
        first = TRUE;
        flag = FALSE;
        once_Flag = FALSE;
        end_loop = FALSE;
        twenty_count_once = FALSE;
        count = 0;
        RPM1 = 0;
        RPM2 = 0;
        MotorHardStopped = 0;
    }
};

#endif // MY_APP_H

Credits

Esmacat

Esmacat

11 projects • 15 followers
Esmacat is an easy yet powerful EtherCAT solution for robotics. Our EtherCAT tech allow users to run EtherCAT applications in minutes!

Comments