Feedback!

Joy Gamer

Views: 4999 Difficulty: 2 Status: Complete
Joy_gamer_banner

Handheld gaming machine, based on the Arduino Leonardo, equipped with joystick, SD card and more.

The Joy Gamer is a handheld, programmable, game machine. It comes with a joystick, and SD Card slot, and an accelerometer. Check them out in our store! The Joy Gamer is built on top of Arduino so you can program your own games and load them up using a micro USB cable. We 3D print enclosures and joystick knobs to make the JoyGamer more ergonomic, colorful, portable, and strong. It can run on rechargeable lithium batteries, USB power, or any 5V power source with hook-up wires.
We have made tons of projects with JoyGamer and we share all our code with you! For example, you can make dynamic picture frames, drawing tools, gesture-based games, and even a fully function USB keyboard or mouse (by using the USB capabilities of the Arduino Leonardo. What's even cooler is that the JoyGamer shows up to your computer like an Arduino Leonardo so you can run any Arduino code you like on the Joy Gamer.

The Brochure

Leo_gamer_brochure
The LEO Gamer Brochure

LEO Gamer Demo

Check out a few of the programs the LEO Gamer can handle. Including Adafruits Graphics test code, a keyboard, pong, and more!

Joy Gamer Demo Code

Here is a little Arduino sketch to get started with the Joy Gamer. The main loop is just 6 lines of code which outputs the current readings from the accelerometer and joystick. In the setup function we also check for an SD card and if there is one we print out "SD GOOD" and otherwise print out SD Failed.
While simple this code shows some of the common design patterns for coding on the Joy Gamer. First notice that we declare both Adafruit_ST7735 and JoyGamer variables:
Adafruit_ST7735  tft = Adafruit_ST7735(SS, 9, 8);
JoyGamer jg = JoyGamer(&tft);
This allows us to directly access all of the functionality of the Adafruit graphics library for the ST7735 screen directly by calling functions on our tft variable. However, we also pass a pointer to this variable to the JoyGamer. Don't worry if you don't know what pointers are, but thats what we get when we put the ampersand before a variable. Since the JoyGamer knows about the tft LCD screen our library can also create graphics. So when you are writing code for the joy gamer you can use functions from the JoyGamer library and/or from the Adafruit graphics library. This is why we have to include all those libraries at the top of this file.
/* LucidTronix Joy Gamer
 * For instructions, details and schematic, See:
 * http://www.lucidtronix.com/tutorials/48
 */

#include <JoyGamer.h>
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#include <Color.h>
#include <I2C.h>
#include <MMA8453Q.h>
#include <SD.h>

Adafruit_ST7735  tft = Adafruit_ST7735(SS, 9, 8);
JoyGamer jg = JoyGamer(&tft);

void setup(){  
  jg.initialize();
  jg.start_sd_card();
}

void loop(){ 
  jg.show_accelerometer(10, 40);
  tft.fillRect(49, 75, 40, 22, jg.background.color_16());
  jg.draw_string(10, 75, "Joy X:", jg.stroke.color_16(), 1);
  jg.print_integer(50, 75, analogRead(0), 1);
  jg.draw_string(10, 85, "Joy Y:", jg.stroke.color_16(), 1);
  jg.print_integer(50, 85, analogRead(1), 1);
}

Display a Bitmap on the Joy Gamer Arduino Code

Here is Arduino Code to show a bitmap image on the Joy Gamer. Our library does almost all the work for you :) Just call the function:
  jg.bmp_load_and_draw_image("sample.bmp");
Make sure you have the SD card inserted properly, and loaded with the bitmap file "sample.bmp". You can of course load whatever images you want. The images do have to be in bitmap format and at largest 128 by 160 pixels. We wrote a little program to convert images into the bmp format, you can download it below.
/* LucidTronix Joy Gamer
 * For instructions, details and schematic, See:
 * http://www.lucidtronix.com/tutorials/48
 */

