Skip to content

Almarch/Nanogotchi

 
 

Repository files navigation

TaMaGoTcHi A Tamagotchi emulator for ESP chips × Arduino IDE

TamaLIB is a hardware-agnostic original P1 Tamagotchi emulator.

It has been optimized and restructured to fit the Arduino Uno board. Arduino environment comes with an IDE designed for ease of use. However, the Arduino Uno board, powered by an ATmega328P chip, is not fast enough to follow up the real-time emulation.

From the Arduino fork, TamaLIB has been adapted to ESP8266 and ESP32, both chips being fast enough for a real-time emulation. These two ESP forks are set on a different IDE.

The goal of the present fork is to bring together the beginner-friendliness of the Arduino IDE and the performance of the ESP chips. It relies on the developments from all previously listed projects.

The game icons have been copied from MCUgotchi, a Tamalib implementation targetting STM32FO/STM32LO boards. This choice of aesthetics is motivated by there resemblance to the original toy ones.

An extra functionality is added to the original gameplay: the game state can be saved by a simultaneous click on both 3 buttons (right, middle, left). EEPROM can only be written a limited number of times, this functionality should be used with parcimony.

Hardware

List of components

  • An ESP8266 or ESP32 board
  • 1K resistor x 3
  • Push button x 3
  • Buzzer 3V
  • SSD1306 I2C OLED 128x64
  • Breadboard and wire

Assembling

The board PINs have to be connected to the components.

ESP8266 ESP32
Component GPIO pinout GPIO pinout
Screen SCK - D1 - D22
Screen SDA - D2 - D21
Buzzer 14 D5 15 D15
Left button 12 D6 18 D18
Middle button 13 D7 19 D19
Right button 15 D8 23 D23
VDD - 3V3 - 3V3
Ground - G - G

More info on the PIN mapping is available for common ESP8266 and ESP32 boards.

VDD is distributed to the push buttons and to the screen. The resistors are used as pull-down.

Software

Clone this repository:

git clone https://github.com/Almarch/Nanogotchi.git

Arduino IDE must be available.

Original P1 ROM

The emulation requires a ROM converted to 12 bits. Two options are available:

  • If you have a working Java environment, you can use the original program from ArduinoGotchi. Place the rom.bin file in the project folder and execute:
cd Nanogotchi
java TamaRomConvert rom.bin
  • If you have a working R environment and tamaR installed, you can export the 12 bits ROM into the project folder:
cd Nanogotchi
R -e "library(tamaR); o = Tama(); o\$GetROM() |> tamaR:::nb2hex(header = 'static const unsigned char g_program_b12[] PROGMEM = {') |> write('rom_12bit.h')"

Using tamaR it is possible to substitute P1 sprites by P2 ones adding p2(o);. Before switching sprites, you might have to erase the EEPROM. From the Arduino IDE, start a serial connection and type the command: 9 to erase a previously saved games state.

After the conversion step, a rom_12bit.h file should be available in the project folder.

Conditionally compiled code

The code contains conditionally compiled parts. Depending on the target chip, comment the appropriate line between #define ESP32 or #define ESP8266 at the beginning of Nanogotchi.ino.

Arduino IDE parameterization

Open the .ino file in Arduino IDE.

Add the lines into File/Preferences/Additional Boards Manager URLs:

https://dl.espressif.com/dl/package_esp32_index.json, http://arduino.esp8266.com/stable/package_esp8266com_index.json

Then look for esp8266 and/or esp32 in Tools/Board/Boards manager and install the library.

Install U8g2 library in Tool/Manage Libraries.

You might have to install the USB-to-serial drivers for the board chipset. For instance, for some ESP32 development boards:

Restart the computer after drivers installation.

Compilation & launch

When the environment is ready, select the appropriate board as for instance: Tools/Board/esp32/ESP32 Dev Module.

Select the port: Tools/port/, the port to which the board is connected should appear.

Finally, use the upload command: ➡️. Some ESP32 development boards require a reset from the board reset button during the "Connecting..." step.

About

A Tamagotchi emulator for ESP chips × Arduino IDE

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 82.2%
  • C++ 15.2%
  • Java 2.6%