首页 文章

通过蓝牙 - > arduino-> DAC-> 3.5mm分线板 - >耳机发送音频时发出惊人的音频 . 不知道原因

提问于
浏览
0

我编写了一个python代码和arduino代码的混合来使这项工作 . I am sending an array of numbers (audio)HC-05 bluetooth module/arduino uno (这些都设置为 communicate via serial at 115200 baud ,至少这是我为两者设置的(用于arduino的Serial.begin(x)和用于HC-05的AT命令)范围从0-4095作为来自python的字符串通过蓝牙(bluetoothsocket(RFCOMM)) . 它们在arduino中逐个字符地接收并读入一个数组,该数组将char数组转换为单个原始的unsigned int . 直到那里 I can confirm that chars were received and definitely constructed into integers . 那些 integer values are passed into a 12-bit DAC via I2C (SDA(A4)/ SLC(A5) arduino上的引脚 . 在网页上(https://learn.adafruit.com/mcp4725-12-bit-dac-tutorial/using-with-arduino)它说要提高传输速度你在arduino脚本中写这个"TWBR = 12; // 400 khz",我猜 . 否则DAC将以100kHz发送; so I set the transmission speed to 400kHz for the DAC . 当我连接时DAC输出到3.5mm突破/耳塞 I only hear crackling, absolutely no "sound" . 耳机在我的笔记本电脑上工作得很好,所以问题就是其他问题.DAC绝对输出一个电压(网页上的三角波文件)我尝试了两个3.5mm分线板(也许粗制滥造焊接工作?) . Does anyone have an idea of what the issue could be or steps I could take to find what the error is? 我的猜测是传输速率/位传输没有排队的地方,但这就是我想通过询问找到的东西 .

在python方面,代码或多或少看起来像这样:

*initializing socket, setting to non-blocking socket,etc..

for i in range((1000)):  #just to test, the file Id like to send is maybe 300,000 strings
    HC05_socket.send(soundchars[i])

这是arduino代码:

#define ledPinr 4
#include <Wire.h>
#include <Adafruit_MCP4725.h>

Adafruit_MCP4725 dac;

int wait =10000;  //

void setup() {
  // put your setup code here, to run once:
pinMode(ledPinr, OUTPUT);
  digitalWrite(ledPinr, LOW);
Serial.begin(115200);
dac.begin(0x62); 
TWBR = 12; // 400 khz  done in library
Serial.setTimeout(wait);   // for now
}

void loop() {
  // Read serial input:
 char val[4]; // length 4  for 12-bit resolution


if (Serial.available()){
digitalWrite(ledPinr, LOW);


    Serial.readBytesUntil(',', val, 4);  


 int num = atol(val);

dac.setVoltage(num, false);
Serial.print(num);

}


if (Serial.available()==0){
digitalWrite(ledPinr, HIGH);
}

}

注意:忽略LED代码行,这只是为了在运行程序时了解数据流 .

1 回答

  • 0

    导致音频噼啪声的原因有很多,特别是在这些设置中(我相信你已经知道了) .

    有几件事:

    • 虽然在你链接的例子中说它写了 TWBR = 12 ,如果你看source code of the library它会检查 #define TWBR 宏 . 因此,我会在 setup() 函数之前将代码更改为 #define TWBR 12 .

    • 您多久收到一次蓝牙数据?当你没有收到任何数据时,DAC就会发生这种情况,只会冻结你上次写的任何值

    • 确保拨打正确的地址 - >您没有提及A0是否在您的设置中连接到VCC .

    首先,请务必调用begin(addr),其中addr是i2c地址(默认为0x62,如果A0连接到VCC,则为0x63)

    附注:

    • 根据我的经验,人们尝试使用 atol() avoid . 如果你看adafruit's examples,他们会改用 pgm_read_word() .

    • 12音频播放的音频分辨率不是很高,因此大多数音频都会失真(非常基本的数字声音)

    • 确保您're sending from Python is playable (I don'知道您的测试用例是什么音频)

    最后它总是焊接,但我认为这不太可能 .

相关问题