Esmacat
Published © GPL3+

Turtlesim Teleop with EtherCAT and Arduino Using ROS

Use ROS (running on Esmacat Master S/ Esmacat Master C) to teleoperate the turtlesim node using analog input from LCD Shield with EASE.

IntermediateFull instructions provided2 hours1,885

Things used in this project

Hardware components

Esmacat Master S
EtherCAT Master for the tutorial.
×1
Esmacat Master C
(Alternate) EtherCAT Master for this tutorial
×1
EtherCAT Arduino Shield by Esmacat (EASE)
EtherCAT Slave for the application
×1
Arduino UNO
Arduino UNO
×1
Ethernet Cable, Cat6a
Ethernet Cable, Cat6a
×2
Power over Ethernet (POE) Injector
×1
DC Adapter
DC Adapter to power the EASE and Arduino boards
×1
16x2 LCD Shield
Analog input to control the turtlesim Node
×1

Software apps and online services

Arduino IDE
Arduino IDE
Robot Operating System
ROS Robot Operating System
ROS kinetic or above to interface with the EASE board.

Story

Read more

Schematics

Hardware Setup Schematic

Schematic of the connection used in the tutorial

Code

arduino_with_ease_and_lcd_shield

Arduino
 /*
  Liquid Crystal & Esmacat Arduino Library - Controling Turtlesim Node
  
  This sketch does the following:
  1) Prints the User input (button pressed) onto the 
     LCD Screen
  2) Sends and receives the encoded value based on the 
     button pressed to the EASE (EtherCAT Arduino Shield by Esmacat) Registers.

  created 10 Aug 2020
  by Harmonic Bionics Inc. (https://www.harmonicbionics.com/).
  
*/

/*
    PIN CONFIGURATION of Keyestudio LCD Shield
    |-----------------------------------------|
    |  LCD PIN Number  |   Arduino PIN Number |
    |-----------------------------------------|
    |       RS         |      Digital Pin 8   |
    |     ENABLE       |      Digital Pin 9   |
    |       D4         |      Digital Pin 4   |
    |       D5         |      Digital Pin 5   |
    |       D6         |      Digital Pin 6   |
    |       D7         |      Digital Pin 7   |
    |     Buttons      |      Analog Pin A0   |
    |-----------------------------------------|
    
 */

/*
  Analog Input Values for the Push Buttons
  |------------------------------------------------|
  |    Push Button     |          A0 value         |
  |------------------------------------------------|
  |       SELECT       |   val >= 500 & val <= 750 |
  |        LEFT        |   val >= 300 & val < 500  |
  |         UP         |   val >= 50  & val < 150  |
  |        DOWN        |   val >= 150 & val < 300  |
  |        RIGHT       |   val >= 0   & val < 50   |
  |------------------------------------------------|
*/

# include <LiquidCrystal.h>      // Include LCD Arduino Library
# include <Esmacatshield.h>      //Include the Esmacat Arduino Library

// Define the Pin numbers as Macros
# define RS_pin 8
# define Enable_pin 9

# define LCD_coloumns 16
# define LCD_rows 2

# define ARDUINO_UNO_SLAVE_SELECT 10      // The chip selector pin for Arduino Uno is 10 

LiquidCrystal lcd_display(RS_pin, Enable_pin, 4, 5, 6, 7);      // Create an object for the Library class
Esmacatshield ease_1(ARDUINO_UNO_SLAVE_SELECT);      // Create a slave object and specify the Chip Selector Pin
                                

int ease_registers[8];      // EASE 8 registers

int analog_value;      // Initialise analog input value variable
int button_pressed;      // Encoded value for the buttons

/*
    -------------------------------------------
    |    Button on LCD     |    Encoded Value  |
    -------------------------------------------
    |         Left         |          1        |
    |          Up          |          2        |
    |         Down         |          3        |
    |         Right        |          4        |
    |        Select        |          5        |
    --------------------------------------------
 */

void setup() {
  
  lcd_display.begin(LCD_coloumns,LCD_rows);      //Initialise the number of (coloumns, rows) in the LCD
  
  lcd_display.print("Turtle Control..");      // Print a message onto the LCD Display

  ease_1.start_spi();      // Start SPI for EASE
  
  Serial.begin(9600);      // Initialise the Serial Communication with the specified Baud Rate
}

void loop() {

  // Code to print the button pressed on the LCD to the Serial Monitor
  analog_value = analogRead(A0);
  
  ease_1.write_reg_value(0,analog_value);      //Write register data (register,value, led_on)
  
  ease_1.get_ecat_registers(ease_registers);
  button_pressed = ease_registers[1];      // Receive the encode the value for register 
  
  if (button_pressed == 1)
  {
    lcd_display.setCursor(0,1);      // set the LCD cursor position (Coloumn number,Row number)
    lcd_display.print("L"); 
  }
  
  if (button_pressed == 2)
  {
    lcd_display.setCursor(0,1);
    lcd_display.print("U"); 
  }

  if (button_pressed == 3)
  {
    lcd_display.setCursor(0,1);
    lcd_display.print("D"); 
  }
  
  if (button_pressed == 4)
  {
    lcd_display.setCursor(0,1);      
    lcd_display.print("R");
  }

  if (button_pressed == 5)
  {
    lcd_display.setCursor(0,1);
    lcd_display.print("S"); 
  }
}

EtherCAT Arduino Shield by Esmacat (EASE) Arduino Library

Library file to be included in the Arduino IDE.

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