กลับไปหน้ารวมไฟล์
android-dfplayer-mini-bluetooth-audio.md

รีโมทดิจิทัลสำหรับเสียง: Android ควบคุม DFPlayer ผ่าน Bluetooth

Arduino มาตรฐานไม่สามารถถอดรหัสอัลกอริทึม MP3 ที่ซับซ้อนได้เองโดยธรรมชาติ; loop() แบบ 8-bit นั้นอ่อนแอเกินไป! DFPlayer Mini เป็นชิปเสียงเฉพาะแบบ Standalone ที่มีราคาถูกอย่างไม่น่าเชื่อ สามารถจัดการกับการ์ด microSD, ระบบไฟล์ FAT16 ได้เอง และมีแอมพลิฟายเออร์ขนาด 3-Watt ในตัว! สถาปัตยกรรมนี้รวมโมดูล Bluetooth HC-05 เข้ากับ DFPlayer ผู้ใช้กดปุ่มขนาดใหญ่บนแอปพลิเคชัน Android, โทรศัพท์จะส่งคำสั่ง Serial ผ่านทางอากาศ, Arduino จะดักจับคำสั่งนั้น, และสั่งการ DFPlayer ทันทีผ่านบัส SoftwareSerial ตัวที่สองให้เล่น Track 8 อย่างรวดเร็ว!

sound_sensor_activated_led_1772681534011.png

การเชื่อมต่อเครือข่าย Serial สองชุด (SoftwareSerial.h)

Arduino Uno มีพอร์ต Serial แบบ Hardware เพียงพอร์ตเดียว (TX 1, RX 0)

  • โมดูล Bluetooth HC-05 ต้องใช้พอร์ต Hardware Serial เพื่อสื่อสารกับโทรศัพท์ Android อย่างรวดเร็ว
  • เนื่องจาก DFPlayer ก็ต้องการคำสั่ง Serial เพื่อเล่นเพลง คุณจึงต้องเริ่มต้นพอร์ตเสมือน!
  • SoftwareSerial myDFPlayer(10, 11); // RX, TX
  • Arduino ทำหน้าที่เป็นตัวแปลข้อมูลขนาดใหญ่ โดยส่งคำสั่ง String จาก Android ไปยังรหัส Hexadecimal สำหรับ Hardware โดยเฉพาะ!
// Listening to the Smartphone HC-05 Bluetooth Module:
if (Serial.available()) {
  char cmd = Serial.read(); // Read the character sent from Android
  
  if (cmd == 'A') {
    myDFPlayer.play(1);  // The incredible DFRobot library formats the complex Hex payload autonomously!
  } else if (cmd == 'V') {
    myDFPlayer.volumeUp(); 
  }
}

การสร้างอินเทอร์เฟซสัมผัสบน Android

คุณไม่จำเป็นต้องใช้ Terminal Emulator; คุณสร้าง App กำหนดเองขนาดใหญ่ได้เลย!

  • โดยใช้ MIT App Inventor 2, คุณสามารถสร้าง Graphical Interface ที่มีปุ่ม GUI ขนาดใหญ่ "Play", "Stop", และ "Next" ได้ทั้งหมดด้วย Block-code
  • Block ต่างๆ จะเชื่อมต่อกับ Component Bluetooth Client โดยตรง
  • เมื่อ Button_Play ถูกแตะทางกายภาพ, App จะส่งอักขระ ASCII "A" อย่างโปร่งใสผ่านย่านความถี่ RF 2.4GHz ไปยัง HC-05!

ฮาร์ดแวร์ที่ต้องใช้

  • Arduino Uno/Nano/Mega
  • DFPlayer Mini Module (สามารถขับลำโพงขนาดเล็ก 8-Ohm ได้โดยตรง โดยไม่จำเป็นต้องใช้แอมพลิฟายเออร์ MOSFET ภายนอก!)
  • HC-05 หรือ JDY-31 Bluetooth Module (ต้องใช้ Voltage Divider ขนาด 3.3V บนขา RX เพื่อป้องกัน Logic 5V ไม่ให้เผาผลาญ Bluetooth SoC ทันที!)
  • MicroSD Card (ต้องฟอร์แมตเป็น FAT32 สูงสุด 32GB โดยเฉพาะ) (ไฟล์ต้องจัดระเบียบอย่างระมัดระวังในโฟลเดอร์ชื่อ /mp3/ และตั้งชื่อให้ถูกต้องเป็น 0001.mp3, 0002.mp3 เพื่อไม่ให้ Hardware Indexer เกิดข้อผิดพลาด!)
  • Android Smartphone

ข้อมูล Frontmatter ดั้งเดิม

title: "Android DFPlayer Mini Bluetooth control"
description: "Remote digital acoustics! Intercept Bluetooth serial arrays transmitted from custom Android Smartphone matrices, parsing precise hexadecimal commands locally to instantly execute indexed mp3 files natively on a dedicated hardware DFPlayer module."
category: "Audio & Sound"
difficulty: "Intermediate"