有什么辦法可以讓我的Mcp3008采樣均勻嗎?
我正在做一項工作,使用 ADC mcp3008 樣本傳感器數(shù)據(jù)并收集它們直到 10k。然后將其發(fā)送到 influxdb。所有這些工作應(yīng)該在 1 秒內(nèi)完成。這才是重點?,F(xiàn)在的問題是,每條數(shù)據(jù)的時間戳非常不均勻。如你看到的:我希望時間戳統(tǒng)一為0.1ms。我的意思是 influsdb 中的時間精度應(yīng)該是 0.1ms。但不幸的是,寫入?yún)?shù)time_ precision只有's'、'ms'、'u'或'n'。所以我能做的就是讓采樣過程更加統(tǒng)一,對嗎?我使用多處理模塊來完成這項工作。這是我的原始代碼:import Adafruit_GPIO.SPI as SPI # Import Adafruit GPIO_SPI Moduleimport Adafruit_MCP3008 # Import Adafruit_MCP3008import serialimport timeimport datetimefrom influxdb import InfluxDBClientfrom multiprocessing import Process, Queuedef producer(name): i=0 while True: begin=time.time() body = [] while i<10000: val = round(mcp.read_adc(0),4) #here read the data from SPI port current_time = datetime.datetime.utcnow() js = { "measurement": "Double", "time": current_time, "tags": { }, "fields": { "sensor2": val } } body.append(js) i+=1 i=0 res = client.write_points(body) #Send influxdb 10k data at once body.clear() end=time.time()-begin print(end,name) if __name__ == "__main__": HW_SPI_PORT = 0 # Set the SPI Port. Raspi has two. HW_SPI_DEV = 0 # Set the SPI Device mcp = Adafruit_MCP3008.MCP3008(spi=SPI.SpiDev(HW_SPI_PORT, HW_SPI_DEV)) client = InfluxDBClient(host='XXXXX', port=8086, username='admin', password='admin', database= 'db',ssl=False, verify_ssl=False) p1 = Process(target=producer,args=(0,)) p2 = Process(target=producer,args=(1,)) p3 = Process(target=producer,args=(2,)) p4 = Process(target=producer,args=(3,)) p5 = Process(target=producer,args=(4,)) p6 = Process(target=producer,args=(5,)) p1.start() p2.start() p3.start() p4.start() p5.start() p6.start()是的...我必須經(jīng)過六個過程才能在平均一秒內(nèi)完成..
查看完整描述