Appendix A. troubleshooting programs, the EV3 brick, and wireless connections

When building and programming the robots in this book, you may occasionally run into problems transferring your programs to the EV3, and this appendix aims to help you find solutions to such problems. You’ll also learn how to manage wireless connections to the EV3 brick, how to reset it, and how to update its firmware.

When you download your program to the EV3 brick, the EV3 software turns your source code (the programming blocks you see on the screen) into a file with more compact code representing the actions that the EV3 brick will perform. This process is called compilation. Compilation sometimes fails, and if it does, you’ll see an error message such as the one shown in Figure A-1.

Compilation will fail if a program tries to run a block that no longer exists. If this happens, a question mark will be displayed on the missing block (see Figure A-1). Let’s say you have a My Block called Talk and a program called SoundProgram that uses the Talk My Block. The project fails to compile if the Talk My Block is missing—for example, if you’ve deleted the Talk My Block from the Project Properties page.

Note that the error message doesn’t tell you which My Block is missing (Talk); rather, it tells you which program (SoundProgram) contains references to the missing My Block.

To solve the problem, you can create a new My Block with the same name (Talk) or copy it from another project into your current project, using the instructions in Figure 5-13. Or, if you just want to continue without the missing blocks, delete all blocks with a question mark on them.

Compilation can also fail if your program contains instructions that the software doesn’t understand. For example, compilation will fail if you enter an unknown symbol in the Equation setting of the Math block, as shown in Figure A-2.

The software doesn’t tell you which block causes the compilation to fail, but you can track down the error by selecting a few blocks and trying to run them using the Run Selected button. If a selection runs, it contains no compilation errors; if it fails to run, the selection contains an error. As you systematically rule out which sections work and which ones don’t, you should eventually find the block that contains an error. Then, you can resolve the error if you know what caused it or delete the block and replace it with a new one.

When you copy a Variable block from one project and paste it into another, the definition is not always copied along with it. This means that even though the variable’s name appears on the block that you copied, it’s not available for use in other Variable blocks (see Figure A-3). To solve this problem, define a new variable of the same type with the same name.

The same thing can happen when you import a program or My Block containing Variable blocks into your project. You can see an overview of all variables on the Variables tab of the Project Properties page (see Figure 16-3). These variables should be available for use in all programs throughout your project.

The previous section can help you solve certain technical problems, but what if you have a program that runs, just not in the way you expect it to? This outcome can have many causes, and in many cases, there may simply be a user error. I’ve programmed robots for many years, and I still often make mistakes. For example, sometimes I forget to connect a data wire, and then my robot won’t work.

On the other hand, making mistakes can help you discover new techniques and solutions that you might not have found by following the steps perfectly. Troubleshooting might not seem useful or fun while you’re at it, but it’s an essential element of robotics. And, once you make your robot work by solving the problem on your own, programming is even more rewarding.

You may find the following tips useful for troubleshooting and preventing errors in your own programs:

This section will show how you can diagnose several aspects of the EV3 brick, such as the battery level, free memory, and the USB connection between the EV3 and the computer, and it’ll illustrate how to reset or update the EV3.

You can find information about the EV3 brick and devices connected to it on the Hardware Page, as shown in Figure A-6. The Brick Information tab shows the name, the battery level, and the firmware version of the EV3 brick that’s currently connected. To change the name of the EV3, type a new name in the indicated field and press the ENTER key. The personalized name should also appear at the top of the EV3 brick’s display. This name helps to distinguish EV3 bricks if you have more than one. The Port View tab displays the sensor value of each motor or sensor connected to the EV3 (see Figure 6-5).

When you connect the EV3 brick to the computer with the USB cable, the EV3 software should detect the EV3 automatically, as indicated by the red EV3 symbol () on the Hardware Page. If the symbol stays grey (), try following these directions to resolve the issue:

  1. Make sure the EV3 brick is turned on.

  2. Make sure the EV3 brick is connected to the computer with the USB connection labeled PC (see Figure 2-5). The other end of the cable should be plugged into any of the computer’s USB ports.

  3. If you’re sure everything is connected properly, try unplugging the USB cable and then plugging it back in, or try using another USB port on the computer.

  4. Close the EV3 software and restart it, or reboot the computer.

  5. If that doesn’t help, unplug the USB cable, turn off the EV3 brick, turn it back on, wait for it to fully start, and then plug the cable back in.

You may experience problems when trying to connect an EV3 to a public computer, such as a computer in a classroom. If so, ask the system administrator to log in, launch the EV3 software, and check whether it connects to the EV3. When you’re done, you should be able to connect to the EV3 using your own account.

When you send a program to the EV3 brick, it’s saved in temporary memory. The EV3 saves files and settings to permanent storage only when you turn off the EV3 brick. (This is why shutting down the EV3 takes a while.)

If you restart the EV3 without shutting down first, or if you remove the batteries while the EV3 is on, you’ll lose all files and settings that changed since the EV3 brick was last turned on because the EV3 won’t have had a chance to store them permanently. In fact, if you remove the batteries during shutdown (when the EV3 is busy saving files), you may lose older files, too.

