1

I am using Raspberry Pi 3 Model B and MCP3008 for sampling my analog signal and the sampling frequeny is approximately 10 kHz. I need to display the sampled values in 3.5' inch graphical LCD. I just tried to find out the frequency of writing operation (using python command). The frequency is approximately 2 kHz and most of the points are missing. Can you guys help me in synchronizing the read and write operation so that I dont miss out the sampled values. The minimum sampling frequency that I need is 1.5 kHz. Thank you guys in advance. I have attached the code which I have implemented right now.

import sys
import time
from itertools import islice
sys.path.append("../../")
from gfxlcd.driver.ili9486.spi import SPI
from gfxlcd.driver.ili9486.ili9486 import ILI9486
import RPi.GPIO
import time
import Adafruit_GPIO.SPI as SPIO
import MCP3008
import Adafruit_MCP3008
import random

drv = SPI(speed=31200000)
o = ILI9486(320, 480, drv)
o.rotation=90
o.init()
o.fill_rect(0, 0, 480, 325)
o.background_color = (0, 0, 0)
o.color = (255, 255, 255)
RPi.GPIO.setmode(RPi.GPIO.BCM)


# Hardware SPI configuration:
SPI_PORT   = 1
SPI_DEVICE = 0
mcp = Adafruit_MCP3008.MCP3008(spi=SPIO.SpiDev(SPI_PORT, SPI_DEVICE, 
max_speed_hz=500))

def adc_wave(values):
    pixel=range(0,len(values))
    for i in range(0,len(values)): 
        y=int(values[i]/3.2)
        start=time.time()
        o.draw_pixel(pixel[i], y)
        end=time.time()
    data1='After write'+'\t'+str(pixel[i])+'\t'+str(values)+'\t'+str(end- 
   start)+'\n'
   print(data1)

values=[0]*150
def read_adc(iteration):
    DELAY=0.0006
    count=0
    pixel=0
    if(pixel==480):
        pixel=0
    while count<150:
        pixel += 1
        values.insert(pixel,mcp.read_adc(0))
        time.sleep(DELAY)
        count+=1
return values

iteration=0

while True:
    values=read_adc(iteration)
    iteration+=1
    adc_wave(values)

This is the code I am using for reading the data from ADC and writing it on GLCD. mcp.read_adc(0) reads value at a very faster rate when compared to draw_pixel which writes to the GLCD. Because of this I am missing out values when writing. Kindly help me on fixing this issue.

Should I use multi-threading or multi-processing to fix this issue?

  • Welcome -- but you will have to post the code you are using, explain what is supposed to do, and what actually happens. – goldilocks Apr 15 '18 at 16:44
  • @goldilocks.. I have modified the question. PFA – Anu Apr 16 '18 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.