lazymeercat415
New member
** Cách kết nối micrô với Raspberry Pi bằng ADS1115 ADC và ghi âm âm thanh với Pyaudio hoặc SoudDevice **
** Những người cao cho tôi hỏi tôi có muốn hàn micrô vào ADC ADS1115 - 16 bit như hình dưới đây không, ngôi sao được kết nối với PI qua I2C là okie.
** Điều kiện tiên quyết **
* Một quả mâm xôi pi
* ADS1115 ADC
* Một micrô
* Một cái bánh mì
* Một số dây nhảy
**Hướng dẫn**
1. Kết nối ADS1115 ADC với Raspberry Pi theo sơ đồ sau:
[Hình ảnh của sơ đồ mạch]
2. Kết nối micrô với ADS1115 ADC theo sơ đồ sau:
[Hình ảnh của micrô được kết nối với ADC]
3. Sức mạnh trên Raspberry Pi.
4. Cài đặt các thư viện Python sau:
* `Pyaudio`
* `smbus2`
5. Chạy mã sau để ghi âm thanh từ micrô:
`` `Python
Nhập Pyaudio
Nhập SMBUS2
# Tạo một đối tượng pyaudio.
pa = pyaudio.pyaudio ()
# Mở một luồng micrô.
stream = pa.open (format = pyaudio.paint16, kênh = 1, rate = 44100, input = true, frames_per_buffer = 1024)
# Tạo một đối tượng smbus.
bus = smbus2.smbus (1)
# Chọn thiết bị ADS1115.
Địa chỉ = 0x48
# Đặt mức tăng thành 24db.
bus.write_byte_data (địa chỉ, 0x00, 0x02)
# Bắt đầu thu thập dữ liệu.
bus.write_byte_data (địa chỉ, 0x01, 0x80)
# Đọc dữ liệu từ ADC.
data = bus.read_i2c_block_data (địa chỉ, 0x00, 2)
# Chuyển đổi dữ liệu thành số điểm nổi.
điện áp = (dữ liệu [0] << 8) |Dữ liệu [1]
Điện áp = điện áp / 32768.0 * 5.0
# In điện áp.
in (điện áp)
# Đóng luồng micrô.
stream.close ()
# Đóng đối tượng Pyaudio.
pa.erminate ()
`` `
** Đầu ra **
Đầu ra của mã sẽ là một số điểm nổi đại diện cho điện áp của tín hiệu âm thanh từ micrô.
=======================================
**How to connect a microphone to a Raspberry Pi using the ADS1115 ADC and record audio with Pyaudio or Souddevice**
**The high people let me ask if I want to weld a microphone into the ADC ADS1115 - 16 bit as shown below, the star connected to Pi via I2C is okie.Then record with Pyaudio or Souddevice Python**
**Prerequisites**
* A Raspberry Pi
* An ADS1115 ADC
* A microphone
* A breadboard
* Some jumper wires
**Instructions**
1. Connect the ADS1115 ADC to the Raspberry Pi according to the following diagram:
[Image of the circuit diagram]
2. Connect the microphone to the ADS1115 ADC according to the following diagram:
[Image of the microphone connected to the ADC]
3. Power on the Raspberry Pi.
4. Install the following Python libraries:
* `pyaudio`
* `smbus2`
5. Run the following code to record audio from the microphone:
```python
import pyaudio
import smbus2
# Create a PyAudio object.
pa = pyaudio.PyAudio()
# Open a microphone stream.
stream = pa.open(format=pyaudio.paInt16, channels=1, rate=44100, input=True, frames_per_buffer=1024)
# Create a SMBus object.
bus = smbus2.SMBus(1)
# Select the ADS1115 device.
address = 0x48
# Set the gain to 24dB.
bus.write_byte_data(address, 0x00, 0x02)
# Start the data acquisition.
bus.write_byte_data(address, 0x01, 0x80)
# Read the data from the ADC.
data = bus.read_i2c_block_data(address, 0x00, 2)
# Convert the data to a floating-point number.
voltage = (data[0] << 8) | data[1]
voltage = voltage / 32768.0 * 5.0
# Print the voltage.
print(voltage)
# Close the microphone stream.
stream.close()
# Close the PyAudio object.
pa.terminate()
```
**Output**
The output of the code will be a floating-point number representing the voltage of the audio signal from the microphone.
** Những người cao cho tôi hỏi tôi có muốn hàn micrô vào ADC ADS1115 - 16 bit như hình dưới đây không, ngôi sao được kết nối với PI qua I2C là okie.
** Điều kiện tiên quyết **
* Một quả mâm xôi pi
* ADS1115 ADC
* Một micrô
* Một cái bánh mì
* Một số dây nhảy
**Hướng dẫn**
1. Kết nối ADS1115 ADC với Raspberry Pi theo sơ đồ sau:
[Hình ảnh của sơ đồ mạch]
2. Kết nối micrô với ADS1115 ADC theo sơ đồ sau:
[Hình ảnh của micrô được kết nối với ADC]
3. Sức mạnh trên Raspberry Pi.
4. Cài đặt các thư viện Python sau:
* `Pyaudio`
* `smbus2`
5. Chạy mã sau để ghi âm thanh từ micrô:
`` `Python
Nhập Pyaudio
Nhập SMBUS2
# Tạo một đối tượng pyaudio.
pa = pyaudio.pyaudio ()
# Mở một luồng micrô.
stream = pa.open (format = pyaudio.paint16, kênh = 1, rate = 44100, input = true, frames_per_buffer = 1024)
# Tạo một đối tượng smbus.
bus = smbus2.smbus (1)
# Chọn thiết bị ADS1115.
Địa chỉ = 0x48
# Đặt mức tăng thành 24db.
bus.write_byte_data (địa chỉ, 0x00, 0x02)
# Bắt đầu thu thập dữ liệu.
bus.write_byte_data (địa chỉ, 0x01, 0x80)
# Đọc dữ liệu từ ADC.
data = bus.read_i2c_block_data (địa chỉ, 0x00, 2)
# Chuyển đổi dữ liệu thành số điểm nổi.
điện áp = (dữ liệu [0] << 8) |Dữ liệu [1]
Điện áp = điện áp / 32768.0 * 5.0
# In điện áp.
in (điện áp)
# Đóng luồng micrô.
stream.close ()
# Đóng đối tượng Pyaudio.
pa.erminate ()
`` `
** Đầu ra **
Đầu ra của mã sẽ là một số điểm nổi đại diện cho điện áp của tín hiệu âm thanh từ micrô.
=======================================
**How to connect a microphone to a Raspberry Pi using the ADS1115 ADC and record audio with Pyaudio or Souddevice**
**The high people let me ask if I want to weld a microphone into the ADC ADS1115 - 16 bit as shown below, the star connected to Pi via I2C is okie.Then record with Pyaudio or Souddevice Python**
**Prerequisites**
* A Raspberry Pi
* An ADS1115 ADC
* A microphone
* A breadboard
* Some jumper wires
**Instructions**
1. Connect the ADS1115 ADC to the Raspberry Pi according to the following diagram:
[Image of the circuit diagram]
2. Connect the microphone to the ADS1115 ADC according to the following diagram:
[Image of the microphone connected to the ADC]
3. Power on the Raspberry Pi.
4. Install the following Python libraries:
* `pyaudio`
* `smbus2`
5. Run the following code to record audio from the microphone:
```python
import pyaudio
import smbus2
# Create a PyAudio object.
pa = pyaudio.PyAudio()
# Open a microphone stream.
stream = pa.open(format=pyaudio.paInt16, channels=1, rate=44100, input=True, frames_per_buffer=1024)
# Create a SMBus object.
bus = smbus2.SMBus(1)
# Select the ADS1115 device.
address = 0x48
# Set the gain to 24dB.
bus.write_byte_data(address, 0x00, 0x02)
# Start the data acquisition.
bus.write_byte_data(address, 0x01, 0x80)
# Read the data from the ADC.
data = bus.read_i2c_block_data(address, 0x00, 2)
# Convert the data to a floating-point number.
voltage = (data[0] << 8) | data[1]
voltage = voltage / 32768.0 * 5.0
# Print the voltage.
print(voltage)
# Close the microphone stream.
stream.close()
# Close the PyAudio object.
pa.terminate()
```
**Output**
The output of the code will be a floating-point number representing the voltage of the audio signal from the microphone.