Renesas RL78/G23 Application Note
Renesas RL78/G23 Application Note

Renesas RL78/G23 Application Note

Motor shield rev3 sample sketch (arduino sketch)
Hide thumbs Also See for RL78/G23:

Advertisement

Quick Links

Application Note
RL78/G23
Motor Shield Rev3 Sample sketch (Arduino™ sketch)
Introduction
This application note describes how to use the RL78/G23-64p Fast Prototyping Board (FPB) library for
Arduino to control a motor on the serial monitor of the Arduino™ IDE.
Target Device
Evaluation Board
: RL78/G23-64p Fast Prototyping Board
Shield
: Arduino Motor Shield Rev3
Trademarks
Arduino is a trademark of Arduino SA.
R01AN6933EJ0100 Rev.1.00
Page 1 of 25
Jul.20.23

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the RL78/G23 and is the answer not in the manual?

Questions and answers

Summary of Contents for Renesas RL78/G23

  • Page 1 RL78/G23 Motor Shield Rev3 Sample sketch (Arduino™ sketch) Introduction This application note describes how to use the RL78/G23-64p Fast Prototyping Board (FPB) library for Arduino to control a motor on the serial monitor of the Arduino™ IDE. Target Device Evaluation Board...
  • Page 2: Table Of Contents

    Application example ..........................21 Notes ............................. 22 COM port is not displayed on the Windows Device Manager ............... 22 Program is not written correctly to RL78/G23-64p Fast Prototyping Board .......... 23 Sample Code ......................... 24 Reference Documents ......................24 Revision History ..........................25 R01AN6933EJ0100 Rev.1.00...
  • Page 3: System Overview

    Arduino Motor Shield Rev3 with the DC motor and battery or AC adapter. Arduino™ IDE is used for creating a program and writing a program to RL78/G23. Also, confirm that the motor can be controlled by sending commands from the serial monitor.
  • Page 4: Arduino Motor Shield

    RL78/G23 Motor Shield Rev3 Sample sketch (Arduino™ sketch) 1.1 Arduino Motor Shield It is a shield equipped with a motor control circuit (dual full bridge driver L298P) necessary for controlling a DC motor. This shield allows you to set the motor speed, brake, and direction of rotation.
  • Page 5: Operation Confirmation Environment

    The operation of the sample code provided by this application note has been tested under the following conditions. Table 2-1 Operation confirmation environments (Hardware) Item Description Evaluation board RL78/G23-64p Fast Prototyping Board – RTK7RLG230CLG000BJ Shield Arduino Motor Shield Rev3 DC motor RE-280RA Operating voltage...
  • Page 6: Build Development Environment

    USB is used for power supply to the RL78/G23-64p FPB in this system. For the power supply, check the circuit of the RL78/G23-64p FPB by referring to the manual, and set jumpers if required.
  • Page 7: List Of Pins Used

    Direction IO12 PWM (work duty) Brake For detailed pin descriptions of each board, refer to the following manuals. RL78/G23-64p Fast Prototyping Board User’s Manual (R20UT4814) Arduino Motor Shield Rev3 https://store-usa.arduino.cc/products/arduino-motor-shield-rev3 Controlling a DC Motor with Motor Shield Rev3 https://docs.arduino.cc/tutorials/motor-shield-rev3/msr3-controlling-dc-motor R01AN6933EJ0100 Rev.1.00 Page 7 of 25 Jul.20.23...
  • Page 8: Setup Of Arduino™ Ide

    The setup procedure of Arduino™ IDE is explained. Remark. The setup procedure is almost the same as the procedure explained on the Quick Start Guide : renesas/Arduino Wiki · GitHub. The sample sketch to flash LED is described on the above site. Refer to it if required.
  • Page 9 RL78/G23 Motor Shield Rev3 Sample sketch (Arduino™ sketch) Select “All” at the [Type] and input “RL78/G23” in the textbox. Then, “RL78/G23-64p Fast Prototyping Board” is displayed. Next, click the [INSTALL]. (2) Input “RL78/G23” (1) Select “All” (3) Select the latest version (4) Click “INSTALL”...
  • Page 10 RL78/G23 Motor Shield Rev3 Sample sketch (Arduino™ sketch) Select the [Tools] - [Board] - [RL78/G23-64p Fast Prototyping Board] - [RL78/G23-64p Fast Prototyping Board] menu. Select the [RL78/G23-64p Fast Prototyping Board] Figure 3-5 Selection of board R01AN6933EJ0100 Rev.1.00 Page 10 of 25...
  • Page 11: Software

    RL78/G23 Motor Shield Rev3 Sample sketch (Arduino™ sketch) 4. Software 4.1 Overview of sample code This sample code uses the Motor Shield and control the motor by input form serial monitor. This sample code is composed of the sample sketch for the Arduino™ IDE. The file structure is shown below.
  • Page 12: Api Functions

    Line feed for each data and output to the serial port For API function specifications of each library, refer to the website of Arduino™ and the other. API List · renesas/Arduino Wiki · GitHub digitalWrite() - Arduino Reference analogWrite() - Arduino Reference Serial - Arduino Reference R01AN6933EJ0100 Rev.1.00...
  • Page 13: Api Functions For Motor Control

    RL78/G23 Motor Shield Rev3 Sample sketch (Arduino™ sketch) 4.2.1 API functions for motor control The following shows the settings when using channel A. For details of used pins, refer to “Table 1-1 Pins used for motor control” Brake setting Outline Set HIGH or LOW to value for enabling or disabling the brake.
  • Page 14: Operating Procedure Of Sample Sketch

    RL78/G23 Motor Shield Rev3 Sample sketch (Arduino™ sketch) 4.3 Operating procedure of sample sketch The operation procedure of this sample sketch is shown below. Before the steps below, setup the Arduino™ IDE in the “3.3 Setup of Arduino™ IDE”. Select the [File] - [Open…] menu to open the sample sketch “MotorShield.ino”.
  • Page 15 RL78/G23 Motor Shield Rev3 Sample sketch (Arduino™ sketch) Click the [Verify] icon to start compiling the sketch. Click “Verify” icon to start compiling. Figure 4-4 Compile sketch After compiling is finished, click the [Upload] icon to write the program to the device.
  • Page 16: Flowchart

    RL78/G23 Motor Shield Rev3 Sample sketch (Arduino™ sketch) After writing is finished, click the [Serial Monitor] icon to open the serial monitor. The motor can be controlled by entering 1 to 5 from the serial monitor. (1) Click “Serial Monitor” icon...
  • Page 17 RL78/G23 Motor Shield Rev3 Sample sketch (Arduino™ sketch) Rotation direction change flag Disabled Speed change flag Disabled Any serial input? Input value is “1”? Input value is 1 or more and 5 or less? Input status flag Serial output (Error message) Enabled "Please enter a number"...
  • Page 18: Sub Routine

    RL78/G23 Motor Shield Rev3 Sample sketch (Arduino™ sketch) 4.4.2 Sub routine The flow of processing of functions called from the loop function is shown below. (1) inputCheck: Input value check inputCheck() Input values is changed Speed change flag is enabled?
  • Page 19 RL78/G23 Motor Shield Rev3 Sample sketch (Arduino™ sketch) (3) motorChange: Motor setting motorChange() Brake setting Rotation direction setting Speed setting return Figure 4-10 Flowchart of motorChange (4) serialWrite: Serial output serialWrite() Input status flag is enabled? Note Serial output (Status after control)
  • Page 20: Specification Of Functions

    RL78/G23 Motor Shield Rev3 Sample sketch (Arduino™ sketch) 4.4.3 Specification of functions The details of the sub routine are as follows. void inputCheck(int write,bool flgspeed) Outline Input value check of serial monitor Argument Input value Data type Flag of speed change...
  • Page 21: Application Example

    RL78/G23 Motor Shield Rev3 Sample sketch (Arduino™ sketch) 4.5 Application example By combining two motors and a sensor, it is possible to create a self-propelled simple robot that does not collide with walls. Figure 4-12 shows a block diagram that realizes straight ahead, stop, speed, and turning control with the left and right motors, wall distance detection with the Time of Flight (ToF) sensor, and motor current measurement.
  • Page 22: Notes

    5.1 COM port is not displayed on the Windows Device Manager When connecting the PC and the evaluation board (RL78/G23-64p FPB) for the first time, the PC may not recognize the port and the COM port may not be displayed in Windows Device Manager.
  • Page 23: Program Is Not Written Correctly To Rl78/G23-64P Fast Prototyping Board

    Motor Shield Rev3 Sample sketch (Arduino™ sketch) 5.2 Program is not written correctly to RL78/G23-64p Fast Prototyping Board It may not be connected correctly the PC and the RL78/G23-64p FPB even if “USB Serial Port (COMx)” is displayed. Because the RL78/G23-64p FPB is not recognized correctly.
  • Page 24: Sample Code

    7. Reference Documents RL78/G23 User’s Manual: Hardware (R01UH0896) RL78/G23-64p Fast Prototyping Board User’s Manual (R20UT4814) The latest versions can be downloaded from the Renesas Electronics website. Technical update The latest versions can be downloaded from the Renesas Electronics website. All trademarks and registered trademarks are the property of their respective owners.
  • Page 25: Revision History

    RL78/G23 Motor Shield Rev3 Sample sketch (Arduino™ sketch) Revision History Description Rev. Date Page Summary 1.00 Jul.20.23 First edition R01AN6933EJ0100 Rev.1.00 Page 25 of 25 Jul.20.23...
  • Page 26: General Precautions In The Handling Of Microprocessing Unit And Microcontroller Unit Products

    Unit Products The following usage notes are applicable to all Microprocessing unit and Microcontroller unit products from Renesas. For detailed usage notes on the products covered by this document, refer to the relevant sections of the document as well as any technical updates that have been issued for the products.
  • Page 27: Corporate Headquarters

    Renesas Electronics disclaims any and all liability for any damages or losses incurred by you or any third parties arising from the use of any Renesas Electronics product that is inconsistent with any Renesas Electronics data sheet, user’s manual or other Renesas Electronics document.

This manual is also suitable for:

Rl78/g23-64p fpb

Table of Contents