OsciWalker

Introduction

It is sometimes hard for students, especially ones new to electronics, to grasp the limitless possibilities that they gain from the knowledge they obtain while studying electronics engineering. For this purpose, I looked for a simple, mostly software related project that could bring the power of electronics closer to the interest of younger students that already attend electronics engineering courses, or are thinking about it.

Consequently, I have decided to design a simple game, which would be played using only a small microcontroller board and an oscilloscope, which would showcase two of the more important tools that are important during the process of becoming an electronics engineer – the oscilloscope, which is the most important and most useful instrument any electronics engineering student will use, and microcontrollers, which present the foundation of almost all modern electronics project.

Thus was born the idea of OsciWalker, a “runner” (though due to the speed more of a “walker”, hence the name) game where you must guide a lost spaceship through a long (actually endless) subterranean tunnel, where the ship must avoid collisions with dangerous hanging ice stalactites and gigantic poisonous mushrooms. The OsciWalker code can be found at the OsciWalker GitHub repository.

Oscilloscope drawing

The principle of drawing on the oscilloscope is actually pretty straightforward. A two channel oscilloscope takes the signals on its two input channels and based on their values renders a line on the screen – the first channel is used to control the vertical position of the line and the second channel to control the horizontal position. To put this in another way, the two signals represent the X and Y positions of the oscilloscope screen, so to control the screen of the oscilloscope, the X and Y axis signal must be varied to produce the desired result. As an example, refer to the following drawing of a spaceship graphic sprite.

Oscilloscope drawing principle

Game code

The first version of the OsciWalker game was developed as a standalone application, where the SDL2 library was used for graphics rendering. All function of the game itself were coded in a way to be suitable for later use on a microcontroller. The SDL2 library was the used to display the game state on the screen. Using this approach, it is possible to develop a game much faster then if the development was done directly on a microcontroller, as no additional hardware is needed during development.

OsciWalker initial emulated game

The game implements the following features:

  • A spaceship that moves through a tunnel at a fixed rate. It can be controlled to move up or down, allowing it to avoid obstacles.
  • Two types of obstacles: hanging ice stalactites, that must be dived under, and gigantic mushrooms, that must be flown over.
  • If the spaceship collides with an obstacle, it disintegrates in an animated way and the game is restarted.
  • At the beginning, the entrance into the tunnel is shown. Additionally, the tunnel can switch between a total of 5 different height levels.
  • The switching of the tunnels, as well as position of obstacles is controlled by a random number generator.

Hardware interfacing

The game code was then ported to a STM32F3 microcontroller, running a FreeRTOS operating system. The STM32F3DISCOVERY board was used because it had all the required periphery needed (two independant DAC channels and an accelerometer to use for game control).

Signal generation

The signals to the oscilloscope are generated by two independent 12 bit DACs, each running at 100 kHz. By setting a frame rate of 20 frames per second, this means that a total of 5000 points can be drawn each frame, which is more than enough for the OsciWalker game (where the ship uses approximately 500 points and each obstacle approximately 250p points).

Accelerometer

The acceleration sensor that can be accessed over the I2C interface was used as a controller. By flicking the STM32F3DISCOVERY board up or down, the OsciWalker ship can be controlled. This is accomplished by taking the Z-axis readings of the oscilloscope and applying a high-pass IIR filter over it. When the accelerometer signal exceeds a predefined threshold, an move up or move down event is triggered, depending on the direction of the acceleration.

Random number generator

To assure that no two playthroughs are alike, a PRNG is used to generate obstacles and perform level height adjustment. Sicne the STM32F3 microcontroller lacks the methods with which game PRNGs are traditionally seeded (usually system time is used) the least significant bit of the accelerometer readings is used - each time the bit is set, a PRNG value is discarded. This means that the random noise of the acceleration sensor is used to influence the PRNG sequence, greatly incresing the quality of random numbers generated.

Game performance

The game was tested on two different oscilloscopes: the HM1507 by Hameg, which uses a CRT screen and the DS2102A by Rigol, which uses an LCD screen. From the pictures of the game it can be seen that the CRT screen oscilloscope produces a better image than the LCD screen oscilloscope. There are three reasons for this: the CRT screen uses an analog beam to render the image, featuring a low pass filtering effect, the Hameg oscilloscope has better noise performance than the Rigol oscilloscope and the beam of the CRT screen has a better persistence effect, which looks more pleasing to a human than the disjointed pixels of a monochrome LCD screen. OsciWalker Hameg and Rigol Oscilloscope Comparison

Related