Skip to main content
deleted 2950 characters in body
Source Link
#include <SoftwareSerial.h>
const int rx=0;
const int tx=1;

SoftwareSerial mySerial(rx,tx);
int CLK = 2;   //Pin that sends impluse to TSL1401R's CLK pin.
int SI = 1;    //Pin that sends impluse to TSL1401R's SI pin.
int Aout = A3;  //Pin that receives impluse TSL1401R's analog output.
int Aout1 = A2;

int LED = 0;

int pixelsArray[128];   //Array to hold the values of the individual pixles.
int pixelsArray1[128];
    
void setup() 
{
  pinMode(CLK,OUTPUT);    //Setting the CLK pin to be used for output 
  pinMode(SI,OUTPUT);     //Setting the SI pin to be used for output
  pinMode(Aout,INPUT);    //Setting the analog pin to be used for input
  pinMode(Aout1,INPUT);
  pinMode(LED, OUTPUT);
  
  mySerial.begin(9600);     //Setting the data transfer rate

}
/************************************************************************/

 void loop() 
{      
  timming();
  readPixels();
}

/************************************************************************/
/*This method is called at the begining of each cycle to throw away the old image and 
start a new cycle. Notice that unlike the readPixels function it contains a 129th impulse.*/
void timming(void)
{

  //The timing for the impluses was found through direct experimentation.
  //(Meaing that I played around with different times until the code worked)
  
  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 i = 0; i < 128; i++)
  {
    digitalWrite(CLK, HIGH);
    delayMicroseconds(time);
    digitalWrite(CLK, LOW);
    delayMicroseconds(time);
  }

  digitalWrite(CLK, HIGH);
  delayMicroseconds(time);
  digitalWrite(CLK, LOW);
  delayMicroseconds(time);
}
/************************************************************************/
//This method reads in the values of the pixels and stores them into pixlesArray
void readPixels(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 i = 0; i < 128; i++)
  { 
    digitalWrite(CLK, HIGH);
    pixelsArray[i]=analogRead(Aout);
    //pixelsArray1[i]=analogRead(Aout1);
    delayMicroseconds(time);
    digitalWrite(CLK, LOW);
    delayMicroseconds(time);
  }
  
  outputPixels(); //Once the pixelsArray[] has been populated this function is called to print them                                                
  
  delay(20);
}

 /************************************************************************/
 //This method outputs the results that have been stored in pixelsArray[].
 void outputPixels()
{
  for(int j = 0; j < 128; j++)
  {
    digitalWrite(LED, LOW);
    
    if(pixelsArray[j] < 100)
    {
      digitalWrite(LED, HIGH);
      delay(500);
      digitalWrite(LED, LOW);
      delay(500);
    }
  }
}
#include <SoftwareSerial.h>
const int rx=0;
const int tx=1;

SoftwareSerial mySerial(rx,tx);
int CLK = 2;   //Pin that sends impluse to TSL1401R's CLK pin.
int SI = 1;    //Pin that sends impluse to TSL1401R's SI pin.
int Aout = A3;  //Pin that receives impluse TSL1401R's analog output.
int Aout1 = A2;

int LED = 0;

int pixelsArray[128];   //Array to hold the values of the individual pixles.
int pixelsArray1[128];
    
void setup() 
{
  pinMode(CLK,OUTPUT);    //Setting the CLK pin to be used for output 
  pinMode(SI,OUTPUT);     //Setting the SI pin to be used for output
  pinMode(Aout,INPUT);    //Setting the analog pin to be used for input
  pinMode(Aout1,INPUT);
  pinMode(LED, OUTPUT);
  
  mySerial.begin(9600);     //Setting the data transfer rate

}
/************************************************************************/

 void loop() 
{      
  timming();
  readPixels();
}

/************************************************************************/
/*This method is called at the begining of each cycle to throw away the old image and 
start a new cycle. Notice that unlike the readPixels function it contains a 129th impulse.*/
void timming(void)
{

  //The timing for the impluses was found through direct experimentation.
  //(Meaing that I played around with different times until the code worked)
  
  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 i = 0; i < 128; i++)
  {
    digitalWrite(CLK, HIGH);
    delayMicroseconds(time);
    digitalWrite(CLK, LOW);
    delayMicroseconds(time);
  }

  digitalWrite(CLK, HIGH);
  delayMicroseconds(time);
  digitalWrite(CLK, LOW);
  delayMicroseconds(time);
}
/************************************************************************/
//This method reads in the values of the pixels and stores them into pixlesArray
void readPixels(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 i = 0; i < 128; i++)
  { 
    digitalWrite(CLK, HIGH);
    pixelsArray[i]=analogRead(Aout);
    //pixelsArray1[i]=analogRead(Aout1);
    delayMicroseconds(time);
    digitalWrite(CLK, LOW);
    delayMicroseconds(time);
  }
  
  outputPixels(); //Once the pixelsArray[] has been populated this function is called to print them                                                
  
  delay(20);
}

 /************************************************************************/
 //This method outputs the results that have been stored in pixelsArray[].
 void outputPixels()
{
  for(int j = 0; j < 128; j++)
  {
    digitalWrite(LED, LOW);
    
    if(pixelsArray[j] < 100)
    {
      digitalWrite(LED, HIGH);
      delay(500);
      digitalWrite(LED, LOW);
      delay(500);
    }
  }
}
#include <SoftwareSerial.h>
const int rx=0;
const int tx=1;

