Arduino Custom Build Events

by Visual Micro 20. March 2017 04:37

Arduino supports many different build events. Visual Micro supports the same events and more. If you can't find an event that meets your needs then please make a request to our forum. Build events are normally placed in the arduino platform.txt system which can be quite convoluted and difficult to test. Licensed users of Visual Micro can opt to use  local project board.txt instead of the usual Arduino locations. The advantage is easier development and testing along with events that are specific to a single project. When making changes to a local board.txt click the "Save" button pior to testing a new build.

The full Arduino build specification is listed here. Visual Micro also provides the following additionl events:-

  • Pre upload event
  • Error during upload event
  • Post upload event (only executes if no error was encountered)

Paste the following into a board.txt to see an attempt to run events. Obviously the example will produce an error because the .bat file will be missing but you will see how it works :)

# before upload event - example

recipe.hooks.deploy.preupload.pattern=cmd.exe /c "c:\hooks_test\test_pre.bat" "{build.path}"  "{build.project_name}" "{build.project_path}"

# upload failed event - example

recipe.hooks.deploy.errorupload.pattern=cmd.exe /c "c:\hooks_test\test_error.bat" "{build.path}"  "{build.project_name}" "{build.project_path}"

# upload complete event - example

recipe.hooks.deploy.postupload.pattern=cmd.exe /c "c:\hooks_test\test_post.bat" "{build.path}"  "{build.project_name}" "{build.project_path}"

Announcing the Wiring Ide for Visual Studio

by Visual Micro 7. March 2015 11:17

The Wiring Ide has been added to the standard list of supported Visual Studio Ide's.

The Wiring Ide gives an interesting alternative to building programs with the Arduino core/backend.

Hardware manufacturers, such as sparkfun electronics, make simple update packs for Wiring that extend the list of available boards that can be developed using the Ide.

Read more

Image of the Wiring Ide hardware being programmed in Microsoft Visual Studio

 

Arduino Robot and TFT Display

by Visual Micro 22. May 2013 19:22

I just read the article below about the new arduino tft that shows the code to draw a sensor value on the screen instead of serial debug :)

It is a nice little Arduino shield http://arduino.cc/en/Tutorial/TFTDisplayText

I recon the visual micro debugger could have an option to print some breakpoint data to the screen for the users. It would be a hell of a  lot easier :)

Maybe a debugger visualization can be created in c# to replicate the shield? Any offers anyone? 

#include <TFT.h>  // Arduino LCD library
#include <SPI.h>

// pin definition for the Uno
#define cs   10
#define dc   9
#define rst  8  

// pin definition for the Leonardo
// #define cs   7
// #define dc   0
// #define rst  1 

// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);

// char array to print to the screen
char sensorPrintout[4];

void setup() {
  
  // Put this line at the beginning of every sketch that uses the GLCD:
  TFTscreen.begin();

  // clear the screen with a black background
  TFTscreen.background(0, 0, 0);
  
  // write the static text to the screen
  // set the font color to white
  TFTscreen.stroke(255,255,255);
  // set the font size
  TFTscreen.setTextSize(2);
  // write the text to the top left corner of the screen
  TFTscreen.text("Sensor Value :\n ",0,0);
  // ste the font size very large for the loop
  TFTscreen.setTextSize(5);
}

void loop() {

  // Read the value of the sensor on A0
  String sensorVal = String(analogRead(A0));
 
  // convert the reading to a char array
  sensorVal.toCharArray(sensorPrintout, 4);

  // set the font color
  TFTscreen.stroke(255,255,255);
  // print the sensor value
  TFTscreen.text(sensorPrintout, 0, 20);
  // wait for a moment
  delay(250);
  // erase the text you just wrote
  TFTscreen.stroke(0,0,0);
  TFTscreen.text(sensorPrintout, 0, 20);
}

Apm - Installation Guide

by Visual Micro 2. May 2013 15:21

new August 2016. There appears to be a more up to date solution for ArduPilot developers here https://github.com/JeffyW/ardupilot/tree/development

Tip: ArduPilot wiki notes about atmel studio also apply to visual studio.

