简体   繁体   English

Python 使用 MCP3008 采样频率

[英]Python using MCP3008 sample frequency

I am trying to make project of visible light communication.我正在尝试制作可见光通信项目。 Currently I am using a classic LED as TX part and BPW21 photodiode with MCP3008 AD convertor as a RX part.目前,我使用经典 LED 作为 TX 部分,使用带有 MCP3008 AD 转换器的 BPW21 光电二极管作为 RX 部分。 Both of this part run on the RasPi4 withy python 3.7.3.这两个部分都在带有 python 3.7.3 的 RasPi4 上运行。 However I have problem with receiving the bits using OOK modulation on RX part.但是,我在 RX 部分使用 OOK 调制接收位时遇到问题。

import busio
import digitalio
import board
import time
import adafruit_mcp3xxx.mcp3008 as MCP
from adafruit_mcp3xxx.analog_in import AnalogIn

spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)
cs = digitalio.DigitalInOut(board.D5)
mcp = MCP.MCP3008(spi, cs)
channel_0 = AnalogIn(mcp, MCP.P0)

def evaluateSensorValue():

    bits = ""

    sensor_value = channel_0.value
    channel_voltage = channel_0.voltage

    if channel_voltage < 3.0:
        bits = "1"
        print("1")
    else:
        bits = "0"
        print("0")

while True:
    evaluateSensorValue()
    time.sleep(0.05)

I am reading input from the Channel 0 of MCP3008.我正在从 MCP3008 的通道 0 读取输入。 However in such a low frequency of 20Hz, I am not able to "catch" all the bits.然而,在如此低的 20Hz 频率下,我无法“捕捉”所有比特。 BPW21 has fast response time to light in 1.5 us fall and rise time. BPW21 在 1.5 us 的下降和上升时间内具有快速的照明响应时间。 I thouht that MCP3008 will be fast enough to catch all the bits in frequency of 10 kHz, not only lower than 20 Hz.我认为 MCP3008 将足够快以捕获 10 kHz 频率的所有位,而不仅仅是低于 20 Hz。 How can I make it way much faster on RX side to be able to receive data in higher frequencies?如何在 RX 端更快地接收更高频率的数据? Thank you for any kind of help!感谢您提供任何帮助!

This answer is solved.这个答案解决了。 The problem was in the very high sampling frequency of the AD converter.问题在于 AD 转换器的采样频率非常高。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python,RPi + MCP3008 + 2xForce敏感电阻-正方形 - Python, RPi + MCP3008 + 2xForce Sensitive Resistor - Square 使用 Python 在 Raspberry Pi 上以菊花链方式连接 MCP3008 SPI 的问题 - Issue with daisychaining MCP3008 SPI on Raspberry Pi with Python 无法使用 python 在 rpi0 上设置多个 mcp3008 ADC 芯片。任何关于错误的想法都适用 - Trouble setting up multiple mcp3008 ADC chips on rpi0 using python. Any ideas as to what is wrong are appriciated 我可以使用MCP3008输出吗? - could i use a MCP3008 to output? 有什么办法可以让我的 Mcp3008 采样统一? - Is there any way to make my Mcp3008 sampling uniform? 尝试通过SPI(MCP3304,MCP3204或MCP3008)在RPi 2 b +上读取带有Cython的ADC吗? - Trying to read an ADC with Cython on an RPi 2 b+ via SPI (MCP3304, MCP3204, or MCP3008)? 如何使用mcp3008中的数据显示和动态更新多个wxpython静态文本? - how to display and dynamically update multiple wxpython static text with data from a mcp3008? 如何更改将mcp3008读取并显示降雨传感器数据的wxpython程序更改为软件spi? - How to change my wxpython program that read and display rain sensor data from mcp3008 to software spi? Python中的不规则采样频率到规则采样频率 - Irregular sample frequency to regular sample frequency in Python 如何以高频读取和累积传感器值,而无需不断写入磁盘(RPi 2 b+、MCP3304、Python) - How to read & accumulate sensor values at high frequency, without constantly writing to disk (RPi 2 b+, MCP3304, Python)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM