我正在寻找关于如何在BeagleBone上生成合成声音信号的指针/提示,类似于观看tone()函数将返回Arduinos。最后,我想在GPIO引脚上连接一个压电或扬声器,并从中听到声波。有什么指针吗?
答案 0 :(得分: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)
答案 1 :(得分:1)
AM3359的GPIO引脚为低电压且驱动器强度不足以直接驱动任何类型的传感器。您需要构建一个带运算放大器,晶体管或FET的小电路来实现这一目标。
完成此操作后,您只需设置定时器循环即可以所需频率更改GPIO线路的状态。
到目前为止,从该主板获取音频的最快捷,最简单的方法是使用USB音频接口。
答案 2 :(得分:1)
结帐this page。从userland(例如python),您可以通过写入sysfs
中的正确/sys/class/gpio
文件来将引脚设置为高或低。