Adaptation of "Pocket Computer" With DumbDisplay

by Trevor Lee in Circuits > Arduino

275 Views, 1 Favorites, 0 Comments

Adaptation of "Pocket Computer" With DumbDisplay

nano.jpg

This post is the result of my effort to adapt Volos Projects' Arduino Nano "Pocket Computer" project with DumbDisplay. Please reference to the original Arduino Nano "Pocket Computer" project by Volos Projects -- Arduino Pocket Computer featuring calculator, stopwatch, calendar, game and phone book

Basically, the same logics are used except for several areas.

In terms of hardware:

  • Virtual graphical LCD is used, with the help of DumbDisplay.
  • Virtual beeper / speaker is used, also with the help of DumbDisplay.
  • Even the sketch can be run with Arduino Nano with some physical buttons, it will be more fun to use a JoyStick Shield for Arduino UNO.

In terms of software:

  • Most importantly: Even DumbDisplay realizes a virtual graphical LCD with your relatively must more powerful Android phone, sending commands to it is text-based serial communication, with relatively high latency. Hence, it is vital that the screen is not redrawn unless necessary. As a result, some effort is put to avoid unnecessary redrawing of the screen.
  • I have put some effort in developing the logics to detect button clicks, as well as joystick presses. In particular, the button click detection is based on the approach as I mentioned in my previous post, Button Click Counting with Virtual 7 Segment Display
  • As my own challenge, I have developed a module for the cacluator logics.

Setup Arduino IDE

add_library.png

In order to be able to compile and run the sketch shown here, you will first need to install the DumbDisplay Arduino library.

Open your Arduino IDE; go to the menu item Tools | Manage Libraries, and type "dumbdisplay" in the search box there.

Connection for Arduino Nano

ddpocketcomputer_connect.png
  • Connect A2 to one pin of the button on the top side; connect GND to the other pin of the button.
  • Connect A1 to one pin of the button on the lower left side; connect GND to the other pin of the button.
  • Connect A4 to one pin of the button on the lower right side; connect GND to the other pin of the button.

Connection for Arduino UNO

uno.jpg

Since a JoyStick Shield is used, hence there is no need to make any wireling. Simple plug the JoyStick Shield to Arduino UNO.

The "Pocket Computer"

ddcomputer-demo.gif

Basically, the main screen of the "pocket computer" is the menu selection screen, which is used to select any one of the six functions of the "pocket computer":

  • Caculator -- a, hopefully, working caculator
  • Stopwatch -- a very simple stop watch
  • Game -- a simple "brick breaker" grame
  • Calendar -- a simple calendar; just showing monthly calendar of select month
  • Phonebook -- a fake phone book; it is a fake
  • Sound On / Off -- turn sound on / off


The Buttons and JoySticks

nano_uno.png

To nevigate, all needed is three buttons. One for left; one for right; and one for select. In most situation, the joystick of JoyStick Shield simply duals as the left and right buttons (actually, it acts as directional buttons). Nevertheless, during game play, the joystick directly positions the bar.

One more trick. When you are into something, say the caculator, if you press the "left" / "right" button and the "select" button at the same time, you get back to the menu.

Navigate the Menu

0_menu.png

The "left" / "right" button moves to the next / previous menu item.

If using the joystick, the menu item selection move more natually, in all four directions.

To select a menu item, press the "select" button.

Navigate the Caculator

1_cal-2.png

The "left" button moves the key selection from left to right, top to bottom; similarily the "right" button moves the key selection as well, but in reverse direction.

If using the joystick, the key selection move more natually, in all four directions.

To select a key, press the "select" button.

Navigate the Stopwatch

The simple stopwatch have 3 states -- "zero" stage; started; and stopped. You go from one state to another by pressing a button.

Navigate the Game

3_game-2.png

The game is a simplie implicatiion of the very simple form of the popular "brick breaker" game.

You use the "left" / "right" buttons to move the bar. You can also use the joystick to move to bar directly to a position, horizontally.

Since the joystick is not very accurate, don't expect too much. Nevertheless, I myself find using the "left" and "right" buttons to move the bar, makes the game fairly playable.

Navigate the Calendar

4_calen-2.png

Pressing the "left" / "right" button will move forward / backward a month.

The Sketch

The sketch assumes that either an Arduino UNO with JoyStick Shield is used; or an Arduino Nano with appropriate buttons connect as shown above.

Certainly, I believe the sketch will work for other boards and setup as well. Just be imaginative.

(As a matter of fact, I actually tried to use Raspberry Pi Pico for the experiment, of cause with some pin setting changes to the sketch.)

