In this section, you will be loading a new program onto your robotic arm and using the Serial Monitor to control the movement of the arm. This will help you understand how the arm moves and help you understand the XYZ coordinates that the arm uses to position itself.
Let’s start by familiarizing ourselves with the Arduino Serial Monitor.
Think of the Serial Monitor as a tether to your microcontroller. The Serial Monitor does two things:
IMPORTANT: For the Serial Monitor to work, your computer must be connected to the ESP32 via the USB cable. This allows data to flow in both directions.
To complete this activity, you will need to upload a new set of code to the ESP32. To do this, you will need to plug the ESP32 into your computer and open the Arduino IDE.
Follow the steps below to upload the new code to your ESP32:
Program5—Serial_Monitor.ino uses the Serial Monitor to control the built-in LED light on the top of the ESP32 that controls your robot. This LED is a convenient way to test whether you’ve connected successfully because you don’t have to wire anything—it’s always ready to go.
This program lets you send five different commands to the microcontroller; each command does something different with the LED.
Think of these LED commands as “stand-ins” for commands that tell your robot arm what direction to move, how fast to move, whether to close or open the gripper, or when to stop moving.
VIDEO (Use the command line.mp4)
IMPORTANT: Your microcontroller must remain connected to your computer with the USB cable, and the IDE must acknowledge the microcontroller before you can proceed.
In the Arduino IDE, there are two ways to open the Serial Monitor.
Figure 5.2.2 Open the Serial Monitor using the menu.
<INSERT FIGURE 5.2.2>
Figure 5.2.3 The Serial Monitor appears in a new window in the lower half of the IDE.
<INSERT FIGURE 5.2.3>
With the sketch loaded successfully to your microcontroller, let’s use the Serial Monitor to test the five commands.
Take a look: Pay attention to the state of the blue LED before you type anything into the Serial Monitor. Is it ON or OFF? Write down your observation. [Hint: The LED is OFF by default when the program first starts to run.]
Important first step: All your commands must be typed into the Message bar (Figure 5.2.6) at the top of the Serial Monitor. Hit <ENTER> when you are ready to send.
Figure 5.2.6 Enter all commands into the Message bar.
<INSERT FIGURE 5.2.6>
Now, type a “Y” or a “y.” The program is not case-sensitive (that is, it treats uppercase and lowercase letters the same).
<INSERT FIGURE 5.2.7>
Type another “Y.”
<INSERT FIGURE 5.2.8>
So, the microcontroller is keeping track of the state of the LED, as well as feeding that information back to you. This tells us that the information is bi-directional—that is, it flows to the microcontroller (when you send a command) and from the microcontroller back to the serial monitor with status updates displayed in the main window of the Serial Monitor.
Now type an “N” or “n.”
<INSERT FIGURE 5.2.9>
We can flash the LED, as if we were sending a coded message.
With the LED either ON or OFF, type “1” and hit <ENTER>.
Likewise, type “2” + <ENTER>, and after that, try a “3.”
These options show that we can send an infinite number of commands to the microcontroller from the Serial Monitor.
There may be unexpected (but beneficial) behaviors coded into this simple program. For example:
Type 123 (no spaces) and then hit <ENTER>
Type “YNYN” and hit <ENTER>.
Now turn the LED off (use the letter “N”); then enter a string of letters for which no commands have been programmed, but include only ONE “Y” somewhere in the middle of the string. For example, with the LED OFF, type “UIYPQ” and hit <ENTER>.
What happens? Write down your observation. [Hint: The microcontroller will ignore (throw away) all the letters it does not recognize, but it will process the one it recognizes as a command. However, it will take one second to process each letter, recognized or not.]
Clear output from the Serial Monitor screen:
As you work with the serial monitor, lines of data can be built up. Get rid of data you no longer want to see by clicking the Clear Output button at the far-right corner at the top of the Serial Monitor window (below).
Figure 5.2.10 Clear Output to get rid of messages you no longer need.
<INSERT FIGURE 5.2.10>
Change the size of the Serial Monitor
You can drag the Serial Monitor’s upper boundary up or down with the mouse.
Figure 5.2.11 Drag the blue bar to adjust the size of the monitor.
<INSERT FIGURE 5.2.11>
Close the Serial Monitor
There are several ways to accomplish this:
Notice that both Option 2 and Option 3 leave the “Bottom Panel” open.
Figure 5.2.12 Option 3 – Use the small x to close the Serial Monitor.
<INSERT FIGURE 5.2.12>
If you want to close the Bottom Panel as well, you can use…
Figure 5.2.13 The Toggle Bottom Panel button closes the entire panel.
<INSERT FIGURE 5.2.13>
That should give you a solid footing in the Arduino IDE’s Serial Monitor. Now let’s explore how we can use the Serial Monitor to communicate with our robot in real time.