Picade board documentation?


#1

Where do I find documentation on the Picade board? I purchased a Picade board from Adafruit and it works but I need to reprogram the buttons as the defaults do not work with all games.


#2

Documentation is admittedly a little thin on the ground at the moment, but the full source for the firmware Sketch is available here and the portions you’ll need to edit are commented: https://github.com/pimoroni/picade-sketch

See in particular the main sketch file: https://github.com/pimoroni/Picade-Sketch/blob/master/Picade/Picade.ino


#3

I downloaded the Picade source from gethub https://github.com/pimoroni/picade-sketch

When I load the sketch and verify it I get a bunch of errors about variables not declared and libraries missing.

This is supposed to be the sketch currently running in the Picade.

How do I fix this? I just want to change a couple buttons.

[code]#include “picade.h”
#include “TimerOne.h”
#include <EEPROM.h>

/* Comment out this line if you want to bind the volume buttons to keys */
#define ENABLE_VOLUME_BUTTONS

/* Change this to tweak your button debounce delay. Generally the lower you can

  • get it without seeing any unwanted repeat button presses, the better.
    */
    #define DEBOUNCE_DELAY 25

/* Change key bindings below */
static input inputs[] = {
{ KEY_UP_ARROW, UP },
{ KEY_DOWN_ARROW, DOWN },
{ KEY_LEFT_ARROW, LEFT },
{ KEY_RIGHT_ARROW, RIGHT },

{ KEY_LEFT_CTRL, BTN_1 },
{ KEY_LEFT_ALT, BTN_2 },
{ ’ ', BTN_3 },
{ KEY_LEFT_SHIFT, BTN_4 },
{ ‘z’, BTN_5 },
{ ‘x’, BTN_6 },

{ ‘s’, START },
{ ‘c’, COIN },
{ KEY_RETURN, ENTER },
{ KEY_ESC, ESCAPE },

#ifndef ENABLE_VOLUME_BUTTONS
/* Change these lines to set key bindings for VOL_UP and VOL_DN */
{ ‘u’, VOL_UP },
{ ‘d’, VOL_DN },
#endif
};

/* You can ignore everything from this point onwards… */

void setup() {

//Serial.begin(9600);

for(int i = 0; i < sizeof(inputs) / sizeof(input); i++){
pinMode(inputs[i].pin, INPUT_PULLUP);
}
pinMode(BLINK_LED, OUTPUT);

pinMode(HEADPHONE_DETECT, INPUT);

#ifdef ENABLE_VOLUME_BUTTONS
pinMode(VOL_UP, INPUT_PULLUP);
pinMode(VOL_DN, INPUT_PULLUP);
#endif

pinMode(AMP_UP, OUTPUT);
digitalWrite(AMP_UP, HIGH);
pinMode(AMP_DN, OUTPUT);
digitalWrite(AMP_DN, HIGH);

#ifdef ENABLE_VOLUME_BUTTONS
load_volume_from_eeprom();
#endif

#ifndef ENABLE_VOLUME_BUTTONS
volume_target = 31;
#endif

Timer1.initialize(5000);
Timer1.attachInterrupt(update);
Timer1.start();
}

void update(void){
// loop through each input
for(int i = 0; i < sizeof(inputs) / sizeof(input); i++)
{
// test for current state of this input
boolean state = !digitalRead(inputs[i].pin);

if(state != inputs[i].state && (millis() - inputs[i].last_change) > DEBOUNCE_DELAY) // has this input changed state since the last time we checked?
{
  inputs[i].state = state; // update our state map so we know what's happening with this key in future
  inputs[i].last_change = millis();
  // send the key press or release event
  if(state){ Keyboard.press(inputs[i].key);}else{Keyboard.release(inputs[i].key);}
}

}
}

void loop() {

#ifdef ENABLE_VOLUME_BUTTONS
/*

  • Read the current states of the Volume Up, Volume Down and Headphone Detect inputs
    */
    boolean vol_up = !digitalRead(VOL_UP);
    boolean vol_dn = !digitalRead(VOL_DN);
    boolean headphone = !digitalRead(HEADPHONE_DETECT);

/*

  • If headphones are unpugged/plugged in then adjust the volume accordingly.
  • Save the target volume and set it to 0 to fade out.
  • Load the saved value into the target volume to fade back in.
    */
    if(headphone != last_headphone){
    last_headphone = headphone;
    if(headphone){
    volume_target_save();
    volume_target = 0;
    }
    else
    {
    volume_target_load();
    }
    }

if( vol_up != last_vol_up || (millis() - last_vol_up_time) > 100 ){
if( vol_up && volume_target < 31 ){
volume_target++;
last_vol_up_time = millis();
}
last_vol_up = vol_up;
}

if( vol_dn != last_vol_dn || (millis() - last_vol_dn_time) > 100 ){
if( vol_dn && volume_target > 0 ){
volume_target–;
last_vol_dn_time = millis();
}
last_vol_dn = vol_dn;
}

if(volume_target > volume_current){
volume_up();
}

if(volume_target < volume_current){
volume_down();
}

/* If we’ve reached the target volume, save it to EEPROM and blink the notification LED */
if(!headphone && volume_current == volume_target && volume_eeprom != volume_current && (millis() - last_vol_up_time) > 1000 && (millis() - last_vol_dn_time) > 1000){
EEPROM.write(0, volume_current);
volume_eeprom = volume_current;
int x = 2;
while(x–){
digitalWrite(BLINK_LED, HIGH);
delay(50);
digitalWrite(BLINK_LED, LOW);
delay(50);
}
}
#endif

}[/code]

Arduino: 1.6.6 (Windows 7), Board: “Arduino Leonardo”

Build options changed, rebuilding all
Picade:15: error: ‘KEY_UP_ARROW’ was not declared in this scope

{ KEY_UP_ARROW, UP },

 ^

Picade:16: error: ‘KEY_DOWN_ARROW’ was not declared in this scope

{ KEY_DOWN_ARROW, DOWN },

 ^

Picade:17: error: ‘KEY_LEFT_ARROW’ was not declared in this scope

{ KEY_LEFT_ARROW, LEFT },

 ^

Picade:18: error: ‘KEY_RIGHT_ARROW’ was not declared in this scope

{ KEY_RIGHT_ARROW, RIGHT },

 ^

Picade:20: error: ‘KEY_LEFT_CTRL’ was not declared in this scope

{ KEY_LEFT_CTRL, BTN_1 },

 ^

Picade:21: error: ‘KEY_LEFT_ALT’ was not declared in this scope

{ KEY_LEFT_ALT, BTN_2 },

 ^

Picade:23: error: ‘KEY_LEFT_SHIFT’ was not declared in this scope

{ KEY_LEFT_SHIFT, BTN_4 },

 ^

Picade:29: error: ‘KEY_RETURN’ was not declared in this scope

{ KEY_RETURN, ENTER },

 ^

Picade:30: error: ‘KEY_ESC’ was not declared in this scope

{ KEY_ESC, ESCAPE },

 ^

C:\Users\Bob\Documents\Arduino\Picade\Picade.ino: In function ‘void update()’:

Picade:87: error: ‘Keyboard’ not found. Does your sketch include the line ‘#include <Keyboard.h>’?
if(state){ Keyboard.press(inputs[i].key);}else{Keyboard.release(inputs[i].key);}

              ^

Picade:87: error: ‘Keyboard’ not found. Does your sketch include the line ‘#include <Keyboard.h>’?
if(state){ Keyboard.press(inputs[i].key);}else{Keyboard.release(inputs[i].key);}

                                                  ^

exit status 1
’KEY_UP_ARROW’ was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.


#4

Did you download the complete GitHub repository or just the single sketch file? The sketch depends upon the files listed in the include directives at the top: “picade.h” and “TimerOne.h”. Without these, compilation will simply break.

A Sketch in Arduino is defined as the folder that contains the .ino file and not just the file itself so that any extra files can be neatly contained. This is why the Arduino IDE is really particular about moving your ino into a subfolder named after the ino.

Anyway, I’m waffling; you need to:

  1. Go to https://github.com/pimoroni/picade-sketch
  2. Click “Download Zip” on the right hand side
  3. Unzip this file
  4. Navigate into the “Picade” folder and open “Picade.ino”

Now it should build!


#5

Yes I downloaded the complete package and followed the exact steps to open Picade.ino

Go to https://github.com/pimoroni/picade-sketch
Click "Download Zip" on the right hand side
Unzip this file
Navigate into the "Picade" folder and open "Picade.ino"

When I open Picade,ino I can see that TimerOne.cpp, TimerOne.h, known_16bit_timers.h, and picade.h are also opened in other tabs in the Arduino IDE

Still unable to compile


#6

Weird. The Arduino IDE is a complete and total mess, so I’m not surprised it broke at least somewhere.

Could you possibly provide some details of the errors it produces, and the version of the Arduino IDE you’re using?


#7

Here’s the error messages with all the extra taken out. IDE version 1.66

Arduino: 1.6.6 (Windows 7), Board: “Arduino Leonardo”

Build options changed, rebuilding all
Picade:15: error: ‘KEY_UP_ARROW’ was not declared in this scope
Picade:16: error: ‘KEY_DOWN_ARROW’ was not declared in this scope
Picade:17: error: ‘KEY_LEFT_ARROW’ was not declared in this scope
Picade:18: error: ‘KEY_RIGHT_ARROW’ was not declared in this scope
Picade:20: error: ‘KEY_LEFT_CTRL’ was not declared in this scope
Picade:21: error: ‘KEY_LEFT_ALT’ was not declared in this scope
Picade:23: error: ‘KEY_LEFT_SHIFT’ was not declared in this scope
Picade:29: error: ‘KEY_RETURN’ was not declared in this scope
Picade:30: error: ‘KEY_ESC’ was not declared in this scope
C:\Users\Bob\Documents\Arduino\Picade\Picade.ino: In function ‘void update()’:
Picade:87: error: ‘Keyboard’ not found. Does your sketch include the line ‘#include <Keyboard.h>’?
if(state){ Keyboard.press(inputs[i].key);}else{Keyboard.release(inputs[i].key);}
Picade:87: error: ‘Keyboard’ not found. Does your sketch include the line ‘#include <Keyboard.h>’?
if(state){ Keyboard.press(inputs[i].key);}else{Keyboard.release(inputs[i].key);}
exit status 1

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.


#8

I have tired this on more than one computer with the same results.

What am I doing wrong?


#9

Have you tried selecting the board type in the menus?

Tools -> Board -> Arduino Leonardo

The Uno ( the default selection ) doesn’t have the keyboard libraries.

Sorry that you’re pushing the boundaries of our documentation, I’ll make sure to get this written up for future tinkerers!


#10

Yes the board type is set to Leonardo


#11

Sorry, my reading comprehension evidently isn’t great!


#12

Found a moment to install Arduino 1.6.6, it would appear that a manual include of “Keyboard.h” is now required, rather than the previous automatic inclusion. I’ve no idea when this happened, but it’s an easy fix.

The IDE even suggests it in the error output:

Picade:88: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?

So, just add:

#include <Keyboard.h>

And now it compiles for me!


#13

Oh, well look at at that, it compiles without error

Thanks!


#14

It’s always something ridiculously simple! On to the next challenge, eh?