Has anyone continued work with this sensor? Or willing to? I've been working with the sensor for the past few days and have not quite figured it out. I can get representative data when running the code below but it is not very repeatable. I am masking a small area close to the sensor to collect this data.
Code: Select all
import pyb
from array import array
from pyb import Pin, ADC
import os
pin_si = Pin('X1', Pin.OUT_PP)
pin_clk = Pin('X2', Pin.OUT_PP)
pin_ao = ADC(Pin('X3'))
a = array('i', (0,) * 1281)
def deleteFile(filePath=""):
try:
os.remove(filePath)
except OSError:
print('exception: deleteFile()')
def logData():
file = open('/sd/data/ls_data.txt', 'a')
try:
for i in range(1280):
V = a[i]*3.3/4096
file.write(str(V) + '\n')
file.close()
except:
print('exception: logData')
def read():
pin_clk.low()
pin_si.high()
pin_clk.high()
pin_si.low()
for i in range(1281):
pin_clk.low()
a[i] = pin_ao.read() # store raw integer data
pin_clk.high()
deleteFile('/sd/data/ls_data.txt')
data = read() # discard 1st dataset
pyb.delay(1) # 1mS is more than enough (20uS min)
data = read()
logData()
If I run the code below it has much better repeatability (arduino sample extract). I believe repeatability has a lot to do with integration time.
Code: Select all
import pyb
from array import array
from pyb import Pin, ADC
import os
pin_si = Pin('X1', Pin.OUT_PP)
pin_clk = Pin('X2', Pin.OUT_PP)
pin_ao = ADC(Pin('X3'))
a = array('i', (0,) * 1281)
def deleteFile(filePath=""):
try:
os.remove(filePath)
except OSError:
print('exception: deleteFile()')
def logData():
file = open('/sd/data/ls_data.txt', 'w')
try:
for i in range(1280):
V = a[i]*3.3/4096
file.write(str(V) + '\n')
file.close()
except:
print('exception: logData')
# This function generates an outgoing clock pulse from the Arduino digital pin 'CLKpin'. This clock
# pulse is fed into pin 3 of the linear sensor:
def ClockPulse():
pyb.udelay(1)
pin_clk.high()
pin_clk.low()
def setup():
# Clock out any existing SI pulse through the ccd register:
for i in range(1281): ClockPulse()
# Create a new SI pulse and clock out that same SI pulse through the sensor register:
pin_si.high()
ClockPulse()
pin_si.low()
for i in range(1281): ClockPulse()
# Read all 1281 pixels in parallell. Store the result in the array. Each clock pulse
# causes a new pixel to expose its value on the two outputs:
def read():
for i in range(1281):
pyb.udelay(20) # Delay to stabilize the AO output from the sensor
a[i] = pin_ao.read() # store raw integer data
pin_clk.high()
ClockPulse()
# Stop the ongoing integration of light quanta from each photodiode by clocking in a SI pulse
# into the sensors register:
def stopIntegration():
pin_si.high()
ClockPulse()
pin_si.low()
def main():
setup()
deleteFile('/sd/data/ls_data.txt')
data = read() # discard 1st dataset
pyb.delay(1) # 1mS is more than enough (20uS min)
data = read()
logData()
main()
I am trying to collect multiple sample of the output and this is where I am failing miserably (absolutely no representative output). I have tried the following with code base 1:
Code: Select all
for i in range(10):
pyb.delay(1000) # wait 1 sec before collection the next output
data = read()
logData()
and I have tried the code below with the second code base:
Code: Select all
for i in range(10):
stopIntegration()
read()
stopIntegration()
logData(i)
for j in range(18): ClockPulse() # based on datasheet
If anyone has input I would appreciate it.
Regards
Jim