The following notes might be out of date. Please see the ArduPilot link above or the ArduPilot wiki for currnt information.

APM Developer Wikihttp://dev.ardupilot.com/wiki/building-ardupilot-apm-with-visual-studio-visual-micro/

Installation for APM versions 2.9x is quite simple. You will already have installed the APM firmware.

1) Install either Arduino 1.0.x or 1.5.x Ide or the modified diydrones Arduino ide

2) Install Visual Micro and open Visual Studio

3) If you are a first time user of Visual Micro then you might be prompted to enter your arduino ide installation location. Otherwise set via "Tools>Options>Applications & Locations". Please read the next step before closing the locations configuration window.

4) If you have not set the arduino ide sketchbook folder as instructed in the diyd instructions then set it now in Visual Studio or Atmel Studio. If you have not just completed step 3) above then click the list of applications to the left of the list of boards on the tool bar and then click "Configure" (or use tools>options>visual micro>application locations). Enter the sketchbook location against the arduino ide entry that you are using. 

5) Unzip this file into the sketchbook folder (normally the sketchbook folder is 'mydocuments\arduino'), it should create a "hardware" folder with sub folder called apm, in the apm folder should exist one boards.txt file. This zip should result in additional APM boards appearing at the bottom of the boards list in visual Micro

6) If Visual Studio was already open when you unzipped the file then click "Tools>Arduino>Reload Tool Chain"

7) Confirm that you see APM boards in the boards list

8) Enjoy and please use our forum if you encounter any difficulties

notes

For advanced users, it is not important (optional) to install the modified Arduino IDE from diydrones. The standard Arduino ide should work well. For newer users you should install the modified Arduino ide from diydrones so that you can verify that any compile failiures are due to the APM project code and not a fault of the plugin. If the compile works in the modified arduino ide but not with Visual Micro then please report the problem to the forum.

The APM SITL board willl only compile if you have installed cygwin and set visual studio "Tools>Options>Visual Micro>Applications & Locations>Cygwin" with the location of the Cygwin install. Normally c:\cygwin. You can follow these instructions to ensure cygwin installs correctly. If you have a problem then remove the install and start again.

Visual micro will work with boards found in a file called boards.txt or vmboards.txt. Boards.txt is the standard Arduino name for the file, vmboards.txt is unique to Visual micro and will be invisible to the arduino ide. It might be a good idea to place boards for cores that the arduino ide does not understand in vmboards.txt. This will avoid the potential confusion of attempting to build a board in the arduino ide with properties that are unrecognized and might not produce the desired results.

 

Arduino Advanced Build Examples

by Visual Micro 2. May 2013 12:26

Note: In releases after in 1305.01 arduino 1.5 build {variables} can optionally be used

This document is draft and subject to change. Currently using diydrones apm example

##############################################################

apm_1280.name=APM Arduino Mega 1280

apm_1280.upload.protocol=arduino

apm_1280.upload.maximum_size=126976

apm_1280.upload.speed=57600

apm_1280.bootloader.low_fuses=0xFF

apm_1280.bootloader.high_fuses=0xDA

apm_1280.bootloader.extended_fuses=0xF5

apm_1280.bootloader.path=atmega

apm_1280.bootloader.file=ATmegaBOOT_168_atmega1280.hex

apm_1280.bootloader.unlock_bits=0x3F

apm_1280.bootloader.lock_bits=0x0F

apm_1280.build.mcu=atmega1280

apm_1280.build.f_cpu=16000000L

apm_1280.build.core=arduino

apm_1280.build.variant=mega

apm_1280.build.option1=-mcall-prologues

apm_1280.build.linkoption1=-mcall-prologues

##############################################################

mytest1.name=APM Arduino Mega 2560 

mytest1.upload.protocol=wiring

mytest1.upload.maximum_size=258048

mytest1.upload.speed=115200

mytest1.bootloader.low_fuses=0xFF

mytest1.bootloader.high_fuses=0xD8

mytest1.bootloader.extended_fuses=0xFD

mytest1.bootloader.path=stk500v2

mytest1.bootloader.file=stk500boot_v2_mega2560.hex

mytest1.bootloader.unlock_bits=0x3F

mytest1.bootloader.lock_bits=0x0F

mytest1.build.mcu=atmega2560

mytest1.build.f_cpu=16000000L

mytest1.build.core=arduino

mytest1.build.variant=mega

mytest1.build.option1=-mcall-prologues

mytest1.build.linkoption1=-mcall-prologues

##############################################################

apm1_1280HAL.name=Arduino Mega 1280 HAL (Apm 1)

apm1_1280HAL.upload.protocol=arduino

apm1_1280HAL.upload.maximum_size=126976

apm1_1280HAL.upload.speed=57600

apm1_1280HAL.bootloader.low_fuses=0xFF

apm1_1280HAL.bootloader.high_fuses=0xDA

apm1_1280HAL.bootloader.extended_fuses=0xF5

apm1_1280HAL.bootloader.path=atmega

apm1_1280HAL.bootloader.file=ATmegaBOOT_168_atmega1280.hex

apm1_1280HAL.bootloader.unlock_bits=0x3F

apm1_1280HAL.bootloader.lock_bits=0x0F

apm1_1280HAL.build.mcu=atmega1280

apm1_1280HAL.build.f_cpu=16000000L

apm_SITL.build.nocore=true

apm_SITL.build.noarchive=true

apm1_1280HAL.build.option1=-mcall-prologues

apm1_1280HAL.build.option2=-DCONFIG_HAL_BOARD=HAL_BOARD_APM1

apm1_1280HAL.build.option3=-DEXCLUDECORE

apm1_1280HAL.build.linkoption1=-mcall-prologues

apm1_1280HAL.build.noarchive=true

##############################################################

apm1_2560HAL.name=Arduino Mega 2560 HAL (Apm 1)

apm1_2560HAL.upload.protocol=wiring

apm1_2560HAL.upload.maximum_size=258048

apm1_2560HAL.upload.speed=115200

apm1_2560HAL.bootloader.low_fuses=0xFF

apm1_2560HAL.bootloader.high_fuses=0xD8

apm1_2560HAL.bootloader.extended_fuses=0xFD

apm1_2560HAL.bootloader.path=stk500v2

apm1_2560HAL.bootloader.file=stk500boot_v2_mega2560.hex

apm1_2560HAL.bootloader.unlock_bits=0x3F

apm1_2560HAL.bootloader.lock_bits=0x0F

apm1_2560HAL.build.mcu=atmega2560

apm1_2560HAL.build.f_cpu=16000000L

apm1_2560HAL.build.nocore=true

apm1_2560HAL.build.noarchive=true

apm1_2560HAL.build.option1=-mcall-prologues

apm1_2560HAL.build.option2=-DCONFIG_HAL_BOARD=HAL_BOARD_APM1

apm1_2560HAL.build.option3=-DEXCLUDECORE

apm1_2560HAL.build.linkoption1=-mcall-prologues

apm1_2560HAL.build.noarchive=true

##############################################################

apm2_2560HAL.name=Arduino Mega 2560 HAL (Apm 2)

apm2_2560HAL.upload.protocol=wiring

apm2_2560HAL.upload.maximum_size=258048

apm2_2560HAL.upload.speed=115200

apm2_2560HAL.bootloader.low_fuses=0xFF

apm2_2560HAL.bootloader.high_fuses=0xD8

apm2_2560HAL.bootloader.extended_fuses=0xFD

apm2_2560HAL.bootloader.path=stk500v2

apm2_2560HAL.bootloader.file=stk500boot_v2_mega2560.hex

apm2_2560HAL.bootloader.unlock_bits=0x3F

apm2_2560HAL.bootloader.lock_bits=0x0F

apm2_2560HAL.build.mcu=atmega2560

apm2_2560HAL.build.f_cpu=16000000L

apm2_2560HAL.build.nocore=true

apm2_2560HAL.build.noarchive=true

apm2_2560HAL.build.option1=-mcall-prologues

apm2_2560HAL.build.option2=-DCONFIG_HAL_BOARD=HAL_BOARD_APM2

