Nov 072014
MPLAB X IDE Debugging Environment

MPLAB X IDE: In a debugging environment, you can put a breakpoint wherever you want to stop the code from running. On the bottom of the window, you can see the variable tab where you are able to create watch variables. If you create a watch variable, you can see the values change between each step.

If you’re like me, mixing up things that sound alike is not difficult to do. For example, I can easily mix up chipKIT and PICkit, especially if I’m tired and I’m not thinking well. MPIDE and MPLAB IDE are a close second; they just sound too much alike. So it’s not difficult to see that if the names mix you up and you don’t really know that much about either of them, you might wonder what distinguishes the two and why you’d want to use one over the other. For a quick summary of the differences between using MPIDE (Multi-Platform IDE) and MPLAB X IDE check out this MPIDE vs MPLAB IDE blogpost by Digilent.

However, I would like to preface that article with the following points. Since MPIDE was ported from the original Arduino IDE, and since Arduino was meant to be simple and easy to use, there wasn’t a whole lot of functionality built into the IDE from the beginning. It simply works as an editor allowing you to compile your code and program it to your target board (via the bootloader). Debugging was not built into Arduino IDE, but most people use “printf()” statements and the Serial Monitor to help debug their programs/sketches. Microchip’s MPLAB X IDE, however, has always been a debugging environment in addition to being an editor and integrating a compiler.

That being said, good luck not mixing them up now!