#include <JoyGamer.h>
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#include <Color.h>
#include <I2C.h>
#include <MMA8453Q.h>
#include <SD.h>

Adafruit_ST7735  tft = Adafruit_ST7735(SS, 9, 8);
JoyGamer jg = JoyGamer(&tft);

void setup(){
  jg.initialize();
  jg.start_sd_card();
  jg.bmp_load_and_draw_image("sample.bmp");
}

void loop() {

}

ST7735 Adafruit Library

Great library from Adafruit for controlling this LCD Screen Github page here.
Click Here to Download: ST7735 Adafruit Library

Adafruit Graphics Library

The Adafruit GFX library. This is the wonderful work of adafruit we just host it here for convenience. We made the most minor modification of replacing the dash in the library folder with an underscore so this baby is ready for your Arduino library folder out of the box :) Check out the GitHub page for the latest.
Click Here to Download: Adafruit Graphics Library

I2C Arduino Library

Similar to the wire library but more flexible. You may wonder why we cannot use the standard Arduino Wire library, it is because the MMA8453Q uses a repeated start condition for the read operations and the default Wire library cannot handle those without modification.
Click Here to Download: I2C Arduino Library

MMA8453Q Accelerometer Arduino Library

Parts

Title Description # Cost Link Picture
PCB LEO Gamer Circuit board for the LEO Gamer. Joystick, accelerometer and TFT LCD Screen. 1 $10.0 Link Leo_pcb
TFT LCD Screen 1.8 inch 160 x 128 pixels LCD screen. ST7735R driver. JDT-1800. 1 $9.95 Link Id618_lrg
ATMEGA32U4-MU Integrated Circuits MCU AVR 32K FLASH 16MHZ 44-QFN Value: 2.7 V ~ 5.5 V 16MHz 1 $6.04 Link Screen_shot_2012-12-28_at_7.31.41_pm
microSD Card Connector Secure Digital - microSD™ Push In, Push Out Value: microSD 1 $3.44 Link 0473340001
Joystick Potentiometer POT JOYSTICK 10K OHM W/SWITCH Value: Variable Resistors 10K 1 $2.86 Link 252a103b60nb
Accelerometers MMA8453QR1 Tripla axis: X, Y, Z ±2g, 4g, 8g 16-VFDFN I²C 16-QFN (3x3) Value: I²C 1 $1.43 Link 16-vfdfn_exposed_pad
USB Micro B Female Connector Micro USB Surface Mount, Right Angle, Horizontal 1 $0.72 Link 10103594-0001lf_sml
Crystal CRYSTAL 16.00000 MHZ 20PF SMD Value: 16MHz 1 $0.53 Link Ecs-270-20-3x-en-tr
Button Tactile switch SMD SPST 0.05A 12V Value: SPST 1 $0.2 Link Fsm4jsma
LED SMD LED 3X1.5MM 568NM Green Clear SMD Value: 2.2V Green 1 $0.18 Link Apl3015sgc-f01
Capacitor CAP CER 0.1UF 50V Y5V 0805 Value: 0.1µF 1 $0.1 Link 0805(6_0mm_thickness)
Resistor Chip Resistor - Surface Mount RES 10K OHM 1/8W 5% 0805 SMD Value: 10k 1 $0.1 Link Screen_shot_2012-12-28_at_7.29.44_pm
Permalink: http://lucidtronix.com/tutorials/48
The Wearable Wayfinder is a totally programmable, beautiful little computer for your wrist packed wit...
Our take on the classic bouncing ball, paddle game....
32 buttons for a fully-functioning hand-held USB keyboard....
Mixing pixels from two face images together....
Play pong on a little LCD screen with two big joysticks....
Servo motor, JPEG camera, and Arduino Leonardo combine to make a panoramic camera....
Coupling the HMC5883L Compass with our color library turns the Wearable Wayfinder into a handy naviga...
Display bitmap images and text files and folders with this TFT LCD screen and SD Card navigator....