apm2_2560HAL.build.option3=-DEXCLUDECORE

apm2_2560HAL.build.linkoption1=-mcall-prologues

apm2_2560HAL.build.noarchive=true

##############################################################

apm_SITL.name=Apm SITL

apm_SITL.upload.protocol=wiring

apm_SITL.upload.maximum_size=258048

apm_SITL.upload.speed=115200

apm_SITL.bootloader.low_fuses=0xFF

apm_SITL.bootloader.high_fuses=0xD8

apm_SITL.bootloader.extended_fuses=0xFD

apm_SITL.bootloader.path=stk500v2

apm_SITL.bootloader.file=stk500boot_v2_mega2560.hex

apm_SITL.bootloader.unlock_bits=0x3F

apm_SITL.bootloader.lock_bits=0x0F

apm_SITL.build.mcu=atmega2560

apm_SITL.build.f_cpu=

apm_SITL.build.core=

apm_SITL.build.nocore=true

apm_SITL.build.noarchive=true

apm_SITL.build.noeep=true

apm_SITL.build.nohex=true

apm_SITL.build.nosize=true

apm_SITL.build.toolset=cygwin

apm_SITL.build.architecture=

apm_SITL.build.toolchain.path=

apm_SITL.build.command.gcc=gcc-?

apm_SITL.build.command.g++=g++-?

apm_SITL.build.command.link=g++-?

apm_SITL.build.command.run="%SKETCH_BUILD_PATH%\%SKETCH%.exe"

apm_SITL.build.default.cpp.options=-g -DF_CPU=   -Wa,-adhlns="%SOURCE_BUILD_PATH%\%SOURCE_FILE%.lst" -O0 -g -Wformat -Wall -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wformat=2 -Wno-reorder -MD -MT "%SOURCE_BUILD_PATH%\%SOURCE_FILE_W_EXT%.o" -ffunction-sections -fdata-sections -fno-exceptions -fsigned-char -c -I"%SKETCH_PATH%" 

apm_SITL.build.default.c.options=-g  -DF_CPU= -Wa,-adhlns="%SOURCE_BUILD_PATH%\%SOURCE_FILE%.lst" -O0 -g -Wformat -Wall -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wformat=2 -Wno-reorder -MD -MT "%SOURCE_BUILD_PATH%\%SOURCE_FILE_W_EXT%.o" -ffunction-sections -fdata-sections -fsigned-char -c -I"%SKETCH_PATH%" 

apm_SITL.build.default.s.options=-g  -assembler-with-cpp -DF_CPU= -Wa,-adhlns="%SOURCE_BUILD_PATH%\%SOURCE_FILE%.lst" -O0 -g  -MD -MT "%SOURCE_BUILD_PATH%\%SOURCE_FILE_W_EXT%.o" -c -I"%SKETCH_PATH%" 

apm_SITL.build.option1=-DCONFIG_HAL_BOARD=HAL_BOARD_AVR_SITL

apm_SITL.build.option2=-DSKETCH="\"%SKETCH%\""

apm_SITL.build.option3=-D_GNU_SOURCE

apm_SITL.build.default.link.options=-g -D_GNU_SOURCE -O0 -g -Wformat -Wall -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Wformat=2 -Wl,--gc-sections -Wl,-Map -Wl,"%SOURCE_BUILD_PATH%\%SKETCH%.map" -o "%SOURCE_BUILD_PATH%\%SKETCH%.exe"

Apm SITL - Cygwin Installation

by Visual Micro 27. April 2013 18:47

How to install cygwin (download the cygwin setup.exe and run using windows cmd)

setup.exe -q -R [DIR here you want it] -l [dir for packages]packages -s http://box-soft.com -P ca-certificates,make,wget,git,gcc-core,gcc-g++,gcc,git,libintl2 


If you do not have APM sources and want them ....

https://github.com/diydrones/ardupilot.git

ApmRover, copter etc. is here:  https://github.com/diydrones.git

Example sitl compile, just go into APMrover2, and ...

make configure

make sitl

or

make APM

