0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[ミニ化ドライバー]Arduino Modulino Buzzer(STM32C011)-STM32G030F6

Last updated at Posted at 2025-10-24
  • [I2C]UNO3で「0」と「1」を交互にI2Cに出力する。(I2Cホストプログラム)

  • Arduino日本語リファレンス

  • Wire.begin(address)

  • Wire.beginTransmission(address)

  • Wire.write(value)

  • Wire.endTransmission()

いろいろ注意

  • (重要)Modulino Buzzerは、3.3V
  • 過去ログを見て!!!
  • プルアップ抵抗、忘れずに

結果(鳴った、わかりずらいというか、画面では、分からない)

Screenshot from 2025-10-24 10-10-49.png

プログラム



//i2c_beep_g030_1
//Arduino Modulino Buzzer(STM32C011)のミニドライバー
//32BITのARM系限定
//理由 なぜなら、int が32BITで86系と同じ小っちゃい順からだから


//インクルド
#include <Arduino.h>
#include <Wire.h>
#include <string.h> //memcpy用


//定義
int frequency = 440; //周波数
int duration = 1000; //鳴らす時間


//Arduino Modulino Buzzer(STM32C011)のブザーを鳴らす
//鳴らす時間,周波数
void i2c_beep(int freq, int len_ms) {

  //鳴らす時間,周波数をバッファーに転記する 受信側も同じ32BIT,ARM系だから成り立つ
  uint8_t buf[8];
  memcpy(&buf[0], &freq, 4);
  memcpy(&buf[4], &len_ms, 4);


  //I2Cへの送信
  Wire.beginTransmission(  0x1e  ); //スタートとI2Cアドレスを送る

  for (int i = 0; i < 8; i++) { //8回ループ

    //一文字出力
    Wire.write(  buf[i]  ); //1バイトデータを送る

  }//for i

  Wire.endTransmission(); //ストップを送る

} //i2c_beep


//初期化
void setup() {

  //STM32G030F6
  //I2Cのポートの変更
  Wire.setSDA(10);  //PA10
  Wire.setSCL(9);   //PA9

  //I2Cの初期化処理
  Wire.begin(); //STM32G030F6
  delay(200); //ダミーのウエート I2Cスレーブの安定化用

} //setup


//メインループ
void loop() {

  // Play tone at specified frequency and duration
  i2c_beep(frequency, duration); //ブザーを鳴らす
  delay(1000); //1秒待つ
  // Stop the tone (0 frequency)  //ブザーを止める
  i2c_beep(0, duration);
  delay(1000); ////1秒待つ

} //loop


0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?