Simple MicroPython game modules and sample games for ESP8266 and ESP32
gameESP.py for esp8266 or esp32
if you are using esp8266 boards, copy game8266.py as gameESP.py or use mpy-cross to compile to gameESP.mpy
if you are using esp32 boards, copy game32.py as gameESP.py or use mpy-cross to compile to gameESP.mpy
common micropython module for ESP8266 game board designed by Billy Cheung (c) 2019 08 31
Using this common micropython game module, you can write micropython games to run
either on the SPI OLED or I2C OLED without chaning a line of code.
You only need to set the following line in gameESP.py file at the init function
self.useSPI = True # for SPI display , with buttons read through ADC
self.useSPI = False # for I2C display, and individual hard buttons
Note: esp8266 is very bad at running .py micropython source code files
with its very limited CPU onboard memory of 32K
so to run any program with > 300 lines of micropython codes combined (including all modules),
you need to convert source files into byte code first to avoid running out of memory.
Install a version of the mpy-cross micropython pre-compiler that can run in your system (available from github).
Type this command to convert gameESP.py to the byte code file gameESP.mpy using mpy-cross.
then copy the gameESP.mpy file to the micropython's import directory on the flash
create your game and leaverge the functions to display, read buttons and paddle and make sounds
from the gameESP class module.
Add this line to your micropython game source code (examples attached, e.g. invader.py)
from gameESP import gameESP, Rect
#-----------------------------------------
ESP8266 SPI SSD1306 version of game board layout
----------------------------------------
micropython game hat module to use SSD1306 SPI OLED, 6 buttons and a paddle
SPI display runs 5 times faster than I2C display in micropython and you need this speeds
for games with many moving graphics (e.g. space invdader, breakout).
Buttons are read through A0 using many resistors in a Voltage Divider circuit
ESP8266 (node MCU D1 mini) micropython
D0/Sck - D5 (=GPIO14=HSCLK)
D1/MOSI- D7 (=GPIO13=HMOSI)
CS - Hard wired to ground.
n.c. - D6 (=GPIO12=HMISO)
The ADC(0) (aka A0) is used to read both paddles and Buttons
these two pins together control whether buttons or paddle will be read
To read buttons - Pin.Btn.On() Pin.Paddle.off() Pin.Paddle2.off()
To read paddle - Pin.Btn.Off() Pin.Paddle.on() Pin.Paddle2.off()
To read paddle2 - Pin.Btn.Off() Pin.Paddle.off() Pin.Paddle2.on()
buttons are connected in series to create a voltage dividor
Each directional and A , B button when pressed will connect that point of
the voltage dividor to A0 to read the ADC value to determine which button is pressed.
resistor values are chosen to ensure we have at least a gap of 10 between each button combinations.
L, R, U, D, can be pressed individually but not toghether.
A, B, can be pressed invididually but not together.
any one of A or B, can be pressed together with any one of L,R,U,D
so you can move the gun using L,R, U,D, while shooting with A or B.
refer to the schematics on my github for how to hook it up
3.3V-9K-Up-9K-Left-12K-Right-9K-Down-9K-A button-12K-B Button-9K-GND
#-----------------------------------------
ESP8266 I2C SSD1306 version of game board layout
----------------------------------------
mocropython game hat module to use SSD1306 I2C OLED, 6 buttons and a paddle
I2C display runs 5 times slower than I2C display in micropython.
Games with many moving graphics (e.g. space invdader, breakout) will run slower.
Buttons are read through indvidial GPIO pins (pulled high).
Buttons are connect to GND when pressed
GPIO16 cannot be pulled high by softeware, connect a 10K resisor to VCC to pull high
#==================================================================================
The pin layout is exactly the same as that of the Odroid-Go
so this library can be used on the micropython firmware of the Odroid-Go
#------------------------
==============
MISO - IO19-VSPI-MISO (not required for OLED)
TF Card Odroid-go (optional)
================
================
======
======
=============
============
Menu IO13