But in the latter case you need the arduino environ installed and in your configure.mk file.

Resulting build location will be [cygwin]\tmp\APMrover2.build

Recommended: "remake" clone of make, because with the -n option, you can see all the commands the make file will try to issue.  Helps you see exactly what is going on.

Tags:

OEM Projects

Configure Arduino Debugging to use Software Serial

by Visual Micro 6. May 2012 12:00

The method of "Transport" used to send or receive debug messages on the Arduino defaults to standard serial ports such as Serial or Serial1 etc. The default (empty) is "Serial" however the RemotePort project property can be altered to another port suppoted by the micro-controller.

The "RemoteTransport" project property allows SoftwareSerial and spare digital pin(s) to be used as an alternative to the built-in Serial ports. The SoftwareSerial library is automatically included duiring debug compilation if required. The RemoteTx (and RemoteRx for Debug Break/Pause/Step) project properties should be populated with the digital pin numbers used for tx/rx on the Arduino. See the arduino.cc software serial guide when choosing digital pins

To use FastSerial the project must include all required library references and the RemoteTransport project property must be set to FastSerial. Other methods of debugger "transport" can be added by advanced users. We hope that in the future debugger transport will be configurable using a simple user interface. Please ask in the forum for more information.

All of the options shown below are default except for the FastSerial setting. 

click the image for a draft debugger overview tutorial

Tips...

  • To use a different Arduino serial port such as Serial2, enter Serial2 as the "RemotePort" property
  • To use a different PC serial port such as COM7, enter COM7 as the "LocalPort" property
  • To switch from the default speed of 115200, set the "LocalSpeed" to value from the pick list, RemoteSpeed will change automatically to match.
  • Apm users should not that the "Throttle" properties relate to debugger bandwidth throttling and are nothing to do with drones :) Leave the throttle at the defaults, learn more about the throttle via the forum.
  • If using SoftwareSerial on spare digital pins you should clear the RemotePort property and set the Remote Rx Tx Pins to the digital pins that are connected to the serial device or cable. If "Break/Pause" and "Startup Wait" are not enabled (default) then only the Arduino Tx pin is required

And a few hints that might mean something at some stage...

1) Validation Skip (project property) 

Set to False if you are not altering the arduino code in a way that might cause compilation errors. This will skip the "release" build of apm that happens prior to the debug build. (Saves time)

2) TracePoint Throttle (project property)

An unconditional breakpoint/tracepoint example in the 50hz loop is a good example for us to use...

By default, for newer users and non fastserial users the breakpoints are throttled so that the 50hz loop will only run at about 8-12hz. Visual micro ensures an 80 millisecond delay between breakpoints. 

a)
FastSerial, if available, is more efficient than normal Arduino Serial therefore you could change the project property called Throttle (ms) to, for example, 30 (milllis) which would improve the speed. Leaving the Throttle (ms) empty uses the default of 80ms.

or b)
Try setting "Throttle Enabled = False" to entirely disable throttling in which case apm will send as fast as it can but it is possible for the arduino buffer to overflow causing the debug to stop working or invalid serial packets to be received by the debugger

or c)
Set the breakpoint "HitCount" to 50. Because we are in the 50hz loop this should produce one debug breakpoint message every second allowing apm to function at full speed inbetween each breakpoint message

or d)
Set the "Hit Counter" project property to milliseconds and all the breakpoint "HitCounters" will no longer be treated as counts, instead the HitCounts will represent milliseconds. So a breakpoint "HitCount" of 1000 would produce a debug  message exactly once every second regardless of where you put the breakpoint.

IMPORTANT NOTES 

When sharing the serial port with the arduino code you might expect to see some "junk" in the serial window. This is normal, the debugger windows will workaround the "junk" and function correctly. If your arduino program reads the serial port then you will not be able to switch on the break/pause facility in which case you should use a different arduino serial port or SoftwareSerial on two digital pins.

The throttle setting is very dependant on the speed of your pc. If the arduino sends messages faster than your pc can process them the pc display will fall behind the arduino. The pc display will no longer be real-time and will be confusing.

Reminder: Please read our disclaimers !!