Little Rook Chess on an Arduboy DevKit

So, I readed the example for Chess

Ok, now with the source open, refer back to the original topic post, which has some information about the lines that need to be changed to make this source compile for the devkit. For the lines below I’ve replaced it with the button values for the Arduboy 1.0.

Setting up Little Rook for Arduboy 1.0

Add or change the Chess example from the u8glib library to reflect the source below. See the comments of each code block for further instructions.

// Create the u8g object according to the Arduboy's hardware.
// SW SPI Com: SCK = 15, MOSI = 16, CS = 12, A0 = 4, RST = 6
U8GLIB_SSD1306_ADAFRUIT_128X64 u8g(15, 16, 12, 4, 6); // add this line.

// keys for Arduboy 1.0
// change the existing values
uint8_t uiKeyPrev = A2;  // left button
uint8_t uiKeyNext = A1;  // right button
uint8_t uiKeySelect = 7; // 'A' button
uint8_t uiKeyBack = 8;   // 'B' button

Modify the setup() function to stop the screen from being rotated.

void setup() {
  // rotate screen, if required
  //u8g.setRot180(); // comment this line out
  
  uiSetup();
  chess_Init(u8g.getU8g(), 0);
}

Arduboy Button Bindings

The following are the pin values for the Arduboy 1.0 buttons. These can be used to customize the button layout used by the game in the previous section.

PIN_LEFT_BUTTON = A2
PIN_RIGHT_BUTTON = A1
PIN_UP_BUTTON = A0
PIN_DOWN_BUTTON = A3
PIN_A_BUTTON = 7
PIN_B_BUTTON = 8

I think it’s done, I changed the source

Ok now select your target board as the leonardo, and then select the COM port your Arduboy is on. After setting up the device, you then will hit compile and upload, and you should be ready to play.

If it compiles with errors, please post them back in here and we can resolve them.

Im in COM1 not COM3 like the tutorial :confused:

How I compile and Upload ?

Here is a pretty helpful thread as well,

When selecting a COM port, as long as it shows up as a leonardo you should be fine. Windows will tend to place it on COM3 in most cases. When in doubt, save your work, and restart the IDE with the unit plugged in. You can also open up the Windows Device Manager and check which COM it is on.

Anyway, here’s the part that is important to you from the thead above, it should help with the compile/build and upload process.

Select the Leonardo Board and a COM port

  • From the Arduino IDE menu select Tools > Board > Arduino Leonardo.

  • Select the appropriate COM from Tools > Com.

Uploading

In the upper left corner of the Arduino IDE are two buttons used to verify (compile) and upload code to the Arduboy.

To upload a game:

  • Verify the sketch.

  • Upload the sketch.

You are now ready to play!

Its still COM1

Error message : u8g not declared in this scope

D:\Tytin\Mes documents\Arduino\Chess\Chess.ino: In function ‘void setup()’:

Chess:198: error: ‘u8g’ was not declared in this scope

u8g.setRot180();

^

D:\Tytin\Mes documents\Arduino\Chess\Chess.ino: In function ‘void loop()’:

Chess:207: error: ‘u8g’ was not declared in this scope

u8g.firstPage();

^

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

1 Like

Make sure you add

// SW SPI Com: SCK = 15, MOSI = 16, CS = 12, DC = 4, RST = 6
U8GLIB_SSD1306_ADAFRUIT_128X64 u8g(15, 16, 12, 4, 6);

to the top of the source file somewhere, under the header definitions and above or below that big comment blog at the beginning of the file.

That is the constructor call to setup the library so it can draw to the screen. the u8g is being defined in this line. There is a long list of commented out constructors to choose from, this one is custom, but should work.

Mine looks like:

//U8GLIB_SSD1351_128X128_HICOLOR u8g(8, 9, 7); // Arduino, HW SPI Com: SCK = 76, MOSI = 75, CS = 8, A0 = 9, RESET = 7 (http://electronics.ilsoft.co.uk/ArduinoShield.aspx)
//U8GLIB_SSD1351_128X128GH_332 u8g(8, 9, 7); // Arduino, HW SPI Com: SCK = 76, MOSI = 75, CS = 8, A0 = 9, RESET = 7 (Freetronics OLED)
//U8GLIB_SSD1351_128X128GH_HICOLOR u8g(8, 9, 7); // Arduino, HW SPI Com: SCK = 76, MOSI = 75, CS = 8, A0 = 9, RESET = 7 (Freetronics OLED)


