| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Up and running on the ButtonShield (and ButtonPad)

Page history last edited by sarith.ong@liquidware.com 11 years, 6 months ago
Step 1: Get the IDE
 
The Antipasto Arduino branch of the Arduino IDE has the ButtonShield hardware libraries baked in, and it's available for Mac, Windows, and Linux over at the "App Store".
 

 

Here's the Windows version
Here's the Mac version
Here's the Linux version

 

 

 

Step 2: Install the IDE

 

Launch the installer (after Firefox checks to make sure there aren't any viruses or spamware, which there aren't but just in case). And just save to the default location (please) because the installer's technically not that smart, and likes to just be saved to the default specified place.

 
 

 

Step 3: Launch the Antipasto Arduino IDE
(For Windows users, the Antipasto Arduino IDE installs into the main Start menu.) When the IDE launches, it show a tab that's sticking out on the left. That's the "Gadget Module" selector tab, which allows me to pick which modules I'm writing code for.

 
 

 

Step 4: Create a New Gadget
Go to File->New Gadget to create a new "Gadget file". A Gadget file is a meta-file format that Omar developed that allows anyone to store multiple source code files compiled for different module architectures. That way, a single Gadget file can contain source code for a TouchShield, Arduino, ButtonShield, etc.

You can name the gadget file anything you want, I usually just call it "test" or "default" or "hello", but there are definitely more creative names out there.

 


Step 5: Add the Arduino you have by clicking the Plus Sign in the Gadget Window

Like this: 

 

 


 
This sets all the source code you need in order to program the Arduino. It also pops up a standard template program including loop() and setup().  

 

Step 6: Copy and paste the Hello World ButtonShield Code
Copy and paste this code into the Antipasto Arduino IDE window, replacing and overwriting anything that was already there:

 

 

#include

/* Setup for Mode A */
ButtonShield buttons = ButtonShield(0);

void setup() {

Serial.begin(9600);

}

void loop() {

Serial.println(buttons.readButtons());
}

 

 

This code includes the ButtonShield header which includes all the communication primitives you need. Then it defines a variable, ButtonShield buttons, so that you can use the variable buttons anywhere else in the code. Of course Serial.begin sets up a serial communication between the Arduino and the computer. And the piece-de-resistance (haw haw hawww in French) is: Serial.println(buttons.readButtons()). Really that's just trying to be clever on one line. First it's calling:

 

 

buttons.readButtons()

 

which is the magic function. It will read whatever is being pressed on the ButtonShield keyboard at the current time. Then, it encases it in:

 

 

Serial.println()

 
which is the function that sends the number back up to the computer to be displayed.  

 

 

 

Step 7: Compile the Code
Press the run button, to compile the code. If anything goes wrong, just make sure that the code is exactly right. If it is, but it still isn't working, email me :)

 

 

Step 8: Put the ButtonShield on the Arduino
This is the ButtonShield and Arduino separated:

 

 

 

 

Action shot - slow-mo cut sequence:

 

 

 

 

This is the ButtonShield and Arduino, happily reunited:

 

 

 

 

Step 9: Connect the USB cable from the Arduino to the computer
This is so obvious I'm not putting a picture here, on principle.

 

 

Step 10: Set the USB port in the Tools->Serial Port menu
If you're like me, you regularly have 4 or 5 Arduinos (and these days, 10-15 Illuminato X Machina's) dangling off of various USB ports around your computer. So then I always have to try to guess which USB Com port the Arduino decided to become this time - it usually works on the second or third try. Or maybe you just have one Arduino plugging in at any given time, and it's a lot easier.

 

 

 

 

Step 11: Upload the Program to the Arduino
And press buttons on the ButtonPad, and the key codes will be displayed in the Serial Terminal window...

 

 

 

 

Step 13: Use this code if you have a ButtonPad

 
#include

//Create a new ButtonPad
ButtonPad MyPad = ButtonPad();

void setup()
{
Serial.begin(9600);
}

void loop()
{
//Display the pressed buttons to the PC
Serial.println(MyPad.readButtons());

delay(250);

//Random LED blinkage
MyPad.ledWrite(random(0,6),HIGH);
MyPad.ledWrite(random(0,6),LOW);
}

 

 

 

Comments (0)

You don't have permission to comment on this page.