【问题标题】:How to generate sound signal through a GPIO pin on BeagleBone如何通过 BeagleBone 上的 GPIO 引脚生成声音信号
【发布时间】:2012-12-23 01:28:38
【问题描述】:

我正在寻找有关如何在 BeagleBone 上生成合成声音信号的指针/提示,类似于观察 Arduino 上的tone() 函数将返回。最终,我想在 GPIO 引脚上连接一个压电或扬声器,并从中听到声波。任何指针?

【问题讨论】:

    标签: python audio beagleboard


    【解决方案1】:

    这就是我在 Beaglebone 上使用 Python 和 PyBBIO 解决这个问题的方法:

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

    【讨论】:

      【解决方案2】:

      查看this page。在用户空间(例如 python)中,您可以通过在/sys/class/gpio 中写入正确的sysfs 文件来将引脚设置为高或低。

      【讨论】:

        【解决方案3】:

        AM3359 的 GPIO 引脚电压低,驱动强度不足以直接驱动任何类型的传感器。为此,您需要构建一个带有运算放大器、晶体管或 FET 的小型电路。

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

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-11-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多