Due Only Works as HID After Reset - How to fix GPNVM?

Hi Guys,

Im trying to make the Adruino Due work as a multi button joystick with a few functions which I have managed to program such that 2 physical buttons operate 3 joystick buttons.

All this works fine on the Leonardo and the Due - BUT - the Due does not stay in the Joystick state after unplugging and re-plugging.

Only after a reset on the board after it has been plugged back in does it operate as the way I want it to.

I have done some research and found that this is due to the GPNVM and have looked at this:


however it does not tell me how to modify the code so that it always stay as the device I am looking to create. (I am completely new to all of this).

Here is the basic part of the coding which I want to use to get the functions as I want. If anyone can help me to get the code to maintain the joystick as a joystick OR point me in the right direction it will be much appreciated.

#include <Keyboard.h>

#include <Encoder.h>

#include <Joystick.h>

Encoder myEnc(2, 3); 

void setup() {
  // Initialize Button Pins
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  pinMode(10, INPUT_PULLUP);
  pinMode(11, INPUT_PULLUP);
  pinMode(12, INPUT_PULLUP);
  pinMode(13, INPUT_PULLUP);

  Serial.println("Basic Encoder Test:");
  // Initialize Joystick Library

long oldPosition  = -999;

void loop() {

  long newPosition = myEnc.read()/4;
  if (newPosition != oldPosition) {
    oldPosition = newPosition;

  // Read pin values
  int button3Val =digitalRead(4);
  int button4Val =digitalRead(5);
  int button6Val =digitalRead(6);
  int button7Val =digitalRead(7);
  int button9Val =digitalRead(8);
  int button10Val =digitalRead(9);
  int button12Val =digitalRead(10);
  int button13Val =digitalRead(11);
  int button15Val =digitalRead(12);
  int button16Val =digitalRead(13);
  Joystick.setButton(6, !button6Val);
  Joystick.setButton(7, !button7Val);

  if ((button6Val == 0) || (button7Val == 0)) {
    Joystick.setButton(8, 0);
  } else {
    Joystick.setButton(8, 1);
  Joystick.setButton(9, !button9Val);
  Joystick.setButton(10, !button10Val);

  if ((button9Val == 0) || (button10Val == 0)) {
    Joystick.setButton(11, 0);
  } else {
    Joystick.setButton(11, 1);  
  Joystick.setButton(12, !button12Val);
  Joystick.setButton(13, !button13Val);

  if ((button12Val == 0) || (button13Val == 0)) {
    Joystick.setButton(14, 0);
  } else {
    Joystick.setButton(14, 1);
  Joystick.setButton(15, !button15Val);
  Joystick.setButton(16, !button16Val);

  if ((button15Val == 0) || (button16Val == 0)) {
    Joystick.setButton(17, 0);
  } else {
    Joystick.setButton(17, 1);
  // Joysticx axis

  int xaxis = A0;
  int val = 0;
  val = analogRead(xaxis)>>2;




I don't see how your problem is related to the GPNVM bits. There are three bits there:

0 - General security bit. If this is set then FLASH memory cannot be read by anything external to the processor. Basically, this is a a copy protection bit.

1 - Boot source selector. Off = Boot from ROM based bootloader On = Boot from FLASH memory

2 - Flash page selector - Flash on the Due is in two 256k pages. Normally you boot from page 0. On = Boot from page 1.

How would any of those bits change on you? Pushing the reset button does nothing to these bits. Pushing the ERASE button causes them all to switch to "off".

It sounds like your problem has more to do with some sort of start up issue. I think I've heard of other people having an issue where they need to push reset to make it work. Maybe search the forum for such messages and see what other people did to fix it.

Hi, I have several due’s which wont do anything after being unplugged. After a bit of searching, I found that you need to solder a capacitor across the reset switch. See attached photo. I used these - 20 x TAJA106M010R - Tantalum Capacitor, 10uF, 10V, 20% , SMD 1206

I got 20 off eBay for £2

No more problemos