Arduino for ODROID-GO - Speaker

We will learn how to test the speaker with the buttons on the board.

The odroid_go.h library and its GO instance has a Speaker instance for using the speaker easily.
So, you can play something with GO.Speaker.

Some of the GO.Speaker functions are:

  • setVolume(): to set volume level. The given parameter can be 0 to 11(mute).
  • playMusic(): to play music which is written in 8 bit integers. The given parameter is a proper sample rate for playing music.
  • beep(): to play a simple beep sound.
  • tone(): to play a simple beep sound with two parameters of a frequency and a duration in millisecond. You can omit the duration argument.

We're going to write code that plays a sound when a button is pressed.
We will use the A, B, and Start buttons and make these buttons play a sound that differs from each other.
To learn about how the buttons are used, please refer to the Buttons example.

We're also going to show which button is pressed on the LCD.
To learn about how the LCD is used, please refer to the Hello World example.

We can write source code as below:
Initialize the board by calling the GO.begin() function and put the code in the loop() function that activates when the button wasPressed().

#include <odroid_go.h>
void setup() {
  // put your setup code here, to run once:
  GO.lcd.printf("ODROID-GO speaker test:\r\n");
  GO.Speaker.playMusic(m5stack_startup_music, 25000);
void loop() {
  // put your main code here, to run repeatedly:
  if(GO.BtnA.wasPressed()) {
    GO.lcd.printf("wasPressed: A \r\n");
  if(GO.BtnB.wasPressed()) {
    GO.lcd.printf("wasPressed: B \r\n");
    GO.Speaker.tone(3000, 200);
  if(GO.BtnStart.wasPressed()) {
    GO.lcd.printf("wasPressed: Start \r\n");
    GO.Speaker.playMusic(m5stack_startup_music, 25000);

Press CTRL-U to compile and upload the sketch.
Press A, B or Start button to play a sound.

The complete example is available as follows:

Click the Files → Examples → ODROID-GO → Speaker menu to import and press CTRL-U to compile/upload.