This project could be also named "YAIGC" or, for the humans, "Yet Another Invaders-Game Clone".
This is not the very first time an Invaders game has been developed for the .Net Micro Framework (check here), but it should be the very first developed for a Netduino-sized board.
The goal of this post is not give you a game, rather demonstrating how is simple create a pretty complex application using the GDI library for Netduino. Moreover, the good performance of the library as well as the physical layer (driver and hardware) yields the ability to control both a led-matrix and a LCD module at same time.
Of course, for the game to be playable, we also need a minimal controller. A simple sound generation is also provided.
How it's made?
I won't go deeper in the details of the app, because any good programmer can put his/hers hands on it. Instead, I'll go to describe the circuit structure, which is far form being complex.
All the hardware is composed of the following "components":
- a Netduino (Plus) 2;
- a Sure Electronics led-matrix module (introduced here);
- any common LCD character-module (I used a 4x20 one);
- three pushbuttons as the game-controller;
- some parts for the sound generation (optional);
- a good 5VDC power supply (I used a LM7805).
NOTE: although you could try to build this project using an “old” Netduino (Atmel-based), I strongly recommend to use any of the “2nd generation” (STM32-based). That’s because the much better performance of the newer board.
The led-matrix module.
The led-matrix circuit was described here and there's no changes for this circuit. However, here is the Fritzing wiring for your convenience.
The LCD module.
The LCD module is driven using the LcdBoost library, thus the circuit is the same as usual, also used here. Please, bear in mind that the LCD management has to be very fast, so the LcdBoost library+hardware is mandatory.
It follows the Fritizing for this section.
The power supply.
I found several problems around the supply when the regulated power isn't filtered well enough. I mean that many switching-PSUs aren't suitable for such a circuit, unless you'll provide some additional ripple filtering, such as inductors and capacitors. Since this would be complex to deal with, I recommend to choose any 9-12VDC PSU (even switching-mode), then add a linear regulator as the LM7805. It's inexpensive and very easy to wire.
Here is how to do:
The game controller.
The game is controlled with just three buttons: fire, left and right.
The sound generation.
When the game app was almost finished, I really missed for some sound, which gave a bit of reality to the project. So, how to create a super-simple sound generation without messing with complex circuits or heavy software routines?
Really: wasn't in my mind sooner and I though to some wave generations with PWMs or dedicated oscillators such as the NE555.
PWMs wasn't satisfying at all, and also required a relatively intensive work by the Netduino. That's because the PWM waves couldn't be always the same, but should be modified over time to create attractive effects. So, no PWMs.
Even the external hardware oscillators wasn't suitable, because they should be driven in some way. Moreover, the circuit complexity would have raised dramatically. Most of you don't want to deal with complex circuits.
Once again, the Colombo's egg was an "hack" over an unsuspicious component of the MCU. The goal is having an arbitrary wave generation (also with noise), so...why not using the UART?
The UART output is able to shape a variable bit pattern due its nature. You feed the serial buffer with the desired bit-stream, then they will be issued at the desired rate. This is much like the IR-transmitter approach solved with the SPI. This time I don't need a perfect wave generation, but a bit of "messy" data for a better noise generation. Moreover the SPI flows the data too fast for the purpose, but the UART fits perfectly.
So, what I really need as hardware is just an amplifier for a loudspeaker. Note that I can't wire the speaker directly to a I/O pin, because the board might be damaged. Moreover, I wished to get a louder sound other than a Netduino port could do.
Here follows the super-simple circuit for the loudspeaker amplifier.
Finally here we are.
Here is a short video of the running invaders game.
The entire source code is as always in the Cet Toolbox repository on Codeplex.