Python 如何通过BeagleBone上的GPIO引脚生成声音信号

Python 如何通过BeagleBone上的GPIO引脚生成声音信号,python,audio,beagleboard,Python,Audio,Beagleboard,我正在寻找关于如何在BeagleBone上生成合成声音信号的指针/提示,类似于观察Arduinos上的音调函数返回。最后,我想在GPIO引脚上连接一个压电元件或扬声器,并从中听到声波。有什么建议吗 AM3359的GPIO引脚电压低,驱动器强度不足,无法直接驱动任何类型的传感器。要做到这一点,你需要用运放、晶体管或场效应晶体管构建一个小电路 完成此操作后,只需设置一个计时器循环,以按所需频率更改GPIO线的状态 到目前为止,从该板获取音频的最快和最简单的方法是使用USB音频接口 AM3359的GP

我正在寻找关于如何在BeagleBone上生成合成声音信号的指针/提示,类似于观察Arduinos上的音调函数返回。最后,我想在GPIO引脚上连接一个压电元件或扬声器,并从中听到声波。有什么建议吗

AM3359的GPIO引脚电压低,驱动器强度不足,无法直接驱动任何类型的传感器。要做到这一点,你需要用运放、晶体管或场效应晶体管构建一个小电路

完成此操作后,只需设置一个计时器循环,以按所需频率更改GPIO线的状态


到目前为止,从该板获取音频的最快和最简单的方法是使用USB音频接口

AM3359的GPIO引脚电压低,驱动器强度不足,无法直接驱动任何类型的传感器。要做到这一点,你需要用运放、晶体管或场效应晶体管构建一个小电路

完成此操作后,只需设置一个计时器循环,以按所需频率更改GPIO线的状态


到目前为止,从该板获取音频的最快和最简单的方法是使用USB音频接口

退房。从userland,例如python,您可以通过写入/sys/class/gpio中的正确sysfs文件来使用将pin设置为高或低。

签出。从userland(例如python),您可以通过写入/sys/class/gpio中的正确sysfs文件,使用将pin设置为高或低。

这就是我如何使用python在Beaglebone上解决此问题的方法,并且:


这就是我如何在Beaglebone上使用Python和:

#!/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)