VN:F [1.9.22_1171]
Rating: 5.6/10 (5 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

How to Add a Custom Board to MPIDE

 chipKIT Users  Comments Off on How to Add a Custom Board to MPIDE
Nov 082013

chipKIT MPIDE Board Variant Mechanism

The chipKIT MPIDE system has been designed to make it relatively easy to adapt the operation of the system to new hardware as boards are designed. We’ve put together a document that describes the mechanisms used in the system to allow a board developer to describe the features of a new board to the system and allow the system to use the new board without the need to modify any of the core hardware abstraction layer code or standard libraries.

The board variant mechanism makes use of a standardized folder structure and set of definition files that can be installed into the MPIDE system that adapt the system to work with new boards. In some cases, these files are distributed with the MPIDE, but board variant files can be easily added into an installation of MPIDE after it has been installed on the client computer.

In addition to the board variant mechanism described here, a developer designing a new board will also need to produce a boot loader for the board. Note that this document does not describe the process required to create a new custom boot loader from the boot loader project, as that process is described in a separate document.

To learn more, download the full guide here.

VN:F [1.9.22_1171]
Rating: 6.1/10 (8 votes cast)
VN:F [1.9.22_1171]
Rating: -2 (from 2 votes)
Mar 182013


In this project you will learn to use a basic functionality of chipKIT board, which is to use serial communication I2C bus to measure the room temperature and output the corresponding digital reading for it. I2C bus is a master slave bus, which communicates data from the processor on chipKIT board to other peripherals. More description on I2C communication can be found on the Wikipedia website.

Hardware Used:

The hardware used in this tutorial will be a chipKIT™ Uno32 along with a chipKIT™ Basic I/O Shield both manufactured by Digilent Inc.


The reference guide for each board, schematics and other resources are available on their individual homepages:


  1. Go to the chipKIT™ Basic I/O Shield homepage mentioned in the reference section. Download the zip file that contains libraries and documentation for using the Basic I/O Shield™ with the chipKIT MPIDE. Open the downloaded zip folder and copy the three IOShield folders in it. These three folders have the libraries and example programs for EEPROM, OLED and Temperature Sensor peripherals on IO shield.
  2. Now open the drive where you installed the mpide software, inside your mpide folder navigate through hardware > pic32 > libraries and paste the three IOShield folders in it.
  3. Close your mpide software, for the libraries to get included and the changes to take effect.
  4. On restarting the mpide software and navigating through File > Examples; you can find IOShieldEEPROM, IOShieldOled and IOShieldTemp folders with their demo examples being included.
  5. As an initial test, you can run the existing example code for temperature sensor peripheral of the IO Shield. To do this navigate through and open File > Examples > IOShieldOled > IOShield_Oled_Demo. 
  6. Once the new sketch is opened, click the Verify button and this will compile successfully unless the library file is not included properly.
  7. Make sure you connect the Uno32 board via the mini-B connector on board to an available port on your computer.
  8. Place the IO shield on top of the Uno32 board with a bit of a firm press.
  9. Once connected, in your MPIDE window, select Tools>Board>chipKIT UNO32 to identify the UNO32 Board as the target
  10. Next, select Tools>Serial Port>COMxx. This will depend on which port was assigned to the chipKIT UNO32 Board when first connected.
  11. To load your sketch onto the chipKIT UNO32 board’s Microcontroller, press the Upload button. This will compile your sketch (check for errors) and then send to the Microcontroller. Unless you type your own code in the sketch, you wouldn’t need to verify them before uploading.
  12. Once the code is done uploading, open the serial monitor from the toolbar and after a few seconds of delay the temperature will be displayed in Celsius and Fahrenheit as shown below, tempsensor1
  13. As a next step, the Organic LED present in the IO shield can be used to display the temperature.
  14. Make sure that the jumper settings for JP4 on chipKIT Uno32 board is configured as SPI Slave Select input mode. You can find the jumper settings in chipKIT Uno32 board reference manual from the Digilent website. Also, ensure that the jumpers JP6/JP8 are configured to be used as I2C communication lines.
  15. To make the temperature be displayed on OLED, create a new sketch, save it by giving a name and insert the code below in the sketch space.
    #include <IOShieldTemp.h>
    #include <IOShieldOled.h>
    #include <Wire.h>
    int tensc = 0;
    int onesc = 0;
    int dot_tensc = 0;
    int dot_onesc = 0;
    int tensf = 0;
    int onesf = 0;
    int dot_tensf = 0;
    int dot_onesf = 0;
    int tempC=0;
    int tempF=0;
    void setup()
    void loop() 
      float tempf, tempc;
      //Get Temperature in Celsius.
      tempc = IOShieldTemp.getTemp();
      // Convert the result to Fahrenheit.
      tempf = IOShieldTemp.convCtoF(tempc);
      //parse data for temperature in celcius
      dot_onesc = tempC%10;
      tempC = tempC/10;
      dot_tensc = tempC%10;
      tempC = tempC/10;
      onesc = tempC%10;
      tempC = tempC/10;
      tensc = tempC%10;
      //convert data to ASCII for temperature in celcius
       tensc = tensc+48;
       onesc = onesc+48;
       dot_tensc = dot_tensc+48;
       dot_onesc = dot_onesc+48;
      //parse data for temperature in Fahrenheit
      dot_onesf = tempF%10;
      tempF = tempF/10;
      dot_tensf = tempF%10;
      tempF = tempF/10;
      onesf = tempF%10;
      tempF = tempF/10;
      tensf = tempF%10;
      //convert data to ASCII for temperature in Fahrenheit
       tensf = tensf+48;
       onesf = onesf+48;
       dot_tensf = dot_tensf+48;
       dot_onesf = dot_onesf+48;
      //Clear the virtual buffer
      //Draw a rectangle over wrting then slide the rectagle
      //down slowly displaying all writing
        IOShieldOled.setCursor(0, 0);
        IOShieldOled.putString("Tempertaure is");
        IOShieldOled.setCursor(0, 2);
        IOShieldOled.setCursor(1, 2);
        IOShieldOled.setCursor(2, 2);
        IOShieldOled.setCursor(3, 2);
        IOShieldOled.setCursor(4, 2);
        IOShieldOled.setCursor(6, 2);
        IOShieldOled.putString(" Degrees C");
        IOShieldOled.setCursor(0, 3);
        IOShieldOled.setCursor(1, 3);
        IOShieldOled.setCursor(2, 3);
        IOShieldOled.setCursor(3, 3);
        IOShieldOled.setCursor(4, 3);
        IOShieldOled.setCursor(6, 3);
        IOShieldOled.putString(" Degrees F");
  16. In this code, the floating point values of temperature in celcius and fahrenheit are received, separated into digits by parsing the value and each digit is expressed in ASCII, aligning the position on OLED screen.
  17. To get more details on each function used with respect to OLED, open the IOShieldOLED folder which you downloaded from Digilent website and refer IOShield Library – Oeld.pdf. The same apply for functions for TEMP sensor too.
  18. To get the display, verify the code and upload it to the board. Once uploaded, you can see the temperature value displayed on OLED.
VN:F [1.9.22_1171]
Rating: 7.3/10 (3 votes cast)
Feb 162013

Running on Microchip Starter Kits

MPIDE has been expanded explicitly to support all of the Microchip starter kits such as:
  • PIC32 Starter Kit
  • PIC32 USB Starter Kit
  • PIC32 Ethernet Starter Kit
  • Explorer 16 Starter Kit
Currently for all of these boards you will need some sort of USB to serial adapter. For all but the Exp-16 I use an FTDI cable that breaks out to pins. I connect those to pins on the expansion board for uart1. The PIC32 USB Starter Kit and PIC32 Ethernet Starter Kits are also compatible with the USB PIC32 bootloader. The Explorer-16 has an on-board DB-9 RS-232 connector. This is connected to UART2. The bootloader is configured to use UART2 for the Explorer-16 and the Serial ports for Arduino are remapped so that Serial.print goes to uart2 and Serial1.print goes to uart1. This is all done automatically so the user does not have to worry about it at all. In order to install the bootloader on any of these boards, you have to have one of the Microchip compatible programmers such as the MPLAB ICD 3 or PICkit 3. Ideally you should download MPLAB X IDE from microchip ( and use that to compile and burn the bootloader. The bootloader source and pre-compiled hex files are all on github. (

Using other PIC32 boards

As far as using MPIDE with other boards, the answer is YES, it should work with ANY PIC32 there is. The only limit might be it won’t work on chips smaller than 32K, And that’s because it hasn’t been tried on anything smaller. To get it to work on other boards, a few things have be be done.
  • First, the bootloader has to be burned onto the target board. The source is on github and MPLAB is used to compile and burn the bootloader. The multi-platform MPLAB-X was used on a Mac, but other versions should work as well.
  • If you using a chip that has not already been added to avrdude.conf, that has to be done.
  • You need to add a new entry to boards.txt and then you will be able to program the board directly from MPIDE.
VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Using USB

 Bootloaders and Connectivity  Comments Off on Using USB
Feb 162013
The PIC32MX3xx series parts do not have a USB controller. The other PIC32 series (i.e. PIC32MX4xx/5xx/6xx/7xx) all have a USB controller. The Uno32 uses a PIC32MX320F128H and therefore does not have a USB controller. The Uno32 and Max32 have standard FTDI serial to USB interface chips (FT232R) to keep consistent with the Arduino way of interfacing. However, it is also nice to be able to use the built in USB port. Many other PIC32 boards have this USB port brought out to a standard connector such as the Microchip USB Starter Kit and the Digilent Cerebot 32MX4 and Cerebot 32MX7. The latest version of HardwareSerial.cpp now supports the first serial port (Serial.begin(), Serial.print() etc) can be reconfigured to use the USB port instead. In order to take full advantage of this, first you have to program the board with the USB bootloader, then use the appropriate board setting in the BOARDS menu. If you are using a custom board in the boards file you can just add the following to your board description: custom_pic32.compiler.define=-D_USE_USB_FOR_SERIAL_ When using the USB for Serial, UART1 becomes Serial0 Serial1 etc, are still there normal configurations Serial.begin(baudrate); //The baudrate is ignored, when doing real USB, there is no baudrate. Receive is interrupt driven and behaves EXACTLY like regular Serial. NO CODE CHANGES REQUIRED. If you want to see how this is done, look at HardwareSerial.h and HardwareSerial.cpp, the actual usb code is in HardwareSerial_cdcacm.c and HardwareSerial_usb.c. The USB code was written by Rich T ( More documentation will be provided on how to do this soon. (Created 7/3/2011)
VN:F [1.9.22_1171]
Rating: 9.0/10 (1 vote cast)
VN:F [1.9.22_1171]
Rating: +1 (from 1 vote)
Feb 162013
Header files listed in alphabetical order. Files are denoted as either (AVR) or (PIC32) specific, if they apply to both platforms they are marked as (AVR|PIC32). For headers that are marked (AVR|PIC32) they can be either “generic” or “ported”. Generic files will work on either platform without modification where ported files are different for AVR or PIC32.

avr/interrupt.h (AVR)

avr/io.h (AVR)

avr/progmem.h (AVR)

avr/pgmspace.h (AVR)

Tools to access program space of the AVR processor, not needed on PIC32, but some macros can be used in its place to make AVR code run on a PIC32. <source>
  1. if defined(__PIC32MX__)
   // neither PROGMEM or PSTR are needed for PIC32, just define them as null
   #define PROGMEM
   #define PSTR(s) (s)
   #define pgm_read_byte(x)	        (*((char *)x))
   #define pgm_read_byte_near(x)	(*((char *)x))
   #define pgm_read_byte_far(x)	(*((char *)x))
   #define pgm_read_word(x)    	(*((short *)x))
   #define pgm_read_word_near(x)	(*((short *)x))
   #define pgm_read_workd_far(x)	(*((short *)x))

   #define	prog_void	 const void
   #define	prog_char	 const char
   #define	prog_uchar	 const unsigned char
   #define	prog_int8_t	 const int8_t
   #define	prog_uint8_t	const uint8_t
   #define	prog_int16_t	const int16_t
   #define	prog_uint16_t	const uint16_t
   #define	prog_int32_t	const int32_t
   #define	prog_uint32_t	const uint32_t
   #define	prog_int64_t	const int64_t
   #define	prog_uint64_t	const uint64_t
  1. else
  2. include <avr/pgmspace.h>
  3. endif


The start of all good programming sessions.





plib.h (PIC32)

Contains type definitions for PIC32 registers.


Servo.h (?)

SPI.h (AVR|PIC32) ported

Library to provide SPI communications.

stdint.h (AVR|PIC32) ported


wire.h (?)

wiring.h (?)

WProgram.h (?)

VN:F [1.9.22_1171]
Rating: 7.0/10 (3 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)
Feb 162013
This is a dump of the interrupt vector from the Max32 (32MX795F512L) It gives you an idea what is available and what is already in use.
Arduino-32MX795F512L>V show interrupt Vectors
EBASE          =9D000000
IntCtl         =00000020
VectorSpacing  =00000001
+++ 0= 02 00---0B4017F0 jump 9D005FC0  _CORE_TIMER_VECTOR
+++ 1= 00 00---FFFFFFFF unused         _CORE_SOFTWARE_0_VECTOR
+++ 2= 00 00---FFFFFFFF unused         _CORE_SOFTWARE_1_VECTOR
+++ 3= 00 00---FFFFFFFF unused         _EXTERNAL_0_VECTOR
+++ 4= 00 00---0B401E5A jump 9D007968  _TIMER_1_VECTOR
+++ 5= 00 00---FFFFFFFF unused         _INPUT_CAPTURE_1_VECTOR
+++ 6= 00 00---FFFFFFFF unused         _OUTPUT_COMPARE_1_VECTOR
+++ 7= 00 00---FFFFFFFF unused         _EXTERNAL_1_VECTOR
+++ 8= 00 00---FFFFFFFF unused         _TIMER_2_VECTOR
+++ 9= 00 00---FFFFFFFF unused         _INPUT_CAPTURE_2_VECTOR
+++10= 00 00---FFFFFFFF unused         _OUTPUT_COMPARE_2_VECTOR
+++11= 00 00---FFFFFFFF unused         _EXTERNAL_2_VECTOR
+++12= 00 00---FFFFFFFF unused         _TIMER_3_VECTOR
+++13= 00 00---FFFFFFFF unused         _INPUT_CAPTURE_3_VECTOR
+++14= 00 00---FFFFFFFF unused         _OUTPUT_COMPARE_3_VECTOR
+++15= 00 00---FFFFFFFF unused         _EXTERNAL_3_VECTOR
+++16= 00 00---FFFFFFFF unused         _TIMER_4_VECTOR
+++17= 00 00---FFFFFFFF unused         _INPUT_CAPTURE_4_VECTOR
+++18= 00 00---FFFFFFFF unused         _OUTPUT_COMPARE_4_VECTOR
+++19= 00 00---FFFFFFFF unused         _EXTERNAL_4_VECTOR
+++20= 00 00---FFFFFFFF unused         _TIMER_5_VECTOR
+++21= 00 00---FFFFFFFF unused         _INPUT_CAPTURE_5_VECTOR
+++22= 00 00---FFFFFFFF unused         _OUTPUT_COMPARE_5_VECTOR
+++23= 00 00---FFFFFFFF unused         _SPI_1_VECTOR
+++24= 00 00---0B401B67 jump 9D006D9C  _I2C_3_VECTOR _UART_1A_VECTOR _UART_1_VECTOR _SPI_1A_VECTOR _I2C_1A_VECTOR _SPI_3_VECTOR
+++25= 01 00---FFFFFFFF unused         _I2C_1_VECTOR
+++26= 00 00---FFFFFFFF unused         _CHANGE_NOTICE_VECTOR
+++27= 01 00---FFFFFFFF unused         _ADC_VECTOR
+++28= 00 00---FFFFFFFF unused         _PMP_VECTOR
+++29= 00 00---FFFFFFFF unused         _COMPARATOR_1_VECTOR
+++30= 00 00---FFFFFFFF unused         _COMPARATOR_2_VECTOR
+++31= 00 00---0B401BDD jump 9D006F74  _UART_2A_VECTOR _I2C_2A_VECTOR _SPI_2_VECTOR _SPI_2A_VECTOR _I2C_4_VECTOR _UART_3_VECTOR
+++32= 00 00---0B401C53 jump 9D00714C  _UART_2_VECTOR _SPI_3A_VECTOR _I2C_3A_VECTOR _UART_3A_VECTOR _SPI_4_VECTOR _I2C_5_VECTOR
+++33= 00 00---FFFFFFFF unused         _I2C_2_VECTOR
+++34= 00 00---FFFFFFFF unused         _FAIL_SAFE_MONITOR_VECTOR
+++35= 01 00---FFFFFFFF unused         _RTCC_VECTOR
===36= 00 00---FFFFFFFF unused         _DMA_0_VECTOR
===37= 00 00---FFFFFFFF unused         _DMA_1_VECTOR
===38= 00 00---FFFFFFFF unused         _DMA_2_VECTOR
===39= 00 00---FFFFFFFF unused         _DMA_3_VECTOR
===40= 00 00---FFFFFFFF unused         _DMA_4_VECTOR
===41= 00 00---FFFFFFFF unused         _DMA_5_VECTOR
===42= 00 00---FFFFFFFF unused         _DMA_6_VECTOR
===43= 00 00---FFFFFFFF unused         _DMA_7_VECTOR
===44= 00 00---FFFFFFFF unused         _FCE_VECTOR
===45= 00 00---FFFFFFFF unused         _USB_1_VECTOR
===46= 00 00---FFFFFFFF unused         _CAN_1_VECTOR
===47= 00 00---FFFFFFFF unused         _CAN_2_VECTOR
===48= 00 00---FFFFFFFF unused         _ETH_VECTOR
===49= 00 00---0B401BA2 jump 9D006E88  _UART_4_VECTOR _UART_1B_VECTOR
===50= 00 00---0B401C18 jump 9D007060  _UART_6_VECTOR _UART_2B_VECTOR
===51= 00 00---0B401C8E jump 9D007238  _UART_5_VECTOR _UART_3B_VECTOR
VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

The MPIDE Compiler for PIC32

 MPIDE Under the Hood  Comments Off on The MPIDE Compiler for PIC32
Feb 162013
This is a fork of the compiler from about October 2010. So it’s ahead of the Microchip MPLAB C32 v1.12 release, but behind the upcoming C32 v2.00 release. Basically it’s similar to C32 v1.12, but updated to GCC 4.5.1. Also, the default linker scripts are modified to work with the chipKIT bootloader. There are no optimization restrictions in this build, but it will likely be updated less often than the official MPLAB C32 compiler. Source code:

MPIDE Compiler optimisation

Currently, MPIDE is configured to call the compiler with the -O2 optimization option. The -O2 set of optimization usually results in a nice balance between code size and speed. However, there are some instances where you want to sacrifice code size (use more FLASH memory) in order to get more speed. Luckily, Rick has introduced features in MPIDE that makes changing the default compiler options easy to change. To change the optimization level:
1. Open the /hardware/pic32/platforms.txt file in your favorite text editor.
2. Find the lines beginning with pic32.compiler.c.flags and pic32.compiler.cpp.flags. 
   In those lines, you should see a compiler optimization option, -O0, -O1, -O2, -Os, or -O3.
3. Change the optimization level option to the desired level, as listed below.
4. Save platforms.txt
5. Restart MPIDE.
Optimization levels
-O0 - Disable optimizations
-O1 - Reduce code size and execution time, without performing any optimizations that take a 
      great deal of compilation time.
-O2 - Optimize even more. GCC performs nearly all supported optimizations that do not involve a 
      space-speed trade-off. As compared to -O1, this option increases both compilation time and 
      the performance of the generated code. (This is currently the default.)
-O3 - Optimize yet more. GCC optimizes for maximum performance at the expense of code size.
-Os - Optimize for size. -Os enables all -O2 optimizations that do not typically increase code size.
It also performs further optimizations designed to reduce code size. For example:
If you really want aggressive performance for your sketch, you could also add the -funroll-loops option. Note that this option almost always increases code size but it may or may not increase performance. For example:
VN:F [1.9.22_1171]
Rating: 7.0/10 (1 vote cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Overview of the Build Process

 MPIDE Under the Hood  Comments Off on Overview of the Build Process
Feb 162013
This is in response to questions about the build process You are asking very reasonable questions however, this stuff is specifically hidden to make the entire system easy for the beginner. You state your are a beginner so I would recommend ignoring these details to start with. HOWEVER, to answer your questions: The build process in MPIDE is the same as it is for the original Arduino system. It compiles all of the files in the core/xxx folder, xxx is specified in boards.txt. Normally there is only one and for PIC32, it’s cores/pic32. It also will compile files from the 2 libraries folders. The 2 locations for libraries are the main one in pic32/libraries, this is where officially supported libraries go. There is a second optional libraries folder in your sketches folder. This is where you are supposed to put any libraries that you download from 3rd parties. The reason behind that is if you download a new version of MPIDE (or Arduino) you wont lose those 3rd party libraries as happened in earlier versions of Arduino. It copies all files from your sketch folder, the library folders to a temp folder. You can follow this entire process by holding down the SHIFT key and clicking on COMPILE (the button on the far left). Similarly you can hold down the shift button when you click UPLOAD and you will see the entire UPLOAD process. ONE IMPORTANT NOTE… HITTING UPLOAD ALSO COMPILES SO YOU DO NOT NEED TO DO BOTH. The compile process uses gcc from a command line. What was done different in MPIDE is the code to drive the compiler was totally re-written and is driven by a file called platforms.txt which spells out the entire compile and link process. In Arduino this was hard coded and darn near impossible to change
VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)