// DOGS102 shield configuration values
// uint8_t uiKeyPrev = 2;
// uint8_t uiKeyNext = 4;
// uint8_t uiKeySelect = 5;
// uint8_t uiKeyBack = 3;

// DOGM128-Shield	 configuration values
// DOGXL60-Shield configuration values

U8GLIB_SSD1306_ADAFRUIT_128X64 u8g(15, 16, 12, 4, 6); // <- Here is the added line

uint8_t uiKeyPrev = A2;
uint8_t uiKeyNext = A1;
uint8_t uiKeySelect = 7;
uint8_t uiKeyBack = 8;

And in the setup() function (line 197 about), comment out u8g.setRot180(); so that it looks like the following:

void setup() {
  // rotate screen, if required
  //u8g.setRot180();
  
  uiSetup();
  chess_Init(u8g.getU8g(), 0);
}

When I try to upoload the sketch

D:\Tytin\Mes documents\Arduino\libraries\U8glib\src\clib\u8g_rot.c:48:1: warning: initialization from incompatible pointer type [enabled by default]

u8g_dev_t u8g_dev_rot = { u8g_dev_rot_dummy_fn, NULL, NULL };

^

D:\Tytin\Mes documents\Arduino\libraries\U8glib\src\clib\u8g_rot.c:48:1: warning: (near initialization for ‘u8g_dev_rot.dev_fn’) [enabled by default]

Ok sorry about the delay. I currently have it running… haha but the screen is upside down, you just need to comment out the call to rotate the screen in the setup() function.

So warnings shouldn’t prevent you from compiling and uploading.

I did have the values setup incorrectly in the source I posted, so it has been updated. Please look at the source a the bottom of Little Rook Chess on an Arduboy DevKit - #22 by ekem again.

After playing this rather fun game for a bit, it might actually benefit from using the Arduboy Library, either through saving the game state so you can resume a game after the unit is powered off or just saving a game record.

Sound might also make a nice addition as well.

The button mappings are definitely going to be up to a user’s preference : )

Any news on this? Would love to be able to get a nice little version of chess on my production Arduboy.

Everything should work @Josh_Hartdegen. Use whats in this thread Little Rook Chess on an Arduboy DevKit to setup the sketch.

I think this was a pain to put on Codebender, and I didn’t feel right putting it up on Github yet :smiley:

Maybe now I will, but if you follow those instructions you should be able to get everything running. And yes, I flipped the image right side up :smiley:

Please do! It’s not out of laziness or an inability to learn, but this whole process - sketches, functions, etc. - is incredibly new to me, and I’m struggling here. If it’s not too much of a hassle to upload a working production version, I’d really appreciate it! :innocent:

1 Like

The only way I ever learned anything was by seeing it done :smile: . So I present to you a finished, working upload (some assembly required ;)).

Arduboy Little Rook


The link provided is to a Git repository containing the sketch needed to play Little Rook on an Arduboy.

Instructions


Step 01 · Install the U8glib library.

It is the same process to install the U8glib library as it to install the Arduboy library: use the Arduino IDE’s Library Manager. The Library Manager can be found in the Arduino IDE’s menu bar under the Sketch drop down menu, Sketch > Include Library > Manage Libraries....

Step 02 · Create the ArduboyLittleRook sketch, copy and paste, then upload.

It is easiest to open the Arduino IDE and create a new sketch called ArduboyLittleRook, save it, and then copy and paste the source from Github into your new file to create the sketch. Save your sketch, then compile and upload the result to an Arduboy.

Has anyone built an .arduboy package version of this?

All Arduboy Manager games are also hosted on the site’s repo as .arduboy games.

You can find the .arduboy file here: http://www.crait.net/arduboy/littlerookchess/LittleRookChess.arduboy

neat, thanks.
Did you package it? Could you call the hex file something more meaningful, at the moment it’s called app.hex

I currently flash my arduboy using a pocket chip, so the hex files are handy.

If the arduboy format states it should be called app.hex that’s fine, I can work with that.

I have a system that kinda makes them real quick so I don’t worry about manually naming them. Sorry, but feel free to rename the .hex file if it works best for you! :smiley:

Is there a reason the board is only half the screen when it coudl easily be 75% and probably have easier to discern pieces? Was it originally designed for a lower res screen?