SoftwareSerial mySerial(rx,tx);
int CLK = 2;
int SI = 1;
int Aout = A3; 
int Aout1 = A2;

int LED = 0;

int pixelsArray[128];   //Array to hold the values of the individual pixles.
int pixelsArray1[128];

 void outputPixels()
{
  for(int j = 0; j < 128; j++)
  {
    digitalWrite(LED, LOW);
    
    if(pixelsArray[j] < 100)
    {
      digitalWrite(LED, HIGH);
      delay(500);
      digitalWrite(LED, LOW);
      delay(500);
    }
  }
}
Source Link

Debugging with an ATtiny?

I have an ATtiny hooked up to two line scan modules. I'm sending digital signals to the line scan modules then receiving the analog output and storing it in an array. I have an if statement that will make the LED on the ATtiny programmer blink when the number are below a certain range (meaning that lens is covered).

Here is my code:

#include <SoftwareSerial.h>
const int rx=0;
const int tx=1;

SoftwareSerial mySerial(rx,tx);
int CLK = 2;   //Pin that sends impluse to TSL1401R's CLK pin.
int SI = 1;    //Pin that sends impluse to TSL1401R's SI pin.
int Aout = A3;  //Pin that receives impluse TSL1401R's analog output.
int Aout1 = A2;

int LED = 0;

int pixelsArray[128];   //Array to hold the values of the individual pixles.
int pixelsArray1[128];
    
void setup() 
{
  pinMode(CLK,OUTPUT);    //Setting the CLK pin to be used for output 
  pinMode(SI,OUTPUT);     //Setting the SI pin to be used for output
  pinMode(Aout,INPUT);    //Setting the analog pin to be used for input
  pinMode(Aout1,INPUT);
  pinMode(LED, OUTPUT);
  
  mySerial.begin(9600);     //Setting the data transfer rate

}
/************************************************************************/

 void loop() 
{      
  timming();
  readPixels();
}

/************************************************************************/
/*This method is called at the begining of each cycle to throw away the old image and 
start a new cycle. Notice that unlike the readPixels function it contains a 129th impulse.*/
void timming(void)
{

  //The timing for the impluses was found through direct experimentation.
  //(Meaing that I played around with different times until the code worked)
  
  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 i = 0; i < 128; i++)
  {
    digitalWrite(CLK, HIGH);
    delayMicroseconds(time);
    digitalWrite(CLK, LOW);
    delayMicroseconds(time);
  }

  digitalWrite(CLK, HIGH);
  delayMicroseconds(time);
  digitalWrite(CLK, LOW);
  delayMicroseconds(time);
}
/************************************************************************/
//This method reads in the values of the pixels and stores them into pixlesArray
void readPixels(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 i = 0; i < 128; i++)
  { 
    digitalWrite(CLK, HIGH);
    pixelsArray[i]=analogRead(Aout);
    //pixelsArray1[i]=analogRead(Aout1);
    delayMicroseconds(time);
    digitalWrite(CLK, LOW);
    delayMicroseconds(time);
  }
  
  outputPixels(); //Once the pixelsArray[] has been populated this function is called to print them                                                
  
  delay(20);
}

 /************************************************************************/
 //This method outputs the results that have been stored in pixelsArray[].
 void outputPixels()
{
  for(int j = 0; j < 128; j++)
  {
    digitalWrite(LED, LOW);
    
    if(pixelsArray[j] < 100)
    {
      digitalWrite(LED, HIGH);
      delay(500);
      digitalWrite(LED, LOW);
      delay(500);
    }
  }
}

The problem that I am having is that when I test my code with one line scan module it works just fine. You will notice that in the readPixels() I have the statement pixelsArray1[i]=analogRead(Aout1); commented out. However, when I try to use it with two the LED start blinking regardless of how much light is hitting the line scanner.

The strange thing is that EVEN when I comment out the digitalWrite(LED, HIGH); statement in the outputPixels() method...THE LED STILL BLINKS!!!

Since the ATtiny does not support URT and can't use the console in Arduino I have no idea how to debug this. Does anyone here have any clue what is wrong?

Here is the datasheets

ATtiny: http://www.atmel.com/Images/doc2543.pdf

ATtiny Programmer: https://learn.sparkfun.com/tutorials/tiny-avr-programmer-hookup-guide/?_ga=1.59946280.467360091.1464906372