Gameboy Emulator & Playing I2S Audio on the Omega2
Welcome back to this special edition of 2-Bullet Tuesday, where we’ll share useful tips and awesome stuff sent in by Omega2 users all around the world. Check out creative projects and tutorials that will supercharge your IoT development!
Our favorite project this week is an awesome Omega2 Gameboy Emulator made by Maximilian Gerhardt. Max took advantage of the SPI improvements in the new Omega OS version released last week and was able to make a functioning Gameboy and Gameboy Color emulator. A USB audio card provides game sound and a Nintendo Wii Classic gamepad serves as the input device.
On the software side, the
gnuboy emulator runs the games, the ILI9225 library drives the screen, and the WiiClassic library accepts gamepad input. We would be remiss not to mention that Max also developed the ILI9225 and WiiClassic libraries!
The emulator runs all tested games without issues, but the display was running at a very, very low frame rate. Using the newest Onion OS, Max was able to increase the visual performance of games from 2 FPS to 20 FPS! The source code is also available on Max’s GitHub repo.
Great project, Max! We can’t wait to see more awesome retro and display-based projects!
We have some more exciting news this week: the very latest release of the Omega OS has support for I2S audio devices! For this week’s tip, we’ll show you how to install the latest release and play some tunes with your Omega using an I2S amp IC and a small speaker.
We’ll guide you through the installation process and the hardware setup. Then we’ll jump into playing MP3 and WAV files, and even streaming internet radio! So, let’s get started!
Updating the Omega
Our very latest firmware,
b177, adds I2S support to the Omega. Let’s go ahead and upgrade our OS. Please note, the upgrading process has to be done via either SSH or a Serial connection. Note that it will not work on the Terminal app on the Onion Console.
From the command line issue the following command:
Make sure to note that this is the
latest release, and not the
stable release. As such, proceed with caution!
Connecting to the Amp
Let’s wire everything up! We’ll need the following ingredients:
- MAX98367A I2S mono amp breakout board
- 2.5W Speaker
- Onion Dock with the Expansion Header (Expansion Dock, Arduino Dock R2, Power Dock 2)
- 7 Male-to-Male Jumper Wires
- 100K Ohm Resistor
We’ll be connecting things together:
- Connect the speaker to the
I2S Amp(Positive to + terminal and Negative to – terminal)
GNDto I2S Amp
GPIO2 (I2S WS)to
LRC (Left-right clock)
- WS stands for Word Select, it tells the amp which channel is active (left or right), hence it’s also sometimes called Left-Right Clock
GPIO 3 (I2S CLK)to
BCLK (bit clock)
GPIO 1 (I2S SDO)to
SDO– serial data out from Omega goes to Data In on the amp
I2Samp with 100kΩ Resistor
- This resistor is used to decrease the amp gain, greatly improving the sound quality on our little speaker
Your setup should look something like this:
After your Omega is done updating, we’ll need to install some software to help us play music files:
opkg update opkg install alsa-utils mpg123
Enabling the I2S Pins
Next, we’ll need to change the mux settings for GPIO 0-3 to switch them from regular GPIOs to I2S pins. To do so, run the following command:
omega2-ctrl gpiomux set i2s i2s
And you’ll see the following output:
set gpiomux i2s -> i2s
Playing Audio Files
Now, we are all set and ready to play some tunes using your Omega2! To play a
WAV file we’ll use the following command:
aplay <WAV FILE>
To play an MP3 file, issue the following command:
mpg123 <MP3 FILE>
If you want to stop playback before the file is done, hit
For example, if you want to listen to an MP3 file, transfer it to your Omega and use
mpg123 to play it:
root@Omega-F159:~# mpg123 glass-onion.mp3 High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3 version 1.22.3; written and copyright by Michael Hipp and others free software (LGPL) without any warranty but with best wishes Playing MPEG stream 1 of 1: glass-onion.mp3 ... MPEG 1.0 layer III, 160 kbit/s, 44100 Hz stereo Title: Glass Onion Artist: The Beatles Album: White Album CD 1 Year: 1968 Genre: Rock & Roll
Playing Internet Radio
You can also use
mpg123 to stream internet radio! You will need the
.m3u URL of the radio station that you want to play. For example, you can download the
.m3u file from any internet radio web-site. We downloaded the file from here. Now, open the file using any text editor (e. g. notepad, vi), copy the link, and run the
mpg123 command with the URL as the argument:
root@Omega-F159:~# mpg123 http://uk5.internet-radio.com:8251/ High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3 version 1.22.3; written and copyright by Michael Hipp and others free software (LGPL) without any warranty but with best wishes Directory: http://uk5.internet-radio.com:8251/ Playing MPEG stream 1 of 1: ... ICY-NAME: Classic Rock HD Plus ICY-URL: http://classicrockflorida.com MPEG 1.0 layer III, 192 kbit/s, 44100 Hz joint-stereo ICY-META: StreamTitle='Santana - Oye Como Va';
And here you have it! Now, you can listen to your favorite local and internet tunes using your Omega2!