首页 利用VS调试arduino

利用VS调试arduino

举报
开通vip

利用VS调试arduino利用VS调试arduino Setup The following page guides you through the first steps needed to set up your development environment. At the end of these steps, you will be ready to write, compile, debug, and upload your Arduino sketches 1. Start your IDE , Start Micr...

利用VS调试arduino
利用VS调试arduino Setup The following page guides you through the first steps needed to set up your development environment. At the end of these steps, you will be ready to write, compile, debug, and upload your Arduino sketches 1. Start your IDE , Start Microsoft Visual Studio or Atmel Studio 2. Setting up Visual Micro If it is the first time after you have installed Arduino for Visual Micro, the Configuration Manager will pop up wherever you can configure your system. Visual Micro must know the version and installation path of the Arduino software that you have installed previously, see the Getting Started page, step 1. This also applies to similar IDEs like mpIDE or Energia. The Configuration manager looks like this:c The sketchbook location specifies where Visual Micro will search for user libraries. See "Adding Libraries to your Sketc". h It is recommended to leave this field blank, so that Visual Micro uses the same sketchbook location as your original IDE (e.g.Arduino IDE). In contrast to the original IDEs, the sketchbook location string is only relevant for finding user libraries inVisual Micro. Sketches (projects) themselves can be sored everywhere. Done! Now the initial setup of your system is done. You may now continue by creating your first project or by opening an existing project. Learn more on this page Support for Multiple Versions of the Arduino Software If you work with different boards that required different IDEs, or if you have multiple versions of the Arduino IDE installed, then repeat the steps above for each IDE. You can then switch between configurations with this toolbar control: With multiple configurations installed, Visual Micro will always support the boards that are contained in the selected configuration. Read more. Modifying Existing Configurations You can open the configuration manager at any time later by clicking on "Configuration Manager" in theVisual Micro toolbar: Your First Project Once your system is setup, you can start to create new projects or open existing Arduino projects created in the classic Arduino IDE. If you are familiar with the classic Arduino IDE, you know the concept of sketches. Arduino Sketches are software projects consisting of one or more source files, which have the file name extension .INO or .PDE in the classic Arduino IDE. Sketches are organized in folders on your disk. In Atmel Studio and Visual Studio these are called projects, which also consist of several files that together build a complete software program. Visual Micro makes it easy to create projects from scratch or to convert existing Arduino sketches into projects. Creating a New Project If you are using Microsoft Visual Studio The following text shows you how to create a new project in Visual Micro. , In Visual Studio, click File > New > Sketch Project , Enter a name for your project and click OK An empty project is now set up. Your screen should look like this: Now you can start editing your code. A setup() and loop() function are already created for you. Continue by Setting up your board model and connection. Opening an Existing Arduino Sketch If you already have projects created in the classic Arduino IDE, then you can create Visual Studio/Atmel Studio projects from them and continue to work on them in Visual Studio/Atmel Studio , Click on File > Open > Arduino Project (with .INO or .PDE file extension). - or - , Click on File > Open > File , Select an existing sketch in the Arduino project directory Note: Visual Micro as well as the original Arduino IDE require that the main .ino file and the disk folder containing this file have the same name. Themain .ino file is the one that contains the setup() and loop() functions. Your screen should look like this: Now you can start editing your code. A setup() and loop() function are already created for you. Setting up your Arduino Board Model and Connection Before you upload your Arduino sketch, you must connect your Arduino board and select the proper board model. The following section shows you how to do it. Selecting the Board Model Use the Visual Micro toolbar for that purpose. Note: If the Visual Micro toolbar is missing, then you can show it by right clicking in the toolbar area and checking "Arduino Boards" , If you have entered multiple configurations in the Configuration Manager, then first select the configuration you want to work with in the left selection box . , In the board selection box , choose the board model you use Setting up your Serial Port , Connect your Arduino board to your PC using a USB cable Now you must tell your IDE which serial port to use. Use the Visual Micro Serial Communications toolbar for that purpose. Note: If the Visual Micro Serial Communications toolbar is missing, then you can show it by right clicking in the toolbar area and checking "Arduino Serial Communications" , Select the serial port in the port selection box. Normally, you will only see one serial port, which is the port your Arduino board is connected to Note: If you connect your board to a different USB port, then the port number will change. Whenever you have problems uploading your sketch to the Arduino board, first check if the proper serial port is selected. Compiling, Uploading, and Running your Sketch Note: First make sure that you have set up your board model and connection correctly, see here for more information , Start the compilation and upload process by pressing [F5] or clicking Debug > Start Debugging in the menu. Your sketch will compile, and after successful compilation, Visual Micro will upload it to your Arduino board. As soon as the sketch is uploaded, it will start to run in your board. You will see the compilation and upload progress in the Output Window. If the Output Window is not shown, you can make it visible with the View > Output menu item or by pressing [Alt+2] (not Alt+F2!) Note: If you want to use the debugging capabilities of Visual Micro, make sure to use the Debugconfiguration, selectable by this toolbar control: If you don't want to use debugging or if you want to build the final ("Release") version of your sketch, choose "Release" in the above control. Read more about build configurations in this article. If you only want to compile but not upload your sketch, press [F7] instead or click Build > Build Solution in the menu. Note: If you have multiple projects in your solution, reading this page is recommended. In the above example, Debugging was enabled, which causes two compilations, one without Visual Micro’s debugging code, and one with the debugging code inserted into the sketch. (Advanced users can switch off the two stage compilation and save some time at the risk of getting hard to interpret error messages, should their code have errors.) You can see how much of the available program memory is occupied by your sketch. As your project develops, you may want to add more source files and use Arduino libraries. Read the following sections to learn more. Using a Programmer for Uploading Original Arduino boards and clones use the serial (USB) connection for programming (uploading) the sketch onto the CPU. Other boards may also offer the option to use a programmer for uploading. Users who build their own boards and use a socketed CPU may also want to program it using a programmer. Using a programmer for upload can be configured in the Visual Micro tools menu. Performing a Clean Build Visual Micro keeps track of changes to your files between builds and rebuilds only those parts of your sketch that require it. This saves time in the build process. However, sometimes, in advanced projects, changes to the #defines in the sketch code can cause custom core or libraries to require a complete rebuild. Editing library sources that are a dependency of other libraries can also cause the need for a complete rebuild. In these cases you can clean your solution with the Build > Clean Solution menu item so that all compiled files are deleted. The next build will then rebuild everything. Of course, none of your source files will be affected by the "Clean Solution" command. Handling Compiler Errors If the compiler encounters an error in your code, it outputs an error message to the Output window: You can double click anywhere in the line containing the error message and revise your code to eliminate the error. You can jump from one error to the next using the [F4] key, use [Shift+F4] to jump to the previous error. Sometimes the compiler generates multiple messages to give more information about the discrepancies it has found. Intellisense: Detecting errors as you type Visual Micro provides a technology called Intellisense. Intellisense tries to find errors as your are typing your code in without having to compile your sketch. This saves a lot of time and gives you immediate feedback about the error. IntelliSense underlines erroneous areas of your code with a red waved line like the spell checker in your text processing or E-Mail program. If you put the mouse pointer over the underlined portion of your code, a quick tip will show the error: Hints for removing compiler errors Sometimes the compiler issues many error messages that have the same reason. So don't be shocked if you get lots of error messages, often it's a single mistake that caused all the messages. The following hints help you to eliminate compiler error messages in an efficient way. , Process the errors from top to bottom Start with the first messages and fix the error. If the subsequent messages do not appear reasonable for you, they may be consequential errors from the first one. Just recompile your sketch to eliminate the phantom error messages. , Curly brace‎‎s If there are lots of error messages in code areas that were correct before, then you might have put too few or too many curly braces ('{', '}') into your code. If you put the cursor on one curly brace and press Ctrl+], Visual Studio will jump to the matching brace. If that matching brace is not the one you expected, then there is an excess brace somewhere or one is missing. Note: The key that is assigned to the "Matching brace" function in Visual Studio/Atmel Studio differs depending on the layout of your keyboard. For example, with German keyboards it is Ctrl+? (left of the backspace key). , Misplaced breakpoints If you have set a breakpoint recently, maybe you have set it at a location where it's not allowed so set one. Read more about where in source code breakpoints can be set. , Help in the web Find help in the web, for example on www.cprogramming.com or www.stackoverflow.com. Use the error message of the compiler output as a search term there, or enter it in your favorite search engine. Adding and Deleting Source Files As your project becomes bigger, you should split it into individual source files to keep a clear structure. Having separate source files also reduces compilation time, at least if you decide to use .CPP files instead of .INO files, see later. The resulting program will be identical, independent of having one or multiple source files. It's just a matter of organization of your sources. Adding a new source file , In the menu, click Project > Add New Sketch Item: You can choose between Arduino items, C Items and Cpp items. Note If the Add New Sketch Item menu item is grayed out, then you most likely have selected the whole solution in the Solution Explorer, instead of the project: (Solutions are a collection of individual projects in Visual Studio/Atmel Studio, but at this point, we don't need to know more about them.) If the Solution Explorer is not shown, make it visible by pressing [Ctrl+Alt+L] After clicking the menu item, a new and empty .INO, .C or a .CPP file are added to your project. You will be prompted for a filename. Enter the filename without the extension. All three file types are used to write source code. What is the difference between these file types? , Arduino items = .INO files are the Arduino standard. When compiling, Visual Micro treats all .INO files as they were one file. That's why you don't have to deal with include files (.H extension) as long as you are using .INO files only. , .C items are used to write code that is written in the C language. Unless you have special reasons, you should not use .C files, because the C language has no obvious advantages over the language Arduino uses normally and can cause compatibility issues.. , .CPP items are used to write code that is written in the C++ language. This is the same language the .INO files use. Along with the .CPP file, Visual studio also creates a matching .H file. The newly created .CPP file already contains a skeleton for a new class, ready to be used. If that generated code does not fit your needs, simply delete it. Note: File names... , must not start with a number , must not be longer than 30 characters , must not contain any blanks If any of these rules is broken, your sketch will not compile correctly. Read the Renaming Source Files and Projects section to learn how to change file names Which file type shall I use? This article tells you more about the difference between .INO files and .CPP files and helps you in choosing the right file format. Adding an existing source file In accordance to the Arduino specification, a project consists of all source files in the project folder on your hard drive, regardless whether they appear in your Visual Studio/Atmel Studio Solution Explorer or not. If you have a file in your hard drive's project folder that is missing in the Solution Explorer, then you can add it with "Project > Add Existing Item" in the menu, so that you can double click and edit it. With this method, you can not add files to your project which are stored in a different folder on disk. However, you can add them to Solution Explorer, but, according to the rule above, they will not be part of the compilation because they are not in the project folder on disk. Deleting files If you want to remove a file from your project, click on it in the solution explorer and press [Del]. If you do so, a box appears that lets you choose between removal and deletion. Removing a file only means that it won't appear in Solution Explorer anymore, it is still part of your build. After reopening the solution, such files will appear again. That's why it is not recommended to use removal. Deleting a file will remove it from the project and delete the file on your hard drive as well. If you want to be sure that the file will be excluded from compilation, but you want to keep the file, then rename it's file extension in Windows Explorer, e.g. from "myfile.cpp" to "myfile.__cpp" or move it to a different folder. Renaming Source Files and Projects There are several methods of renaming files and projects, depending what the result shall be. In any case, you will have to open the Solution Explorer window. If it is not open, press [Ctrl+Alt+L]. Note: The main .ino file, the containing folder on your hard disk and the project must have always have matching names. Do not rename the project (Red 'x' above), Rename the main .ino file instead, as shown below. This will rename the project and the disk folder as well. If you want to rename the project and the containing folder... Click on the main source file, it is the one containing the setup() and loop() functions, this file has the same name as the project. Press [F2] and give the source file a new name. This will also rename the project and the containing folder on your hard disk, so that all match again. If you want to rename a single source file... Click on the source file, press [F2] and give the source file a new name. If this was the "main" file containing the setup() and loop() functions, the project will be renamed as well, see above. If it was any other file, only the file will be renamed. If the source file has a matching header file (like "somefile.cpp" and "somefile.h"), then you should also rename the header file, so that you will still see which pair of files belong together. If you want to rename a single header (.h) file... Open the "Header Files" node in Solution Explorer and rename the file in the same way as for source files. Do not forget to change all #include <...> references to your header file in all source files where it is used. If you have a situation where the containing folder, the main .ino file and the project have mismatched names, this is how you put everything in order: , Rename the project by clicking on the project name, pressing [F2] and renaming the project , In Solution Explorer, select the main .ino file, press F2 and rename it to match the name of the project , Close the solution with File > Close Solution , Open Windows Explorer, rename the disk folder , Reopen the Solution with File > Recent Projects and Solutions Build Configurations Visual Studio and Atmel Studio allow you to define build configurations which are sets of build parameters (=build settings). By selecting one configuration as active, all parameters that are stored in this configuration become effective. By switching between build configurations, you can change many parameters at once, without being forced to change them painstakingly one at a time. Visual Studio/Atmel studio provide two configurations as a default: Debug This configuration is typically used while you develop your program. You can enter debugging settings in your project properties to control if and how Visual Micro debugging works. Release This configuration is typically used to build the program for final release (hence the name). In this configuration, all debugging settings are left disabled. Note: Initially, all parameters for Visual Micro have identical values for the Debug and Release configurations. In order to enable debugging in the Debug configuration, you must change the respective values in the Project Properties. Please remember that "Debug" and "Release" are only names given for two sets of build parameters. It is up to you how you set the parameters in these configurations. How to change the configuration The available configurations can be selected in the "Standard" toolbar: Which settings are stored in a build configuration? Visual Micro uses three kinds of settings: Project specific, configuration specific parameters These parameters are configuration specific. As described above, if you change the configuration, let's say from "Debug" to "Release", these parameters change the values according to the values stored in the chosen configuration. These parameters are also project specific, so every project can have different parameter settings. All parameters of this category can be found in the Project Properties Window. Project specific, configuration independent parameters These parameters are not affected by a configuration change. However, they are stored project specific, so every project can have different parameter settings. All parameters of this category can be found in the Project Properties Window. System wide parameters These parameters are stored centrally and apply to all projects and configurations. All parameters of this category can be found in the Tools > Options Window. How can I change a parameter in a build configuration? Regardless whether a parameter is configuration specific or not, simply change it in the Project Properties Window or in the Tools > Options Window, respectively. Those parameters that are configuration specific will be stored in the configuration that is currently active (determined by the toolbar control). Adding more configurations Two configurations, Debug and Release, are normally sufficient. If you want to add more configurations, click on the "Configuration Manager" menu item of the toolbar control. The built-in configuration manager of Visual Studio/Atmel Studio opens and lets you manage configurations. Do not confuse this manager with the Visual Micro configuration manager! Navigating Through Your Code, Exploring Your Code Both Visual Studio and Atmel Studio have powerful built in tools that help you when navigating through your code. It is absolutely worth learning to use these functions. You can... , find the places where you declared functions and variables , find the places where they were used , what functions call other functions , and much more In this aspect, Visual Studio and Atmel Studio differ substantially, because they use different software tools for that purpose. Microsoft Visual Studio Microsoft Visual Studio has similar functions already built in. An automatic ("Intellisense") class member dropdown in Microsoft Visual Studio About .INO and .CPP files The difference between the two file types Both file extensions, .INO and .CPP, relate to source files, there is no difference in the file format or any difference in the programming language, but there are differences in how Visual Micro handles the files during compilation. Note: Every project must have one main sketch file, which must be an :ION file. This is the file containing the setup() and loop() functions. This main .INO file must have the same name as the project itself, e.g. if your project is named "MyRobot", then your main .INO file must be calledMyRobot.INO. .INO files As long as you are using .INO files it does not matter how you distribute your functions among the files and how they are ordered within them. This makes programming easier, which is the idea behind .INO files. However, as your project becomes larger and more complex, you might experience certain limitations of the .INO approach, especially if you are starting to use certain elements common to the C++ language liketypdefs or global variables. This will be the time when you should consider switching to .CPP and .H files. Note: If you are using .INO files, you should follow these rules to avoid problems with compilation: 1. Put all global variables and objects into the main .INO file (the one that has the same name as your project) 2. You cannot use user defined data types like your own classes, structs or typedefs as arguments to functions. a function like this: myFun( int arg ) is OK, but a function like this: myFun( MyClass *p ) will cause a compiler error. If you ned that, switch to .CPP and .H files. You can choose that .INO files shall behave just like .CPP files by switching the "Generate Prototypes" setting in the Project Properties to "false". .CPP and .H files Even though the Arduino web site does not mention it, the programming language Arduino uses is nothing but C++, with some limitations due to the tight memory constraints of the processors used. Every user that is familiar with C or C++ should use .CPP and .H files in all but the simplest projects, because they show a behavior he is familiar with. When using .CPP files, some "magic" of the .INO files does not apply. That's why the user must care about typical C/C++ constructs like function prototypes. At the end of the day, the larger the project gets, the more sense it makes to switch to .CPP/.H files. Which file type shall I use? (This question is irrelevant as long as you have only one source file, which must always be an .INO file.) In a nutshell: , If you don't want to learn about C++ declarations and header files, stay with .INO files , If you have a more complex sketch with many separate source files that use classes and methods from each other, you will have more control and overview if you use "classic" C++ .CPP and .H files How Visual Micro handles the files during compilation .INO files Before compilation, Visual Micro concatenates all .INO files in your project in alphabetical order into one big .INO file. In this alpabetical order, all upper case letters are preceding the lower case letters. Example: The files messages.INO, analog.INO, and Digital.INO are concatenated into one singe file in this order:Digital.INO, analog.INO, messages.INO (note the upper/lower case in the file names). Exception: The main sketch file is always the first in this order, regardless of alphabetical order. Note: This way of handling .INO files might seem somewhat counterintuitive, but Visual Micro tries its best to mimic the way the original Arduino IDE does it, to ensure maximum compatibility with existing projects when migrating from the original IDE to Visual Micro. To relieve the user from writing function prototypes, Visual Micro automatically generates them for all functions in all .INO files and puts them at the head of the combined .INO file. After that combination step, the resulting, combined .INO file is compiled as one large file. .CPP files .CPP are treated as with every common C++ compiler: They are compiled one after another. The order how the files are compiled does not matter, because every .CPP file is treated separately. Visual Micro does not automatically create function prototypes for .CPP files, so you must take care of them using header (.H) files, like it is common with C++. Adding Libraries to your Sketch What are libraries? Libraries are program modules that other people wrote and that you can integrate into your project in order to use them. The classic Arduino IDE comes with lots of libraries for purposes like controlling stepper motors, reading and writing the EEPROM and so on. You can find a description of available Arduino libraries on the Ardui. no homepageTo add a library, choose Project > Add/Import Sketch Library > Core to choose one of the libraries provided by Arduino or your board's manufacturer. If you have created your own libraries, then you can add them in the same way with Project > Add/Import Sketch Library > User. Note If the Add/Import Sketch Library menu item is missing, then you most likely have selected the whole solution in the Solution Explorer, instead of the project: (Solutions are a collection of individual projects in Visual Studio/Atmel Studio, but at this point, we don't need to know more about them.) If the Solution Explorer is not shown, make it visible by pressing [Ctrl+Alt+L] Visual Micro adds the necessary include directives into your code: Note: under the "Core" menu item, Visual Micro always shows those libraries that fit to the selected board. If you switch to a different board you might notice that the list of libraries changes as well. Search path for user libraries Visual Micro searches for user libraries in the "Libraries" subfolder of your sketchbook folder, provided you have specified a sketchbook location in the Configurat. ion ManagerIf you did not specifiy a sketchbook location in the configuration manager, then Visual Micro searches in a "Libraries" subfolder. is the user libraries folder, are your sketch folders. For every library, you must create a subfolder in your "Libraries" folder: The Output Window The Output window shows the output of the compiler/build system as well as output from debugging sessions. To make the Output window visible, choose View > Output or press [Alt+2] (not Alt+F2!) The Output window has several panes that can be shown with the "Show output from" control. The "Micro Build" Pane This pane shows messages from the compile/build and upload operations, including error messages when compilation or upload failed. See also: Handling Compiler Errors Compiling, Uploading and Running your Sketch The most common mistakes when using serial connections The "Micro Debug Message" Pane This pane shows information generated from breakpoints. The "Micro Debug Trace" Pane This pane also shows information generated from breakpoints, but more detailed than the Micro Debug Trace window. The "Micro Disassembly" Pane This pane is only available if you have switched on the generation of a disassembly listing. You can do this with the "Disassembly view" setting in the Project Properties Window. The pane shows a disassembly listing of your sketch. This can be useful in special cases, for example to examine the amount of code generated by the compiler, but it requires profound knowledge of the processor's assembly language. You can click on the file paths that appear in the listing (see red arrow) to jump to the respective source file. Note: The links lead you to either the Arduino core library path or to a folder where Visual Micro stores temporary results. You should not change anything to source files at these locations. The Output Window Toolbar The toolbar of the Output window has the following controls: Show output from Selects the output pane to be shown, see above. Clear all panes Clears all panes at once. Jump to source line with error ("Micro Build" pane only). If the cursor is placed on a compiler error message, click on this icon to jump to the source code line where the error occurred. Jump to prev./next message Jumps to the start of the next or previous message. Clear current pane Clears the pane that is currently displayed, leaving all other panes unchanged. Word wrap text If enabled, wraps text at the right border of the window for lines that are longer than the window's width. The Visual Micro Explorer The Visual Micro Explorer is a powerful browser for any kind of information concerning Arduino. , To open the Micro Explorer, click on the icon on the Visual Micro toolbar The Micro Explorer window opens. Click on one of the tabs to show the respective pane: If you have multiple platforms installed -e.g. multiple versions of the Arduino IDE-, then select the right platform first in the platform selection box. These are Micro Explorer's panes and their contents: "Ide" Shows the list of available boards and libraries for a given platform. "Reference" Shows a table of contents of the language documentation available onwww.arduino.cc Click on an item to jump directly to its documentation page. "Examples" Shows a list of example source files provided by your platform. Click on an example to load it as a project (either the original or a copy) or click on a single source file to open it in your IDE. Read more about working with examples . below "Search www" Provides a search field and performs a Google search for the given text either in the Arduino Reference, the Arduino tutorials, or both on www.arduino.ccand www.visualmicro.com . Note: The top of the result list is occupied by Google paid ads which are not related to www.arduino.cc or www.visualmicro.com. "What's new" Shows a "What's new" page that gives you the newest information aboutVisual Micro. Working with examples In the "Examples" tab above, you can easily open or copy examples to your project. Simply click on an example... and the following window appears: Open Copy Creates a new project as a copy of the example in a subfolder named "MyExamples" in your Arduino sketch folder Open Original Opens the example as a project in its original location. With this option you can modify the example source files directly. Note: Use this option only if you intend to change the examples themselves. Opening a copy (see above) is safer if you want to leave the example files untouched. Browse Source Opens a subtree under the example where you can pick a single source file and open it: Note: Visual Micro opens the original file, not a copy. Save the file immediately under a different name unless you intend to modify the original file. The Serial Monitor Window You can use the Serial Monitor Window to send data via the serial connection to your Arduino board and to visualize incoming data from your board. With the Serial.print() and Serial.read() functions, you can send and receive data via the serial port. Visual Micro's Serial Monitor is the PCs counterpart on the other end of the serial line. You can find the documentation of the Serial... functions on the Arduino web site. To show the Serial Monitor in your IDE, choose Tools > Visual Micro > Serial Monitor or click the Serial Monitor button in the Arduino Communications toolbar: With the selection box you choose the COM port your board is connected to. Note A good start for experimenting with Arduino's Serial functions is the ReadASCIIString example provided by the classic Arduino IDE. Anatomy of the Serial Monitor window Sending and receiving data In the Outbound Area you can enter characters. As soon as you click on the Send Button, the string is sent to your Arduino board and can be received by the board via a Serial.Read() function. Strings sent by your Arduino board are displayed in the Inbound Area. Settings and other functions The other elements of the Serial Monitor window are important to configure and control the serial connection. Connection Checkbox If you uncheck this box, the connection to your board will be interrupted. The serial port is then free for other programs on your PC. If you check that box again, the connection will be restored. The behavior of your Arduino board depends on the DTR checkbox (see below). DTR Switch The DTR line of your board's UART is used to reset the board and restart the sketch. If this box is checked, Visual Micro controls the DTR line which results in a board reset if the board connection is established/restored (with the "Connect" box above). The DTR switch has no effect if you use SoftwareSerial as the transport method, see "Advanced Serial Communication". The DTR switch also has no effect with some sorts of boards that have a separate small processor for serial communications. "Clear" Checkbox Check this box to clear the contents of the Inbound box where the data sent by the Arduino board is shown. When this box is checked, the inbound area of the window will be cleared every time the port is reopened. "Reconnect" Switch Indicates whether Visual Micro attempts to reconnect to the board once it was disconnected. The initial state of this switch is taken from Tools > Options > Communications > Auto Re-Connect. Echo Settings This setting can be used to route all incoming data from one board to another board connected to a different COM port. Example: If you have two boards attached to your PC, one on COM3 and one on COM4, and you choose "COM4" in the Serial Monitor of COM3, then all data coming in from COM3 will be displayed in the Serial Monitor and sent to the other board via COM4. Line End Settings Specifies how the string is terminated that you send to your Arduino board after clicking the Send Button. "no line endings": no character is appended to the string being sent. "Carriage return": a Carriage return character ('CR'=0x0d or '\r') is appended . "Newline": a newline aka Line Feed character ('LF'=0x0a or '\n') is appended . "Both NL and CR": both a CR and a newline (LF) character are appended . The right setting depends on how your sketch handles the incoming characters. In the Arduino ReadASCIIString example, you will notice that the sketch waits for a '\n', which is a "newline" or "line feed". So for this sketch, the "Newline" setting will be the right one. If in doubt, use the "Both NL and CR" setting. Baud Rate Settings Specifies the transmission speed or so called "baud rate" that Visual Micro and your board use. This setting must match the setting your sketch uses in the Serial.begin() function. In the Arduino ReadASCIIString example, the sketch operates with a setting of 9600. If the baud rate of your board and that of Visual Micro don't match, you will see no incoming characters or garbage only. If you are using Visual Micro debugging, then this value must also match the baud rate setting you chose for debugging communication, see "Debugging with Different Ports, Pins and Speeds". The options butto n See here for a description of this button's menu items. The most common mistakes when using serial connections These are the most common causes for problems with serial communication: Wrong baud rate selected Make sure that the baud rate in your sketch is the same as selected in the Serial Monitor of Visual Micro. If both do not match, you won't be able to read and write characters to and from the serial connection. Serial.begin() missing You cannot perform any serial reading or writing operation unless you call Serial.begin() in your sketch. Usually, Serial.begin() is put into the setup() function of your sketch. Wrong port on the Arduino board chosen With boards that have multiple serial ports, like the Arduino Due, you must make sure that you work with the correct port in your sketch and that you have connected this port to your PC. Wrong serial port selected on PC If you connect your board to different USB connectors of your PC or if you use a different board, the COM port number may change. In these cases you must adjust the COM port setting in the Visual Micro Arduino Communications toolbar. What is a COM port? The CPUs used in most boards have one or more built in serial communication devices called UARTS. They work according to the RS-232 standard. The USB hardware on the board converts these signals into similar USB signals. On the PC side, there is a driver that can send and receive such USB-RSR-232 signals and that mimics a RS-232 hardware interface in your PC, that's why these drivers are called "Virtual Com Port Drivers". From a PC application's viewpoint, everything looks as if the UART of your board's CPU was directly connected to a serial hardware interface in your PC. Traditionally, serial ports in PCs are called COM ports and numbered COM1, COM2 etc. That's why you can use any software that is able to work with COM ports in order to read and write data to and from your board. The Serial Monitor Options Button This section describes the menu items of the options butto foundn in the serial Monitor window. To learn more about the Serial Monitor window, read here. The Serial Monitor Options menu Start See "Pause" Pause Freezes the inbound data area of the Serial Monitor so that incoming data does not show up any more. Helpful to stop received text from scrolling out of the window while the sketch keeps sending more data. To continue and unfreeze the inbound area, use the "Start" menu item. Note: If you have paused the Serial Monitor with this "Pause" function and the sketch has halted in a breakpoint in the meantime, then you can choose "Start", but since Visual Micro had no connection with the board in between, it cannot "know" that the sketch is halted in a breakpoint. If you press [F5] then, Visual Micro wants to stop the sketch and rebuild it. In this case you can manually continue the sketch execution by sending a lower case "c" (for continue) to the board using the Serial Monitors outbound window and the Send button. The next time the board halts in a breakpoint, [F5] acts as expected again. Stop Closes the Serial Monitor and interrupts communication between board and PC. The sketch continues to run until it hits a breakpoint, then it stops. To restart the sketch (to "boot" your board), reopen the Serial Monitor window. Settings This menu item contains a single submenu item "Discard inbound when sending". You can enable and disable this setting by selecting the submenu item. If "Discard inbound when sending" is selected, then inbound data is discarded by Visual Micro while sending data to the board. Enable this function if large amounts of data are constantly sent from the board to the PC to ensure that data being sent to the board reaches the board correctly. Breakpoint Manager "Jump to breakpoints": If this option is selected, Visual Micro will jump to the source code line of a breakpoint when this breakpoint is hit and code execution is stopped. "Jump to trace points": If this option is selected, Visual Micro will jump to the source code line of a breakpoint even if Visual Micro is configured so that code is not stopping there (e.g. by "Auto continue" below). This is useful to see the code executing in a "live" manner. "Auto continue": If enabled, breakpoints will not halt the execution of the sketch, but the sketch will continue execution if a breakpoint is hit. However, you will be able to follow the flow of execution by watching the Output Window. Note: In conjunction with "Jump to breakpoints" or "Jump to tracepoints" enabled, you can follow the flow of execution in your source code, as every breakpoint hit will be shown in the source window. "Disable all breakpoints": This will disable all breakpoints in your sketch, so that nothing will show up in the Output Window and in the source code window. Note: You can enable/disable breakpoints individually if you right click on the breakpoint icon in your source windo and selecw t "Enable/Disable breakpoint". Both methods of disabling require rebuilding and uploading your sketch and can be selected at any time. Other Windows "Watch expression": This will open the Expression window. Read here for a description of the Expression window. "AGauge Example" and other submenu items: These settings are used to show/hide so called Visualization Windows (read more). Message Windows Controls which window(s) will show messages from the board. All submenu items are on/off switches. "Messages" means information from breakpoints when using the "When Hit" function. "Serial": Messages will appear in the Serial Monitor window "Message": Messages will appear in the "Micro Debug Message" portion of theOutput Window. "Trace": Messages will appear in the "Micro Debug Trace" portion of the Output Window. Using Multiple Serial Monitors (Read more about Serial Monitors) If you work with multiple Serial connections, then you can open multiple Serial Monitor windows, one for each COM port. This can be useful if you work with an Arduino board that has multiple serial ports, or with multiple boards attached to your PC. However, with one Visual Studio/Atmel Studio/Visual Micro session, you can always use only one board for programming and debugging. If you want to program/debug multiple boards, simply open multiple Visual Studio/Atmel Studio sessions. , To open a second, third etc. Serial Monitor, select Tools > Visual Micro > Other Serial Ports > Monitor COMx in the menu. Debugging your Arduino Sketch Note: The Visual Micro Debugger is available during a trial period after installation. After that trial period, you can buy it for a low price. Read more What is Debugging? Please read this introduction first to learn the basic concepts around debugging. How do I Enable Debugging in Visual Micro? Debugging requires that you use the Debug configuration of your project. To select this configuration, choose "Debug" in the configuration selector in the Visual Studio/Atmel Studio toolbar: (This page tells you more about configurations, but for now, you only must remember to choose "Debug".) What is a Breakpoint? The key element in Visual Micro debugging is breakpoints. A breakpoint is a marker that you can set in a source code line where execution shall be halted. Once your program reaches the breakpoint, it stops and begins communicating with Visual Micro. Afterwards, you can instruct your Arduino board to continue execution of the sketch. What Can You Do With Breakpoints? , By setting multiple breakpoints you can follow the flow of execution inside your program. For example you can check when certain functions are called and in what sequence. , You can configure the breakpoints... 1. so that execution is not halted, but only logged, so that you can observe the flow of execution while your program is running uninterrupted (so called Tracepoint). Visual Micro shows every breakpoint your program passes in a window. Then your breakpoint is like a track marshal in sports. This is the default setting for new projects. 2. so that your sketch is halted every time a breakpoint is hit. The sketch will resume execution when you press [F5]. , When a breakpoint is hit, you can watch the values of variables and can even change them. , You can define conditional breakpoints. These breakpoints only stop program execution if a certain condition is met, for example a variable value. You can also define breakpoint counters, so that a breakpoint only stops after the program has passed it a certain number of times. Note: You can find a complete description of the breakpoint functionality on this page. First Steps: Working With Breakpoints The following example uses the Blink sketch from Arduino. , Put the cursor on an instruction in your program code , Press [F9]. , This sets a breakpoint at this code location. Your screen will now look like this: The red circle on the left indicates your breakpoint You can also set a breakpoint by clicking into the gray shaded are left of the code, where the red circle appears. , Compile, upload and run your program by pressing [F5] , Your program starts to run. Every time it hits the breakpoint you will see a notification in the Micro Debug Trace window: Note After making changes to your breakpoints (adding, deleting, modifying), you have to recompile and upload your sketch in order for the changes to go into effect. However, enabling and disabling breakpoints can be done at any time without having to recompile and upload. Read more about differences between the Visual Micro debugger and normal debuggers. Breakpoints and Your Code Where Breakpoint Can Be Set In a nutshell, you can set a breakpoint wherever you could insert a normal statement. In fact, Visual Microbreakpoints are small pieces of extra code that Visual Micro inserts in your sketch. Breakpoints in Comments and Empty Lines You can also set breakpoints in comment lines or empty lines. The breakpoint would behave as with every regular code line. Breakpoints in Multiple Line Statements If you want to set a breakpoint at a statement that spans multiple lines, then set the breakpoint at the last line of that statement (where the ";" or the "}" are located): Violation of this rule will result in compiler errors. Debugging and the Serial Port The Visual Micro debugger uses the serial port for communication with the board. If you use the serial port yourself in your sketch, then make sure that the baud rate set by your code (with Serial.Begin) matches the baud rate that Visual Micro uses for debugging. You can set Visual Micro's baud rate with these project settings. If you use Serial read functions (like Serial.Read), be prepared to receive characters from the Visual Microdebugger, depending on the position of your breakpoints. As long as you only send strings to the PC using serial functions, you won't experience any interference between Visual Micro's debugger and you own usage of the serial port. To avoid such interference, you can use separate ports for these two purposes. This article shows you how to do this: "Debugging with Different Ports, Pins and Speeds". The Exact Location of a Breakpoint If you have set a breakpoint at a specific line, the instructions in this line will be executed before the breakpoint is hit. So the exact location of a breakpoint is after the last instruction of a line. In the example below, the instrdigituctioalWrin te(13, HIGH) is first executed and then the sketch hits the breakpoint. In this aspect, Visual Micro works differently than other debugging enabled development environments. Differences Against "Classic" Debuggers Users with a background from PC based development environments and debuggers may read this page to learn about the differences between these systems and Visual Micro in terms of debugging. How to Stop your Sketch, Recompile and Run As long as you are not using debugging, there is no need to explicitly stop your sketch before uploading a new version. If you have changed anything in your sketch, just press [F5] to compile and upload the new sketch. Visual Micro will interrupt the running sketch on your Arduino board, then it will upload the new sketch and restart it. See also: Compiling, Uploading and Running your Sketc h If you are using debug, howevginger, and your sketch is halted in a breakpoint, pressing [F5] will continue your sketch and will not recompile and upload. So after pressing [F5], your sketch will continue to run until it hits the next breakpoint. In this case, in order to stop the sketch, click the blue "Stop" icon in the Serial Monitor toolbar: ...or press Shift+[F5] This will disconnect your PC from the Arduino board. Pressing [F5] will then start the recompile and upload process. The "Stop" menu item in the Serial Monit menu has the same effecort. Working with Breakpoints The following chapter describes what you can do with breakpoints. For general information about debugging, read the chapter "Debugging your sketc" hfirst. All functions can be accessed with the context menu that appears when you right click the breakpoint marker to the left of your code in the code window: The main elements of this context menu are: Click on these links to learn more: Enable/Disable breakpoints Conditional breakpoints Breakpoint counter "When Hit" action Watching Variables with the "When Hit" action The "When Hit" function is a very powerful tool of Visual Micro. It lets you show the values of variables and lets you change their values while your sketch is halted in a breakpoint. Select "When Hit..." from the breakpoint context menu and the "When Hit" window appears: In the text field, you can enter a message that will be shown when the breakpoint is hit. The message will appear in the Output Windo. w Example: If you put the following in the "When Hit" text field: "Hello from my board!",... ... then the Output Windo will show the followwing when the breakpoint is hit: You can not only print static text in your message, but also actual values of variables. Example: Assuming you have a float variable called "hum". If you put the following in the "When Hit" text field: then the Output Windo will show the followwing when the breakpoint is hit: The message shows the actual value of the "hum" variable every time the breakpoint is hit. You can mix text and variables as you like, and you can also insert more two or more variables in the "When Hit" text. See below for more infor‎‎mation about the "When Hit" message string. If you have an Expression Window open, then the variable value is also reported there. See below. Analog, Digital and Performance Reporting Visual Micro can report the current status of the analog and digital inputs/outputs of 2your board as well as the devices connected to the IC bus of your CPU. If you put the following keywords into the "When Hit" field of your breakpoint, Visual Micro will open diagram windows when you sketch is started that show these values in real time. @ReportDigital Updates the status of the digital I/O lines of your board and opens the "Report Digitals" diagram window @ReportAnalog Updates the status of the analog I/O lines of your board and opens the "Report Analogs" diagram window @ReportFreeMemory Updates the diagram showing the amount of free memory and opens the "Report Free Memory" diagram window @ReportI2C 22Updates the list of connected IC devices and sends a list of connected IC devices to the Output Windo w Tracking and changing variable values in the Expression Window You will notice that there is an "Expression Window" while your debugging session is running. If this window is missing, make it visible by clicking the Serial Monitor button in the Visual Micro toolbar: The Expression Window shows the actual values of all the variables mentioned in the message strings. Every time a breakpoint is hit, the respective values will be updated in the Expression Window. In the above example, we have two breakpoints: Breakpoint 1 is located in Blink.ino, line 25 and contains this message string: "Humidity is {humidity}, counter is {counter=?}" (We will take a closer look at that "=?" after "counter" later). This lets the values of "humidity" and "counter" appear in the Expression Window. Breakpoint 2 is located in Blink.ino, line 35 and contains this message string: "valve position is {position}". This lets the value of "position" appear in the Expression Window. Values shown in red have changed since the last breakpoint hit. Note: The "Min" and "Max" columns show the minimum and maximum value of the variable. If you right click on the table header, a menu appears where you can show/hide various columns of the table: Changing variables If you put a "=?" behind a variable name, then you will not only see the value in the Expression Window, but you will also be able to change the variable's value if your sketch is halted in a breakpoint. In the above example, the variable "counter" is defined like this: "counter=?". In the Expression Window these variables are shown with a yellow background. To change the value, click into the yellow cell and enter a new value. As soon as you hit [F5] to continue your sketch's execution, the sketch will take over the changed value and set its variable (in this case "counter") accordingly. Tips for using "When Hit" breakpoints Showing more than one variable You can insert two or more variables in the "When Hit" string: Example: "Position is {position} and temperature is {currTemp}" Changing display format You can specify how your variables are displayed by adding a format specifier to the message string. Example: "Position is {position,HEX}" will show the variable in hexadecimal. You can find a complete listing of available formats in the description of the print() function in the Arduino library refer. ence Showing expressions Instead of variables, you can show expressions, like in this "When Hit" message string: Humidity is {humid‎‎ity*22.1} Expressions can also include function calls: Humidity is {getHu‎‎midityFromSensor()} Time elapsed is {millis()-startTime} milliseconds Valve {valveNo} is {valvePos == V_SHUT ? "shut" : "open"} Of course, you cannot use expressions in conjunction with "=?", because only values of variables can be changed. Showing the function name You will notice that the "When Hit" window's text mentions "special keywords" like $FUNCTION or $CALLER. Of these keywords, Visual Micro supports $FUNCTION. If you use this keyword in your message string, it will be replaced by the function's name where the breakpoint is placed. Example: If you enter this message strin‎‎g: "Hello from the $FUNCTION function", then you will get this string in the Output Windo: w The $FUNCTION placeholder was replaced by the name of the function where the breakpoint resides Enabling/Disabling breakpoints You can enable and disable breakpoints at any time without having to recompile/upload. , To enable/disable a breakpoint, right click on the breakpoint) and symbol ( select "Disable Breakpoint" or "Enable Breakpoint". Even breakpoints that are disabled keep sending trace messages to the Micro Debug Trace pane of the Output Windo, but they neverw stop the sketch when they are passed. Note: There is a setting in the project properties ("Inc. Disabled Breakpoints") that controls whether disabled breakpoints remain part of the program code during compilation. If that switch is set to "False", only enabled breakpoints will be part of the compiled sketch. With that setting, disabled breakpoints consume no program space but require the sketch to be rebuilt after being re-enabled. If the switch is set to "True", then also disabled breakpoints will be part of the sketch, which allows you to re-enable them without rebuilding the sketch. Read more about the Properties windo wherew you can change this setting. Conditional breakpoints You can specify conditions for breakpoints. When your sketch hits such a breakpoint, it only becomes effective if the condition is true. Setting a conditional breakpoint , In the breakpoint context menu, select "Condition..." The following window appears: Check the checkbox. In the text field below, enter a condition. This can be a variable like "i" or an expression like "i > 30". You can use all variables that are available at that location in your code. Choose either "Is true" or "Has changed". , With "Is true", the breakpoint will become effective if the condition is true, in this case, if 'i' is greater than 30. , With "Has changed", the breakpoint will become effective if the given expression's result has changed since the last time the breakpoint was passed. A condition can as well be quite complex like "(i > 30 || rectangle.width > 100) && k+l < m". You can even make function calls in the condition: "i > getRectangleWidth()" Note The condition remains effective even if you uncheck the condition checkbox . This is due to a limitation in the underlying Microsoft Visual Studio IDE. To remove the condition, simply enter a condition that is always true like "1", or delete the breakpoint and set a new one at the same location. Breakpoint counter Visual Micro provides breakpoint counters that are either identical to the value returned by the millis() function or are an individual counter for each breakpoint. With breakpoint counters, you can influence when and how often a breakpoint becomes effective. For example, you can tell Visual Micro to break execution only every 10th time your code passes a breakpoint or only 2 minutes after your sketch has been started. For an instruction on how to switch between individual counters and "millis()" counters, see the "Individual breakpoint" secti count‎‎eron below. Until then we assume that the Default is chosen, which is a counter that always has the value returned by the milli functs()ion. With the start of your sketch, If you choose the "Hit Count..." context menu item, the following dialog appears: Note Please ignore the informational text in the window above. This text applies to Visual Studio as a general IDE only. Visual Micro works slightly differently than the text in the window would indicate. The "Current hit count" and "Reset" controls in that window do not have any meaning when usingVisual Micro. With the selection box, you can choose... , ..."break always": the breakpoint is not affected by the counter , ..."break when the hit count is equal to": the breakpoint is effective if the value returned by millis() is equal to the number entered. , ..."break when the hit count is a multiple of": the breakpoint is effective if the value returned by millis() is a multiple of the number entered. In this way you can specify that the breakpoint is only hit every x milliseconds/seconds and ignored in between, even if the sketch code has passes it. , ..."break when the hit count is greater than or equal": the breakpoint is effective if the value returned by millis() is greater or equal to the number entered. In this way you can specify that the breakpoint is not hit before a certain time has passed. Note: "break when the hit count is equal to" may be unreliable in conjunction with a millis() counter, because you often cannot predict that whether a breakpoint is passed at all at a specificmillisecond. Use one of the other options instead. However, this option is very useful if you use individual breakpoint counters instead of the millis() value, see the section "Individual breakpoint counter" below. Visual Micro takes into account that the breakpoint may not be passed exactly when the millis() function has the given value or a multiple of it. This is an advantage over using conditional breakpoints in conjunction with the millis() function. To remove the "Hit Count" condition, open the Hit Count window again and select "break always". Individual breakpoint counter You can use an individual counter per breakpoint instead of the millis() function. You can change this setting globally or per project. If Visual Micro is set to "Counter" instead of "Milliseconds", then it maintains one counter per breakpoint. All counters start with a value of 0 when your sketch starts running. Each breakpoint's counter is incremented by one every time the sketch passes the breakpoint. By the settings above you can control when the breakpoint becomes effective in relation to the value of the counter. How to change from millis() to individual counters: , globally, for all projects: Go to Tools > Options > Visual Micro > General > Micro Debug - Advanced and change the setting from "Milliseconds" to "Counter" , ...per project: Open the Project Properties Windo. w Change the "Hit Counters" setting from "Milliseconds" to "Counter". A project specific setting -if there is any- supersedes the global setting. Note The "Current hit count" and "Reset" controls in that window do not have a meaning when usingVisual Micro. Controlling breakpoint behavior There are many settings that influence how breakpoints control execution of your code. This page summarizes the various settings. There are three modes a breakpoint can work: , Disabled In this mode, breakpoints have no effect at all, but you can leave them in your sketch, if you want to. , Enabled, not halting execution In this mode, the breakpoint updates expression windows, trace and code windows but execution of your sketch continues without interruption. , Enabled, halting execution In this mode, when a breakpoint is hit, it halts execution of your sketch until you press [F5]. To disable Debugging/Breakpoints completely... , Disable debugging in the Project Properties window by setting "(Micro Debug)" to "None" , -and- , Uncheck the "Automatic Debugging" menu item in the Tools menu If you want to disable breakpoints temporarily: , Check "Disable all breakpoints" in the "Breakpoint Manager" menu item of the Serial Monitor Options button To enable Breakpoints... , Enable breakpoints in the Project Properties window by setting "(Micro Debug)" to "Full" , -or- , Check the "Automatic Debugging" menu item in the Tools menu , -and- , Uncheck "Disable all breakpoints" in the "Breakpoint Manager" menu item of the Serial Monitor Options button To make breakpoints halt sketch execution when passed... , Uncheck the "Debug Trace Only" menu item menu item in the Tools menu , -and- , Deselect "Auto Continue" in the "Breakpoint Manager" menu item of the Serial Monitor Options button To let breakpoints continue execution of your sketch when passed... , Check the "Debug Trace Only" menu item menu item in the Tools menu , -or- , Select "Auto Continue" in the "Breakpoint Manager" menu item of the Serial Monitor Options button , -or- , If you added a "When Hit" condition to a breakpoint, check "Continue execution", see "Working With Breakpoints/When Hit " These settings become effective after a recompile/upload of your sketch These settings become effective immediately in your debugging session These settings are global for all Visual Micro projects These settings are project and configuration specific and apply to all breakpoints in the project These settings are breakpoint specific These settings are global for all Visual Micro projects and affect all configurations with names "Debug" or "Release" Debugging with Different Ports, Pins and Speeds If you need your serial port for your own purposes, e.g. for communication to other devices, then you can instruct Visual Micro to use a different serial port or you can freely define to use pins of your choice as serial ports. In general, Visual Micro supports all the serial communication options your Arduino board offers. Vice versa, it depends on your board's capabilities which options you can choose. For example, the Arduino MEGA has 4 serial ports to choose from, while many other boards only have one. Note: Visual Micro uses the upload port only while the sketch is uploaded, afterwards it releases it and it can be used for other purposes. Using Separate Ports for Debugging The port used for debugging is kept open by Visual Micro as long as the debugging session is running. Using different transport methods Arduino provides a multitude of serial communications methods which are all supported by Visual Micro. Advanced users can select the transport method of their choice and can take advantage of the flexibility needed for certain constellations. All settings are project dependent and can be found in the Project Properties window. Remote Port Specifies which port of your board shall be used for debugging. The names of the settings like "Serial1" etc. are related to the names of the Arduino library "Serial" functions for the respective ports. Make sure your board supports the ports you have selected. For debugging over the network with the Arduino Yún, select "Console" here. Remote Speed Specifies the speed (baud rate) that is used for debug communication. This value must match the Local Speed setting in your Project Properties window. Remote Transport Specifies which transport method (class) of the Arduino library shall be used for debug communications. "HardwareSerial" is the Default using the UART circuits of the board's CPU. "SoftwareSerial" uses purely software based serial communication, where you can freely choose the RX (receiving) and TX (transmitting) pins which serve as serial port. Therefore, with "SoftwareSerial" you must also specify these RX and TX pins in the respective fields of the project properties. "Bridge" is used for the Arduino Yún in conjunction with the so-called bridge. Note: Please note that the terms HardwareSerial and SoftwareSerial refer to the method in which outgoing signals are generated and incoming signals are decoded (with hardware in your processor or with a software module from the Arduino library). HardwareSerial and SoftwareSerial do not refer to hardware or software handshake (RTS/CTS vs. XON/XOFF). Arduino does not use hardware handshare with any of its serial ports. Remote Pin RX When using SoftwareSerial as remote transport method, you must specify which pin of the board shall be used as the RX (receiving) pin of the software emulated serial port. With HardwareSerial, the pins to be used are determined by the hardware and therefore cannot be changed. Remote Pin TX When using SoftwareSerial as remote transport method, you must specify which pin of the board shall be used as the TX (transmitting) pin of the software emulated serial port. With HardwareSerial, the pins to be used are determined by the hardware and therefore cannot be changed. Using a Different Local (=PC) Port for Debugging To change to local (=PC) port used for debugging, open the Project Properties window and change the settings for "Local Port" and "Local Speed". Debugging over a network with Arduino Yún To debug over the network, use the following settings in the Project Properties window: Local Port = RemotePort = Console RemoteTransport = Bridge How Tracepoints Influence Execution Speed of Your Sketch Note: Remember: Tracepoints are like breakpoints, but they do not stop sketch execution, but transmit information about your running sketch to the PC, when passed. Read more on how to control if breakpoints halt execution ("breakpoint") or not ("tracepoint") If you have tracepoints that are hit with a very high rate per second, then Visual Micro will slow the board down to a maximum of approximately 10-12 tracepoint messages per second. This prevents the PC from being flooded with messages causing it to fall behind "real-time". This retarding mechanism is called the "debugger throt tle". However, in some cases, a huge volume of trace messages might be required in bursts, followed by a "quiet" period with no trace messages. In this situation the throttle would not be required because the PC is given periods of time to process and clear the inbound debugger trace message queue and it might be annoying to have the Arduino slowed down. Then you can influence the throttle behavior with the project properties settings described here. The Tools menu The following section describes the menu items you can find under the Tools > Visual Micro menu. Many of the functions of these menu items can also be found in the Arduino Boards or Arduino Serial Monitortoolbars. Boards Selects the board you want to work with. See Setting up your Board Model and Connection, where board selection is described using the Arduino Boardstoolbar. Serial Port Selects the Serial Port to which your board is connected. See Setting up your Board Model and Connection, where port selection is described using theArduino Boards toolbar. Serial Monitor Opens the Serial Monitor Window for the serial port you have selected. Other Serial Ports Opens an additional Serial Monitor Window where you can watch serial communication with a second board or with a second serial connection to the same Arduino board. See Debugging with Different Ports, Pins and Speeds for more information. Programmers Programmers are hardware devices that you can use for uploading sketches to your Arduino board (as an alternative to a serial connection) or -more important- to burn a bootloader into the CPU of your board. They are mainly important for users who like to create their own boards with "blank" processors they have bought at a retailer. The Programmers menu item lets you select the programmer type you have connected to your PC. After selecting a programmer, you can use it to upload sketches or to burn a bootloader. Upload Using Programmer This menu item can be checked/unchecked to switch on or off the upload method using your programmer. If you have checked "Upload Using Programmer", your uploads will be done via the programmer instead of a serial connection. This method requires that you select the programmer model you are using with the "Programmers" menu item above. Note: For Atmel Studio users: If you have a programmer that is compatible with Atmel Studio, then you can instruct Visual Micro to use it for uploads, so that you don't have to upload manually with Atmel Studio's "Device Programming" menu item. For this purpose, select the appropriate programmer (whose name begins with "Atmel ...") in the "Programmers" menu item. Burn Bootloader After you have selected the programmer model you are using with the "Programmers" menu item above, you can use this menu item to burn a bootloader onto your board's CPU. WARNING: You can permanently damage your board's CPU if you make mistakes here! Burning bootloaders is only recommended for experienced users! Automatic Debugging Enables debugging regardless of project properties for all configurationsnames "Debug" or "Release". This is the most convenient way of switching debugging on or off. For a complete overview of debugging setting read this article. Debug Trace Only Only relevant if debugging is on. If this option is checked, breakpoints do not halt the sketch execution and become "tracepoints". If such a tracepoint is passed, you will see a message in the Debug Trace Window, but your sketch will continue execution. Tutorial Mode If this option is checked, then Visual Micro shows additional message windows that help new users. It also sets and automatic "demo breakpoint" at the start of the "loop() function" as described here. Verbose Mode "True" shows detailed compiler output in the Output Window when compiling. Same settings as described under Tools > Options. Compiler Warnings "True" shows compiler warnings in the Output Window when compiling. Compiler warnings are very useful and should be taken seriously to avoid coding errors. Same settings as described under Tools > Options. Note: Compiler Warnings often help you in finding hidden bugs in your code. Example: if( counter = 4 ) { counter == 4; } Both these code lines are legal, but probably it is not what you intended: The first line should possibly be a comparison (==), but it is an assignment (=), and the second line should be an assigment, but it is a comparison without any effect. Both lines are valid C++ but make no sense and indicate a programming mistake. Compiler warnings can show you such spots. Reload Tool Chains If you have changed anything in the board or programmer configuration files, then you can reload the compilation/upload tools in order to make the changes effective in Visual Micro. Example: You have changed something in the BOARDS.TXT file that contains board properties and settings. Then you should use "Reload Tool Chains" afterwards, which will cause Visual Micro to reload configurations. Reset User Interface Sometimes after installation some Visual Micro menu commands do not appear, or Visual Micro menu/buttons commands appear multiple times. In this case, you can use this menu item to repair menus and buttons. Note: If you have customized Visual Micro related menus or toolbars you will lose these settings, as they will be reset to their defaults by this command. Configure IDE locations Opens the Configuration Manager that lets you specify where your original Arduino IDE's files are stored Platform Explorer Opens the Micro Explorer window. Visual Micro Home Opens your web browser and navigates to the Visual Micro home page Visual Micro Documentation Opens your web browser and navigates to the Visual Micro online documentation Tools > Options Settings Reference The following list describes all setti‎‎ngs that are located in the menu under Tools > Options > Visual Micro > General. All these settings are not project specific and are stored system wide. Note: The following list is ordered according to the categorized view of the Settings list. To switch this list to the categorized view, use this icon on the top left of the window: Application Features License Key Enter or remove a purchased license key to activate/deactivate your edition of Visual Micro and its features. If you deactivate during a trial period you will not be able to reactivate it again! If you deactivated a license, you will be able to reuse it on a different computer. License Status This is the current state of your license Applications & Locations Application Ide Locations Opens the Configuration Manager (read more) Cygwin The location of the 'cygwin\bin' folder where 'cygwin' is the root of the cygwin installation. This property is optional, Cygwin is required by certain projects like ArduPlane. More information can be found here and here My Visual Micro Configs Optionally enter the folder where Visual Micro custom applications config is (or will be) stored. If unspecified then 'MyDocuments\Visual Micro' folder is used. Additional features pack license holders have the facility to create/register new ide apps and override hardware settings using this configuration. Communications Auto Clear If set to "True", clears the inbound data window of the Serial Monitor every time Visual Micro reconnects to the Arduino board. Auto Re-Connect Automatically detect disconnects from your Arduino board over the serial line, makes repeated attempts to reconnect. Tip: Alternatively, you can untick the "Connect" button on the Serial Monitor to prevent auto-reconnect, then tick it again when the device has become available again. Auto Scroll When inbound serial data is received the Serial Monitor auto scrolls to the location where the cursor is. Baud Rate (only for internal purposes, do not change) Dtr (only for internal purposes, do not change) Friendly Port Lists Show additional information in the port selection box of theSerial Communications Toolbar and window titles. This property is ignored if "Network Discovery" is enabled. Friendly Port Menus Same as above for Serial Port Menus (see The Tools Menu). Do not change this setting unless instructed by a Visual Micro support person. Last Port (only for internal purposes, do not change) Line Endings (only for internal purposes, do not change) Network Discovery Allow DNS network discovery for hosts such as the Arduino Yun. Requires "Apple Bonjour for Windows" to be installed otherwise network devices will not be found. You can get Apple Bonjour by installing Apple iTunes or by searching for a download location here. Screen Buffer Size Specifies the maximum size of bytes the Serial Monitor stores and displays. If the buffer runs full, older data will be removed from it. Single Instance (only for internal purposes, do not change) Ssh Connection Timeout Timeout in milliseconds when connecting to remote network devices such as the Arduino Yun. Set to 0 for the default (which is currently 50ms because we are using telnet on localhost). Irrelevant when using serial connections. Compiler Debug Configuration (only for internal purposes, do not change) Release Configuration (only for internal purposes, do not change) Show Build Folder "True" shows the build folder after compilation in the Output Window. Show Build Properties "True" shows the build properties for the current hardware in the Output Window when buidling. Stop On Error "True" stops the compilation immediately if core or library compilation return an error, does not continue with compilation of your sketch's source files. This can be useful as source compilations make no much sense until core and library compilations work correctly. Use temporary folder (only for internal purposes, do not change) Verbose "True" shows detailed compiler output in the Output Window when compiling. Warnings "True" shows compiler warnings in the Output Window when compiling. Compiler warnings are very useful and should be taken seriously to avoid coding errors. Note: Compiler Warnings often help you in finding hidden bugs in your code. Example: if( counter = 4 ) { counter == 4; } Both these code lines are legal, but probably it is not what you intended: The first line should possibly be a comparison (==), but it is an assignment (=), and the second line should be an assigment, but it is a comparison without any effect. Both lines are valid C++ but make no sense and indicate a programming mistake. Compiler warnings can show you such spots. Compiler Optimisation Core Modified "True" skips compilation of the core if there were no changes since the last compilation. This saves compilation time by avoiding unneeded compilations. Library Modified "True" skips compilation of libraries if there were no changes since the last compilation. This saves compilation time by avoiding unneeded compilations. Intellisense Always Re-Add Header In some versions of Visual Studio, intellisense will only refresh reliably when Visual Micro removes and re-adds the auto generated vsarduino.h header. Disable this feature to prevent this feature. If the intellisense becomes wrong then switching board or re-opening the project will fix the problem. It is recommended to leave this value in its default setting ("True"). Intellisense is the built-in functionality that shows popup windows with a selection of functions and variables while you type in the source code editor. MCU General Last Board (only for internal purposes) Last IDE Application (only for internal purposes) Parent Libraries If set to "True", Visual Micro searches for library files in the sketch parent folder Micro Debug - Advanced Automatic debugging If set to "True", the debugger will be also be used with "Release" configurations, regardless of other project and build settings. (Read more). Can also be set by the "Automatic debugging" menu item in the Tools menu. Hit Counters Controls if breakpoint hit counters count how often a breakpoint was hit ("Counter") or represent a millisecond time counter ("Milliseconds"). (Read more) Micro Debug - Automated loop() - Auto Create Breakpoint If set to "True" and if no breakpoints are defined when debug starts, then a tracepoint is automatically created at the start of the loop() function. (Read more about breakpoints). The following settings in this section are all related to this demo breakpoint. loop() - Condition Enabled If set to "True", then the demo breakpoint contains a break condition. (Read more about breakpoints) loop() - Conditional Expression Enter an optional default breakpoint conditional expression for the demo tracepoint that is automatically created. For new user educational purposes only. loop() - Hit Count Frequency (ms) The number of milliseconds between execution of the demo breakpoint. loop() - Hit Counter If True then your board will run at full speed periodically reporting demo breakpoints every n milliseconds (default n=250). loop() - Message/Watch Enter a message or list of {watch expressions} for the demo breakpoint. Expressions must be global values and valid for EVERY project. Please see theProject Properties for more granular control. loop() - Message/Watch Enabled If set to "True", then showing a Message/Watch expression for the demo breakpoint is enabled. Micro Explorer View Project Properties If set to "True", opening the Micro Explorer Help Window, will also open the current Project Properties Window. Misc AllowCompile (only for internal purposes, do not change) AllowUpload (only for internal purposes, do not change) AutoCreate (only for internal purposes, do not change) AutoOpen (only for internal purposes, do not change) LastPowerTools DebuggerCheckDateTime (only for internal purposes, do not change) LastUpdateCheckDateTime (only for internal purposes, do not change) On Shutdown Delete Commands (only for internal purposes) Programmers Last Programmer (only for internal purposes) Programmers Upload Using Represents the setting of the "Upload Using Programmer" menu item in theTools menu. Available Version Shows the version number of the newest Visual Micro version available on visualmicro.com. If the "Check for updates" value is set to "True", then you will be informed that a newer version is ready for download. System Check for updates If set to "True", then Visual Micro checks for updates on visualmicro.com periodically and informs you if a new version is ready for download. Hardware ID (only for internal purposes) Serial No. (only for internal purposes) Stop trying to sell me stuff If set to "True", then Visual Micro will not inform you anymore about upgrade offers. Url Override An alternate location to find Visual Micro software updates. Leave this field empty unless instructed by a Visual Micro support person. avr (only for internal purposes) User Interface Auto Detect (only for internal purposes) User Interface Installed (only for internal purposes) Platform Explorer Used (only for internal purposes) Prevent duplicating UI issues (only for internal purposes) Trace If set to "True", a diagnostics trace messages will be written to a sub folder below the location of the visual micro addin dll. Administrator permissions might be required. Use this setting only if you were told to use it by a Visual Micro support person. Version Assembly Location Show where the visual micro program files have been installed and which ui is running (e.g. 08.dll = Visual Studio 2008) Version (used internally for the update notification system) Version Minor (used internally for the update notification system) Using Project Properties as defines in your code You can define constants in your project properties. You can then use these constants in your sketch to control your sketch's behavior depending on these constants. Simple defines In your Project Properties windo, you can speciwfy defines that behave like #define directives in your source code. Instead of writing #define USBPORT 4 you can enter the define in your project properties: Values in the "Defines - Configuration" field are confi depengurat‎‎iondent, you can have different defines in your sketch, depending on your configuration (e.g. "Debug" and "Release"). You can also enter values in the field below, named "Defines - Project", these are configurationindependent. You can then use these defines like ordinary #defines written into the code, like in this example: #if USBPORT > 3 ....your code here.... #endif Using build properties as defines Note: This functionality requires Visual Micro version 1.1407.10 SP1 (September 2014) or newer. Build properties are parameters that control the compilation and upload process. You can take advantage of these build properties and use them in project property defines. Refer to the build properties by putting them in curly braces: Visual Micro will replace {upload.maximum_size} with the actual value of that build property, e.g. 30720 in case of an Arduino Nano board. An equivalent hardcoded #define in the code would look like this: #define PROGMEM_SIZE 30720 With this type of defines, you can, for example, adjust your sketch to the board you are using without changing your source code. With the PROGMEM_SIZE example above, you could compile parts of your sketch only if the board's program memory is big enough: #if PROGMEM_SIZE > 50000 ....your code here.... #endif Where do I find the build properties? You can create a complete list of the available build properties with this option: Tools > Optio > Visuansl Micro > Compiler > Show Build Properties With your next build (using [F7]), you will get a complete list of the build properties in the Output Windo. w Converting defines into strings The following tip applies to C/C++ preprocessor defines in General and is supported by modern compilers. If you want to use a define as a string, you can use the compiler's "Stringification" function, example: #define TOSTRING( X ) #X char progmemSizeString[] = "Progmem size is " TOSTRING(PROGMEM_SIZE); The TOSTRING quasi macro puts quotes around the value, so that 30720 becomes "30720". This lets you use build properties as C/C++ strings. The above lines of code are equivalent to: char progmemSizeString[] = "Progmem size is 30720"; Note that "Stringification" only works in preprocessor macros, that's why we need the TOSTRING macro here. Frequently Asked Questions Installation and Building Sketches The Visual Micro Installation failed with error number 1001, what shall I do? Solution: Visual Micro requires .NET Framework 3.5 to be installed. Download the .NET Framework, install it and then start the Visual Micro installation again. Can Visual Studio Express and Atmel Studio be installed on the same computer? Yes, all versions of Visual Studio and Atmel Studio can coexist on the same computer without causing any issues. I have deleted files from my project, but they are still used in compilation If you have removed a file from your project by pressing [Del] in the Solution Explorer, you had the choice to remove it from the project or to delete it from your hard drive. If you choose only to remove it, it will still be part of the compilation. Open Windows explorer and delete the file. If you want to keep it but exclude it from the compilation, simply rename the file extension, e.g. from "myfile.cpp" to "myfile.__cpp" After making changes to my project, I get strange compiler errors or my sketch will not run correctly anymore, but I can’t find any mistakes in my code. What shall I do? I have manually changed various library and/or core source codes and need to ensure a clean compilation Sometimes, in advanced projects, changes to #defines or changes to library code require a clean build.This page describes how to perform a clean build. When I try to create a new sketch or add an existing sketch, I get the message "Unable to create an Arduino project for Atmel Studio" This can occur when using Atmel Studio 6.2. In this case, uninstall Visual Micro and reinstall it as an administrator by right clicking on Visual Micro's installer file and choose "Run as administrator". When trying to build my sketch, I get the error message "'xxxx' was not declared in this scope", although xxxx is declared correctly This problem may occur if two conditions are met: 1. You have used a C++ typedef as a parameter for a function definition 2. Your function is in an .INO file Solutions: 1. Change this file into a .CPP file. 2. Avoid using typedefs as function parameters. 3. Switch off automatic generation of function prototypes (see here). Then your .INO files behave like .CPP files I have problems with foreign characters like "ä" and "Д", and the original Arduino IDE handled them differently. If you have such characters in your code, then you will notice that they will all be translated into the same three byte code 0xef 0xbf 0xbd in your compiled program. This article explains how to repair this and gives you general advice about handling Non-ASCII characters. I have renamed one of my .INO files and now the sketch does not compile anymore This may come from the way how Visual Micro combines all .INO files into one big INO file. Debugging I have enabled debugging but it does not work Please keep in mind that the debugging system uses the serial port and expects a baud rate as set in Visual Micro. If your sketch code uses the serial port as well, then you must use the same baud rate as Visual Micro (in your Serial.begin() function call) or adjust Visual Micro's baud rate to yours. Visual Micro's default baud rate is 115.200, you can change the baud rate in the Project Properties (Local Speed and Remote Speed settings). As an alternative, you can use separate serial ports for debugging and other communications (Read more)
本文档为【利用VS调试arduino】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_624976
暂无简介~
格式:doc
大小:984KB
软件:Word
页数:95
分类:企业经营
上传时间:2017-11-14
浏览量:34