我正在寻找有关如何在 BeagleBone 上生成合成声音信号的指针/提示,类似于观察 Arduinos 上的tone() 函数。最终,我想在 GPIO 引脚上连接一个压电或扬声器,并从中听到声波。任何指针?
问问题
4135 次
3 回答
2
这就是我设法使用 Python 和PyBBIO在 Beaglebone 上解决这个问题的方法:
#!/usr/bin/python
# Circuit:
# * A Piezo is connected to pin 12 on header P8. - GPIO1_12
# * A LED is connected to pin 14 on header P8. - GPIO0_26
# * A button is connected to pin 45 on header P8. - GPIO2_6
# Use a pull-down resistor (around 10K ohms) between pin 45 and ground.
# 3.3v for the other side of the button can be taken from pins 3 or 4
# on header P9. Warning: Do not allow 5V to go into the GPIO pins.
# * GND - pin 1 or 2, header P9.
def setup(): # this function will run once, on startup
pinMode(PIEZO, OUTPUT) # set up pin 12 on header P8 as an output - Piezo
pinMode(LED, OUTPUT) # set up pin 14 on header P8 as an output - LED
pinMode(BUTTON, INPUT) # set up pin 45 on header P8 as an input - Button
def loop(): # this function will run repeatedly, until user hits CTRL+C
if (digitalRead(BUTTON) == HIGH):
# was the button pressed? (is 3.3v making it HIGH?) then do:
buzz()
delay(10) # don't "peg" the processor checking pin
def delay(j): #need to overwrite delay() otherwise, it's too slow
for k in range(1,j):
pass
def buzz(): #this is what makes the piezo buzz - a series of pulses
# the shorter the delay between HIGH and LOW, the higher the pitch
limit = 500 # change this value as needed;
# consider using a potentiometer to set the value
for j in range(1, limit):
digitalWrite(PIEZO, HIGH)
delay(j)
digitalWrite(PIEZO, LOW)
delay(j)
if j==limit/2:
digitalWrite(LED, HIGH)
digitalWrite(LED, LOW) # turn it off
run(setup, loop)
于 2013-05-22T20:27:44.047 回答
1
AM3359 的 GPIO 引脚电压低,驱动强度不足以直接驱动任何类型的传感器。为此,您需要构建一个带有运算放大器、晶体管或 FET 的小电路。
完成此操作后,您只需设置一个定时器循环,以所需频率更改 GPIO 线的状态。
到目前为止,从该板获取音频的最快和最简单的方法是使用 USB 音频接口。
于 2012-12-23T02:14:48.103 回答
1
看看这个页面。从用户态(例如python),您可以通过写入正确的sysfs
文件来将引脚设置为高或低/sys/class/gpio
。
于 2012-12-23T02:16:38.070 回答