I am really struggling to use the parallax TSL 1401 line scanner with my Arduino uno R3 along with the BOE shield. I have managed to get it working with the working with an oscilloscope, so now I am trying to have it read a barcode by saving the data onto the internal EEPROM. The code I have posted here
#include <EEPROM.h>
byte value;
#define opened 13
int addr = 0;
int Initiate = 0;
int verify = 0;
#define CLK 2 //camera clock input is connected to pin 2 of arduino.
#define SI 3
#define Aout A0
unsigned int captpix[128]; //FOR STORE THE DIFFENTS VALUES OF EACH PIXEL.
void setup()
{
pinMode(CLK,OUTPUT);
pinMode(SI,OUTPUT);
pinMode(Aout,INPUT); //THE ANALOG OUTPUT OF THE CAMERA is connected to the arduino board.
Serial.begin(9600); // IF YOU WANT TO SEE THE ANALOG OPPUTS VALUES OF THE CAMERA OF EACH PIXEL
}
/************************************************************************/
// WITH THIS FUNCTION YOU CAN SEE THE CAMERA'S ANALOG OUTPUT IN THE OSCILLOSCOPE. YOU CAN WATCH MY VIDEO IN MY YOUTUBE CHANNEL. see page 5 of the datasheet, figure 1 and 2.
void timming(void)
{
int time=170;
digitalWrite(SI, HIGH);
delayMicroseconds(time/2);
digitalWrite(CLK, HIGH);
delayMicroseconds(time/2);
digitalWrite(SI, LOW);
delayMicroseconds(time/2);
digitalWrite(CLK, LOW);
delayMicroseconds(time);
for(int contpixel=0;contpixel<128;contpixel++)
{
digitalWrite(CLK, HIGH);
delayMicroseconds(time);
digitalWrite(CLK, LOW);
delayMicroseconds(time);
}
digitalWrite(CLK, HIGH);
delayMicroseconds(time);
digitalWrite(CLK, LOW);
delayMicroseconds(time);
}
/************************************************************************/
//WITH THIS FUNCTION THE CAMERA PROCESS THE ANALOG OUTPUT FOR MOVE THE SERVO.
// IS VERY IMPORTAND THAT YOU LOOK THAT I AM NOT USING TIMER INTERRUPTS IN THIS CODE, THIS CODE IS JUST FOR DEMOSTRATION.
// PREVIOUSLY I WILL FIX THIS CODE. AND I AM SORRY, BEACUSE EXPLAIN MY CODE FOR THIS MEDIUM IS VERY DIFFICULT.
void ADC_READ_CAMERA(void)
{
int addr = 0;
int time=170;
digitalWrite(SI, HIGH);
delayMicroseconds(time/2);
digitalWrite(CLK, HIGH);
delayMicroseconds(time/2);
digitalWrite(SI, LOW);
delayMicroseconds(time/2);
digitalWrite(CLK, LOW);
delayMicroseconds(time);
for(int contpixel=0;contpixel<128;contpixel++)
{ if (addr == EEPROM.length()){
addr = 0;}
else {digitalWrite(CLK, HIGH);
captpix[contpixel]=analogRead(Aout);
delayMicroseconds(time);
digitalWrite(CLK, LOW);
delayMicroseconds(time);
EEPROM.write(addr, (captpix[contpixel]/4));
addr = addr+1;}}
if (addr == 128){digitalWrite (13, HIGH);
delay(1000);
digitalWrite (13,LOW);
addr = 0;}}
/************************************************************************/
void confirm (void) {
int same = 0;
addr = 0;
int time=170;
digitalWrite(SI, HIGH);
delayMicroseconds(time/2);
digitalWrite(CLK, HIGH);
delayMicroseconds(time/2);
digitalWrite(SI, LOW);
delayMicroseconds(time/2);
digitalWrite(CLK, LOW);
delayMicroseconds(time);
for(int contpixel=0;contpixel<128;contpixel++)
{
digitalWrite(CLK, HIGH);
captpix[contpixel]=analogRead(Aout);
delayMicroseconds(time);
digitalWrite(CLK, LOW);
delayMicroseconds(time);
captpix[contpixel] = analogRead(Aout);
if (captpix[contpixel] > (EEPROM.read(addr)-50) && captpix[contpixel]<(EEPROM.read(addr)+50)) {
same = (same+1); addr = (addr+1);}
else {addr = (addr+1);}}
if (same == 128) { digitalWrite (13, HIGH);
delay(1000);
digitalWrite (13,LOW);}}
/************************************************************************/
void loop()
{
//timming(); // if this function is activated, dont active the ADC_READ_CAMERA() and impre() functions. use this function when the
//A0 pin of the camera is connected to the oscilloscope.
Initiate = digitalRead(5);
if (Initiate = HIGH) {
ADC_READ_CAMERA(); // enable this function if you want the 128 output analog values in the serial monitor of arduino, but
}
else {// if you use this function you can not see the analog output signal in the osiclloscope.
verify = digitalRead(6);
if (verify = HIGH) {confirm(); }}}
programs the scanner to first read the value of each pixel and save each value to individual addresses in the EEPROM. After saving the data of the code it first reads, a separate array compares those values to some fresh data read by the camera. If all 128 bits of data match the last code it read, it should set pin 13 high.
It seems like none of the arrays are working, because pin 13 is also programed to go high when addr in ADC_READ_CAMERA reaches 128, and addr increases regardless of the scan results. What might be wrong, do any of the if functions in this sketch stop the flow of sketch until they find a match, or are the arrays not correct?