While this can be frustrating, it’s not usually a critical problem because you should have a copy of the source code on your computer. However, you can avoid this type of data loss by adding a microSD card to the EV3, as shown in Figure A-11. Projects will be saved to the card automatically each time you download a project to your robot; you shouldn’t need to take any additional steps. The programs should stay on the card even if you restart the EV3 or update its firmware.

If you use a microSD card, you’ll find your projects in the SD_Card folder on the File Navigation tab of the EV3 brick. Even large programs are just a few kilobytes in size, so a small microSD card should provide plenty of storage.

Instead of using the supplied USB cable, you can connect your EV3 brick to the computer using either Bluetooth or Wi-Fi. Wireless transfers make programming a lot easier because you don’t have to repeatedly connect and disconnect the USB cable each time you download a program.

Once you’ve set up the wireless connection, transfer programs to the EV3 using the Download and Run button as you would with the USB cable.

The EV3 brick has built-in Bluetooth functionality that can be used for wireless programming, to communicate with another EV3 brick, or to connect with a smartphone or tablet for remote control. (Note that you can use only one of these features at a time.)

To use Bluetooth for wireless programming, you’ll need either a computer with built-in Bluetooth functionality or a compatible Bluetooth dongle that plugs into the USB port on a computer (see Figure A-12).

Follow the next steps to set up a Bluetooth connection between the computer and the EV3 brick for the first time:

  1. Plug a compatible Bluetooth dongle into a free USB port on the computer, or verify that built-in Bluetooth is enabled. Depending on the operating system, some drivers are automatically located and installed. Usually, it’s not necessary to install the additional drivers that come with your dongle.

  2. Turn on the EV3 brick and connect it to the computer with the USB cable.

  3. Activate Bluetooth on the EV3 by going to the Settings tab and selecting Bluetooth. Then, check Visibility and Bluetooth, and uncheck iPhone/iPad/iPod with the Center button, as shown in Figure A-13.

  4. In the EV3 software on the computer, go to the Available Bricks tab on the Hardware Page and click Refresh, as shown in Figure A-7. The search process should take about 30 seconds. When ready, the list of EV3 devices is updated with the EV3s that are available for a connection.

  5. In the list of EV3 bricks, there should be a checkbox for each available connection type. Create the Bluetooth connection by checking the box under the Bluetooth symbol (). If the checkbox cannot be checked, click Refresh again. If that doesn’t help, uncheck Bluetooth in the menu on the EV3 (see Figure A-13), check it again, and retry the connection procedure.

You can tell whether an EV3 has made a working Bluetooth connection by looking at the top left of the EV3 screen, which shows when connected and when not connected to a computer. If successful, you can now unplug the USB cable and start downloading programs.

The next time you launch the software, you should need only to follow steps 4 and 5 to make the Bluetooth connection, and you shouldn’t need the USB cable to configure the wireless connection.

If you didn’t connect a USB cable in step 2 to make the first connection, the EV3 brick will ask you to confirm the connection and to choose a password to secure it when you reach step 5. Once you’ve set the password, the EV3 software will prompt you to enter the same password. In turn, the EV3 will ask you to confirm once more, and the connection should be ready. It’s easiest if you stick with the default password (1234). If you use the USB cable to set up the Bluetooth connection, the software handles all of these security measures in the background.

You can add a Wi-Fi dongle to your EV3 brick so that it can connect to a wireless network, as shown in Figure A-14. When both the computer and the EV3 brick are connected to the same network, you can program your robot wirelessly. As of this writing, the EV3 brick supports only the NETGEAR WNA1100 N150 Wi-Fi USB Adapter.

For the next steps, I’ll assume that you already have a wireless network and that it’s protected with a WPA2 password. I’ll also assume that you know the network’s name (SSID) and the password and that the computer is connected to this network. Follow these steps to establish the Wi-Fi connection:

  1. Turn on the EV3 brick, and plug the compatible Wi-Fi dongle into the USB host port on the EV3 brick (see Figure A-14). Also, connect the EV3 brick to the computer using the USB cable (not shown in figure).

  2. On the Brick Information tab of the Hardware Page, click Open Wireless (Wi-Fi) Setup (see Figure A-6). The EV3 brick should turn on Wi-Fi automatically and begin searching for wireless networks. When it’s ready, choose your network from the list that appears on the computer screen and then click Connect. If you get an error message saying “No Wi-Fi Adapter found attached to the Brick,” the EV3 brick didn’t detect a (compatible) Wi-Fi dongle.

  3. Enter the network’s password on the dialog that appears, and click Connect. If successful, the symbol on the top left of the EV3 screen should change from (Wi-Fi is on) to (Wi-Fi is connected). The EV3 brick is now connected to the router in your network but not yet to the computer.

  4. Go to the Available Bricks tab on the Hardware Page, and click Refresh, as shown in Figure A-7.

  5. There should be a checkbox for each available connection type. Create the Wi-Fi connection by checking the Wi-Fi checkbox (). If it becomes checked, the connection is successful and you can unplug the USB cable. If the checkbox cannot be checked, try disconnecting the computer from the network, reconnecting it, and clicking Refresh again.

I hope that this short appendix has helped you find a solution to your problem. Of course, only a few problems and solutions are listed here, and you may have other questions relating to one of the building or programming instructions in this book. Visit http://ev3.robotsquare.com/ for links to other helpful resources, including forums where you can ask questions about LEGO MINDSTORMS EV3 in general.