Trying to play music with the MeBaseboard integrated buzzer


#1

Hi everyone,

I’m trying to play music like “jingle bell” with my Me Baseboard and Mblock, but it’s look impossible…
Did a Mblock “block” to control the Me baseboard buzzer exist ?

And with the arduino IDE I can make a beep but nothing else… How can I program to play music ?

#include <Makeblock.h>
#include <SoftwareSerial.h>
#include <Wire.h>

void setup() 
{
}

void loop()
{
  buzzerOn();
  delay(1000);
  buzzerOff();
  delay(1000);
}

Thanks for your help :wink:


#2

With the mBlock IDE, you’d need to tether the robot via WiFi, Bluetooth, or possibly the USB cable (haven’t tried that one because OS X El Capitan screwed up the USB stack and I haven’t gotten it to work with the mBot board), and run the program from the mBlock IDE. See the thread at http://forum.makeblock.cc/t/changing-notes-on-the-speaker/2153/2.

If you’re trying to do it from the Arduino IDE, you’ll need to get the current Makeblock libraries and set the tone with the MeBuzzer::tone methods:

// frequency (in hertz) and duration (in milliseconds).
void MeBuzzer::tone(int pin, uint16_t frequency, uint32_t duration)
{
  buzzer_pin = pin;
  int period = 1000000L / frequency;
  int pulse = period / 2;
  for (long i = 0; i < duration * 1000L; i += period)
  {
    digitalWrite(buzzer_pin, HIGH);
    delayMicroseconds(pulse);
    digitalWrite(buzzer_pin, LOW);
    delayMicroseconds(pulse);
  }
}

// frequency (in hertz) and duration (in milliseconds).
void MeBuzzer::tone(uint16_t frequency, uint32_t duration)
{
  int period = 1000000L / frequency;
  int pulse = period / 2;
  for (long i = 0; i < duration * 1000L; i += period)
  {
    digitalWrite(buzzer_pin, HIGH);
    delayMicroseconds(pulse);
    digitalWrite(buzzer_pin, LOW);
    delayMicroseconds(pulse);
  }
}

void MeBuzzer::noTone(int pin)
{
  buzzer_pin = pin;
  digitalWrite(buzzer_pin, LOW);
}

Hope this helps.


#3

Thank you but it’s not what I want.

I’m trying to make music with the buzzer integrated at the Me Baseboard not with a MeBuzzer…

I only find the code BuzzerOn an BuzzerOff but nothing about the tone or the frequency. I try your example and it’s not working because I haven’t got the Pin of the integrated buzzer …

I see in other post that it’s impossible to do that with the Mblock application, but now I try to make it with IDE Arduino, nobody wants to make music with his MeBaseboard ? The buzzer are only here for a “beep” ?

Anyway thank you for watching at my problem;-)


#4

Hmm, I’m looking at the MeBaseBoard.h header file right now. I see a couple of preprocessor definitions for turning the buzzer on and off, but I also see that the file includes the MeBuzzer.h header file as well. The MeConfig.h file has ME_PORT_DEFINED, so it seems that you’d be able to define the pin to play tones via the MeBuzzer module. In the MeBuzzer.cpp file, I see that the buzzer pin (buzzer_pin) is set to 8 by default if ME_PORT_DEFINED is set. You might want to get a copy of the Makeblock libraries from the Github repo and do some snooping about in the source. It’s really the best way to see what’s going on. :slight_smile: