Fast prototyping board 16-bit single-chip microcontrollers (37 pages)
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...
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...
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.
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.
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...
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.
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...
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...
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.
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...
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.
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.
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"...
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)
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...
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.
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.
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.
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.
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.
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.
Need help?
Do you have a question about the RL78/G23 and is the answer not in the manual?
Questions and answers