// *** 
// * adapted from: youtube.com/watch?v=NTaq6f7NV5U
// ***
// if using Arduino UNO (assume with Joy Stick Shield)
// otherwise, assume Arduino Nano
#if defined(ARDUINO_AVR_UNO)
#define WITH_JOYSTICK
const uint8_t left = 5;
const uint8_t right = 3;
const uint8_t presS = 2;
const uint8_t horizontal = A0;
const uint8_t vertical = A1;
#else
const uint8_t left = PIN_A1;
const uint8_t right = PIN_A4;
const uint8_t presS = PIN_A2;
#endif
const char* COLOR_BG = "darkblue";
const char* COLOR_DEF = "beige";
const char* COLOR_0 = "navy";
const char* COLOR_1 = "ivory";
const uint8_t TEXT_SIZE_DEF = 9;
const uint8_t TEXT_SIZE_2 = 24;
const int TEXT_SIZE_4 = 28;
#include "dumbdisplay.h"
DumbDisplay dumbdisplay(new DDInputOutput(115200));
GraphicalDDLayer *display;
#include "core.h"
#include "pgm_util.h"
void setup() {
dumbdisplay.connect();
dumbdisplay.writeComment("initializing ...");
pinMode(left, INPUT_PULLUP);
pinMode(right, INPUT_PULLUP);
pinMode(presS, INPUT_PULLUP);
#ifdef WITH_JOYSTICK
pinMode(horizontal, INPUT);
pinMode(vertical, INPUT);
#endif
display = dumbdisplay.createGraphicalLayer(64, 128);
display->backgroundColor(COLOR_BG);
display->setTextColor(COLOR_DEF);
display->setCursor(0, 10);
display->print("... init ...");
unsigned char buffer[240];
display->cachePixelImage("logo.png", PgmCopyBytes(epd_bitmap_logo, sizeof(epd_bitmap_logo), buffer), 64, 30, COLOR_1);
display->cachePixelImage("calc.png", PgmCopyBytes(myBitmapcalc, sizeof(myBitmapcalc), buffer), 24, 24, COLOR_1);
display->cachePixelImage("stop.png", PgmCopyBytes(myBitmapstop, sizeof(myBitmapstop), buffer), 24, 24, COLOR_1);
display->cachePixelImage("game.png", PgmCopyBytes(myBitmapgam, sizeof(myBitmapgam), buffer), 24, 24, COLOR_1);
display->cachePixelImage("calen.png", PgmCopyBytes(myBitmapcalen, sizeof(myBitmapcalen), buffer), 24, 24, COLOR_1);
display->cachePixelImage("phone.png", PgmCopyBytes(myBitmapphone, sizeof(myBitmapphone), buffer), 24, 24, COLOR_1);
display->setTextFont("MONOSPACE");
display->clear();
dumbdisplay.writeComment("... done initialization");
randomSeed(millis());
GameReset();
}
void loop() {
if (fase == 0) {
} else {
}
}
if (fase == 1) {
}
if (fase == 2) {
}
if (fase == 3) {
}
if (fase == 4) {
}
if (fase == 5) {
}
}

Since the whole program for this "pocket computer" is quite lenthy, I have split them into several files. The sketch above is simply a bootstrap to the core of this "pocket computer"

All the involved files can be found here. To download the folder, consider using DownGit.

  • ddpocketcomputer.ino -- the sketch as above
  • core.h -- the core coding
  • misc.h -- some global variables for the core
  • PressTracker.h -- the button / joystick press detection class definitions
  • BasicCalculator.h -- the caculator class definitions

Note: Arduino IDE requires that the sketch (ddpocketcomputer.ino), as well as all other INCLUDE files be in a folder with the same name as the sketch (ddpocketcomputer).

Upload the Sketch and Run It

Other than making the needed connections to your Arduino UNO / Nano, you will need to prepare two more addition things:

  • You will need to be able to attach your Arduino UNO / Nano to your Android phone. To do this, you will need an OTG adapter (as listed above in the components and supplies section), which allows you to plug your Arduino UNO / Nano to your phone via the usual USB cable.
  • You will certainly need to install the DumbDisplay Android app.

After uploading the sketch, re-plug the USB cable to your phone via an OTG adapter. Then, open the DumbDisplay Android app on your phone, and make connection.

The Demo

Demo Adaptation of Vovols Projects' Arduino Pocket Computer, with DumbDisplay

One last little suggestion, for making the "Pocket Computer" runs a bit more smoothly -- remember to turn off "Show Commands" of DumbDisplay Android app.

Enjoy!

Peace be with you. Jesus loves you. May God bless you!