Electronza
  • Homepage
  • Privacy
    • Privacy Policy
  • Contact
Electronza
  • Homepage
  • Privacy
    • Privacy Policy
  • Contact
Electronza
You are at:Home»Electronics projects»PIC32 projects»Clicker2 for PIC32MX: Programming in Arduino
Clicker2-for-PIC32MX-featured
Clicker2-for-PIC32MX-featured

Clicker2 for PIC32MX: Programming in Arduino

0
By Electronza on August 31, 2015 PIC32 projects, Tutorials

The popularity of Arduino IDE is undisputable. This success was a great incentive for many other Arduino IDE clones. Introduced in 2011 by Microchip and Digilent and complemented by the initial release of two Arduino compatible PIC32 boards, MPIDE is a fork of the original Arduino 0023 IDE, with support for PIC32 microcontrollers. Since then MPIDE evolved to the current mpide-0150-20150812 release, and also the range of supported boards increased.

Most of the MPIDE-compatible boards used USB-to-serial FTDI chips, similar to the Arduino boards. The latest series of MPIDE bootloaders allows for direct USB connectivity, and an increased number of development boards are now able to run MPIDE. Such example is the Clicker2 for PIC32MX from MikroElektronika.If we take a look at the Clicker2 for PIC32MX, we find it’s very close to the Cerebot 32MX4ck board, later renamed as Diligent chipKIT Pro MX4 board. The only major difference is that the original chipKIT board uses a FDTI USB-to-serial, while the Clicker2 has a native USB connection. Unfortunately, the bootloader that comes with the Clicker2 for PIC32MX is not compatible with the MPIDE.

So, to make this board run in MPIDE one must replace the original bootloader with the chipKIT version.Here we are lucky: there is a USB compatible bootloader available for download. So, all we have to do is to download and extract the zip file, go to BootloadersCurrent-hex and pick the Cerebot-32MX4-USB.hex file. Use a PICkit 3 or similar programmer to burn the new bootloader.

At this moment when you connect the board to the PC it’s detected as Stk500v2. Of course, you need drivers for this. For WIN7 I found the following download link for the drivers.

Compatibility with Arduino IDE

Now comes the really funny part: what does work and what doesn’t. The first thing is to find the correspondence between Arduino pin definitions and the actual pins on the Clicker 2 for PIC32MX. Here’s what I found to be working:

With the above notations most Arduino code will run on the Clicker2 for PIC32MX. Don’t forget to set the board as “chipKIT Pro MX4” in MPIDE.

The only thing I couldn’t make work is the serialprint function, which tries to use the hardware serial port, and not the USB connection. Some care is also needed when using third-party Arduino libraries as some of those libraries are written using 8-bit Atmel C code and will not work with PIC32’s.

Another issue I found is that the board needs a hardware reset to reestablish the communication with the PC. So, every time when you wish to reprogram the board you need to press the reset button before uploading the sketch.

I also found that a LED connected to microcontroller pin RB10 (Arduino pin 64) can be used to provide some diagnostics in bootloader mode.

A simple MPIDE sketch

The following code is a modified example from MPIDE that turns off LED2 if Button #1 is pressed:

/*
 Turns on and off a light emitting diode(LED) connected to digital
 pin 13, when pressing a pushbutton attached to pin 4.

 This example code is in the public domain.
 Based on the original code
 http://www.arduino.cc/en/Tutorial/Button
 */

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 4;     // the number of the pushbutton pin
const int ledPin =  69;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}

Programming is very much the same as in Arduino IDE. For the board I selected “chipKIT Pro MX4”, then I pressed the reset button before uploading. All went smooth, and the code was running just as it would do on any Arduino board.

Some final thoughts

Does it worth all this hassle to change the bootloader? I think so, as I can benefit from a free IDE, and of all the available Arduino code.

Are there downsides? Yes!

The major downside is that when the power is turned off or the reset button is pressed the loaded program is lost. The board just gets into Stk500v2 mode, and waits for a new program to be loaded. I’m not sure is this is the intended behavior, or it’s a flaw in the code. I’m still investigating this issue…

Second, there is no debugger. Besides, some things don’t work for the moment (particularly I miss the serialprint, which is widely used for debugging). Maybe I will try using another serial-to-USB board to see if I can do some limited debugging using the native serial communication.

Update: I found a way to make it work using another bootloader and a USB-UART click.

 

Arduino chipKIT Bootloader MPIDE MIKROE-1717 410-295P-KIT Clicker2 for PIC32MX Compilers
Share. Facebook Twitter Pinterest LinkedIn Tumblr Email

Related Posts

Some software services that make my life easier

SPEC Digital H2S sensor

SPEC DGS sensors: new firmware, new behaviour

Honeywell HPMA115S0-XXX particle sensor

A new code library for HPMA115S0 particle sensor

Leave A Reply Cancel Reply

Latest posts
January 15, 2023

A pretty text box for Blogger posts

January 15, 2023

New blog section: beginners’ corner

January 15, 2023

Cleaning unused images from blogs hosted on Blogger

Categories
  • Beginners' corner
  • Electronics projects
    • ESP8266
    • Arduino projects
    • IoT
    • 8-bit PIC projects
    • Raspberry PI
    • PIC32 projects
    • Robots
  • Arduino libraries
  • Reviews
    • Tools & equipment
    • Development boards
    • IoT
    • Industrial Arduino
  • Blogger / Blogspot
  • Tutorials
  • Casual stuff
Popular posts
Arduino Uno 4-20mA communication using 4-20mA R click and 4-20mA T click boards from MikroElektronika: MIKROE-1296, MIKROE-1387, Uno Click Shield
August 17, 2016

4-20mA current loop Arduino tutorial Part I: hardware

ESP8266 Thing Dev from Sparkfun
May 15, 2019

ESP8266 – running on battery power

ECG click on Arduino Uno
December 5, 2016

ECG click: Arduino IDE code examples

WiFi3 Click - esp8266 in click board format
March 15, 2017

ESP8266: AT mode webserver tutorial

Honeywell HPMA115S0-XXX particle sensor
November 23, 2017

Arduino: measuring PM2.5 and PM10 with Honeywell HPMA115S0

Copyright © 2023 Teodor Costachioiu

Type above and press Enter to search. Press Esc to cancel.