Using the Linear Sensor Array TSL201R with Arduino

March 26, 2014 1 comment

Dealing with linear Sensor Arrays is not easy. After some research in the web, found some experiments with TSL1401, TSL202R and TSL201R, many of them without a happy ending.

My intent is to find out how to do simple image processing of Linear Sensor Arrays using the Arduino.

This will open the path to develop some interesting experiments and applications:

-Line Follower Robots.

-Optical Flow Sensor (to sense movement in robots and autonomous vehicles).

-Laser Range Finders.

-Imagen Scanners (Barcode, character recognition etc.)

-Position Sensors.

-Objet Detection and Objet Counting.

-Objet Shape Identification and Analysis.

-Light Spectrum Analyzers.

-Etc…

After reading the (64×1) linear Sensor Arrays TSL201R manual…

tsl201r-fingertip

…decided to buy some DIP-8 versions (package discontinued) in Aliexpress.com, (breadboard friendly).

This is the wiring diagram:

TSL201R_Wiring

Arduino NANO, solid wires (AWG#22) and an adequate breadboard  for the job.

TSL201R_Test_01_noFilter

Pinhole cameras using  PCB Relay’s cases:

tsl201r-test-panels

Because the small hole, more integration time is necessary.

The projected image field of view can be estimated using geometry…

pinhole-image-size-3

The application in Progressing shows the illuminance of each pixel sent by the arduino.

Integration time and frames per second (FPS) are also presented.

TSL201RView_06e

 Here is an example of how to use the sensor to estimate the position of a floating ball.

20140417_120633

Another  possible application, a laser ranger:

laser-ranger-concept

Working to increase the frames per second (FPS)…

Will be continued…

(in twitter you can follow my progress before it be posted here ): @arduining

 

Arduino Trinket Photo Session

February 19, 2014 1 comment

After receiving a bunch of Trinkets, my first impulse was to do some photographic composition…

AtHand

TrinketHandIntelligence at your fingertips.

Trinket_Photo_01Imagine what can be done…

roundGoing arround…

NestTrinketsTrinket nest…

man_002Distributed intelligence…

ArduinoTrinketsGo arduining…

Arduino Trinket and Serial LCD

February 17, 2014 2 comments

Testing the bit bang serial transmission to connect the Trinket with the Serial LCD Module 16×2 from NKC Electronics.
The first Sketch with string functions use 3,634 bytes, the second Sketch, avoiding string functions, use 1,362 bytes.

20140217_125246

Sketch with string functions:

/*	Test_LCD.ino
	Arduining.com  16 FEB 2014
	Binary sketch size: 3,634 bytes (of a 5,310 byte maximum)

	A timer is implemented presenting minutes and seconds elapsed since start.
	Bit Banging Serial transmission at 9600 bauds.
	Example using the Trinket from Adafruit (5V, 8 Mhz)
	and Serial LCD Module 16x2 from NKC Electronics.
*/

//----- defining bit banging serial values:------------------------------------
#define	TXDATA    1         // Pin used to transmit data.
#define BITTIME   93        // Adjusted with osciloscope to obtain 9600 bauds.

//----------variables:---------------------------------------------------------
int 	seconds= 0;		//seconds counter
String 	number;			//String to be sent to the display.
//=============================================================================
void setup() {                
	pinMode(TXDATA, OUTPUT);   // initialize the TXDATA pin as an output.
	digitalWrite(TXDATA,HIGH); // TXDATA = 5V when is resting.
//---LCD Display initialisation---
	delay(500);
	sendChar(0xFE);
	sendChar(0x41);		//display on.
	sendChar(0xFE);
	sendChar(0x51);		//clear display.
	sendChar(0xFE);
	sendChar(0x4C);		//cursor blinking Off.
	sendChar(0xFE);
	sendChar(0x48);		//cursor Off.
	sendChar(0xFE);
	sendChar(0x46);		//cursor at home.
	sendChar(0xFE);
	sendChar(0x53);		//backlight brightness command.
	sendChar(4);		//brightness 1-8
	sendChar(0xFE);
	sendChar(0x52);		//contrast command.
	sendChar(45);		//contrast 1-50
	show(" Arduining.com");
}

//================= Main loop =================================================
void loop() {
	if ((millis() % 1000)<2){ 				//Skip until the next second.

		sendChar(0xFE);
		sendChar(0x45);						// Set cursor at
		sendChar(0x45);						// line 2 pos 6

		number = String (seconds/60);		//elapsed minutes
		while(number.length()<2)number= "0" + number;   //format to 2 characters.
		show(number); 						//Show minutes in the display

		sendChar(':');

		number = String (seconds % 60);		//elapsed seconds
		while(number.length()<2)number= "0" + number;   //format to 2 characters.
		show(number); 						//Show seconds in the display

   		seconds++;
   		if (seconds >= 3600) seconds=0;		//roll over
	}
}

//-----------------------------------------------------------------------------
void sendChar(char c){
	delayMicroseconds(BITTIME*2);          		// wait 2 Stop bits.
	digitalWrite(TXDATA,LOW);              		// TXDATA=0.
	delayMicroseconds(BITTIME);            		// wait Start bit.
	for (int i=0; i<8;i++){
		digitalWrite(TXDATA,bitRead(c, i)); 	// bit out.
		delayMicroseconds(BITTIME);          	// wait bit
	}
	digitalWrite(TXDATA,HIGH);            		//TXDATA=1.
}

//-----------------------------------------------------------------------------
void show(String s){
	int lenght=s.length();
	for(int i=0;i<lenght;i++){
	sendChar(s[i]);
	}
}

Sketch without string functions:

/*	Test_LCD_01.ino
	Arduining.com  17 FEB 2014
	Based in Test_LCD.ino (2,278 bytes less avoiding string functions).
	Binary sketch size: 1,356 bytes (of a 5,310 byte maximum)

	A timer is implemented presenting minutes and seconds elapsed since start.
	Bit Banging Serial transmission at 9600 bauds.
	Example using the Trinket from Adafruit (5V, 8 Mhz)
	and Serial LCD Module 16x2 from NKC Electronics.
*/

//----- defining bit banging serial values:------------------------------------
#define	TXDATA    1         // Pin used to transmit data.
#define BITTIME   93        // Adjusted with osciloscope to obtain 9600 bauds.

//----------variables:---------------------------------------------------------
int 	seconds= 0;		//seconds counter
//=============================================================================
void setup() {                
	pinMode(TXDATA, OUTPUT);   // initialize the TXDATA pin as an output.
	digitalWrite(TXDATA,HIGH); // TXDATA = 5V when is resting.
//---LCD Display initialisation---
	delay(500);
	sendChar(0xFE);
	sendChar(0x41);		//display on.
	sendChar(0xFE);
	sendChar(0x51);		//clear display.
	sendChar(0xFE);
	sendChar(0x4C);		//cursor blinking Off.
	sendChar(0xFE);
	sendChar(0x48);		//cursor Off.
	sendChar(0xFE);
	sendChar(0x46);		//cursor at home.
	sendChar(0xFE);
	sendChar(0x53);		//backlight brightness command.
	sendChar(4);		//brightness 1-8
	sendChar(0xFE);
	sendChar(0x52);		//contrast command.
	sendChar(45);		//contrast 1-50
	show(" Arduining.com");
}

//================= Main loop =================================================
void loop() {
	if ((millis() % 1000)<2){ 				//Skip until the next second.

		sendChar(0xFE);
		sendChar(0x45);						// Set cursor at
		sendChar(0x45);						// line 2 pos 6

		sendChar((seconds/600)+'0');		//show tens of minutes 
		sendChar(((seconds/60) % 10)+'0');	//show units of minutes
		sendChar(':');
		sendChar(((seconds % 60)/10)+'0');	//show tens of seconds
		sendChar((seconds % 10)+'0');		//show units of seconds
   		seconds++;
   		if (seconds >= 3600) seconds=0;		//roll over
	}
}

//-----------------------------------------------------------------------------
void sendChar(char c){
	delayMicroseconds(BITTIME*2);          		// wait 2 Stop bits.
	digitalWrite(TXDATA,LOW);              		// TXDATA=0.
	delayMicroseconds(BITTIME);            		// wait Start bit.
	for (int i=0; i<8;i++){
		digitalWrite(TXDATA,bitRead(c, i)); 	// bit out.
		delayMicroseconds(BITTIME);          	// wait bit
	}
	digitalWrite(TXDATA,HIGH);            		//TXDATA=1.
}

//-----------------------------------------------------------------------------
void show(char s[]){
	int i=0;
	while(s[i]!=0){					//looking for the string end.
		sendChar(s[i]);
		i++	;
	}
}

Arduino Trinket and Gauge Stepper Motor

January 31, 2014 4 comments

Driving directly a stepper motor used for Vehicle’s Instrument Gauges.

wpid-20140131_232948.jpg

The motor must be removed during the Sketch Loading (disconnect from USB pins) .

wpid-IMG_20140131_235102.jpg

This kind of motors can be driven directly by the Trinket.
The motor follows the potentiometer.

IMG_0009

The Sketch is the same used in the “Arduino Driving a Micro Stepper Motor” in this blog, just change the pin mapping to use the Trinket .

http://arduining.com/2012/04/22/arduino-driving-a-micro-stepper-motor/

Change the definitions in “Gauge_Pot01.ino”:

#define  STEPS  720    // steps per revolution (limited to 315°)
#define COIL1  1
#define COIL2  3
#define COIL3  4
#define COIL4  0
#define POTIN  1

The YouTube video…

 

Arduino Trinket Pinout Diagram

January 30, 2014 Leave a comment

A small pin mapping reference to arduining with the Trinket (5V version).
I have to admit that this little one from Adafruit is awesome!
Happy Wiring !!!…

image

Note: to use PB4 as analog output (PWM) aditional software setting is needed.

The ATtiny85 microcontroller from Atmel is the “heart” of the Trinket.
image

Categories: Trinket Projects

Arduino Trinket and RC Servo

January 26, 2014 Leave a comment

Testing SoftwareSerial library in the Trinket to drive the  7-Segment Serial Display COM-11441 (Sparkfun)
The potentiometer value was maped in the range 900 to 2100 microseconds to generate the servo control pulses.

IMG_0008

The Serial Display  shows the pulse duration in milliseconds.

wpid-20140126_233030.jpg

Using bit banging instead of SoftwareSerial saves more than 2K of program memory.

wpid-20140126_234312.jpg

The YouTube video:

Serial bit banging with Arduino Trinket

January 22, 2014 2 comments

Serial transmission at 9600 bauds is possible with the Trinket ATtiny85 (5Volts, 8Mhz) from Adafruit.
The analog value (0~1023) presented at the analog pin 1 is serially transmited to the COM-11441 ( 7-segments Serial Display from Sparkfun).

wpid-20140122_215515.jpg

The Sketch:

/* Pot_Display7_02.ino
   Arduining.com 20 JAN 2014
   Serial transmission at 9600 bauds using bit banging.(Trinket (5V, 8mhz).
   Analog 1 in presented in the 7-Segment Serial Display COM-11441 from Sparkfun.
   Using delayMicroseconds() for serial timming.
   BITTIME = 93 was adjusted using PROTEUS.
*/

//----- defining some values:-------------------------------------------------
#define TXDATA  0       // Pin used to transmit data.
#define POT     1       // pin used to read the analog value.
#define BITTIME 93      // adjusted to obtain 104 milliseconds delay (9600bauds).

//----------variables:--------------------------------------------------------
  int potVal=0;
//============================================================================
void setup() {                
  pinMode(TXDATA, OUTPUT);   // initialize the TXDATA pin as an output.
  digitalWrite(TXDATA,HIGH); // TXDATA = 5V when is resting.
  delay(10);                 //Wait for Serial Display startup.
  sendChar('v');             //Reset the display 0x76.
}

//----------------------------------------------------------------------------
void sendChar(char c){
  delayMicroseconds(BITTIME*2);          // wait 2 Stop bits before sending the char
  digitalWrite(TXDATA,LOW);              // low the line
  delayMicroseconds(BITTIME);            // wait Start bit
  for (int i=0; i<8;i++){
    digitalWrite(TXDATA,bitRead(c, i));  // bit out.
    delayMicroseconds(BITTIME);          // wait bit
  }
   digitalWrite(TXDATA,HIGH);            //Return TXDATA pin to "1".
}

//-------------------------------------------------------------------------
void show(String s){
  for(int i=0;i<4;i++){
    sendChar(s[i]);
  }
}

//=========================================================================
void loop() {
  potVal= analogRead(POT);
  String strPot = String (potVal);
  while(strPot.length()<4)strPot= " " + strPot;   //format to 4 characters.
  show(strPot);
  delay(100);  
}

Then the potentiometer is replaced by a keypad 3×4 and some resistors.

wpid-20140122_010116.jpg

The resistor networw is designed to produce diferent voltage levels for each key pressed.

image

Using simulation to adjust the serial transmitter timing.

image

And this is the Sketch using the keypad:

/* AnalogKey_03.ino
   Arduining.com 23 JAN 2014
   Using an analog pin to read a 3x4 keypad and presenting the keyed data in the
   7-Segment Serial Display COM-11441 from Sparkfun.
   Notes:
     Implemented using the Arduino Trinket (5V, 8Mhz) from Adafruit. 
     Serial transmission at 9600 bauds using bit banging.
     BITTIME delay was determined using an oscilloscope.
     1% resistors are used in the keypad (1.62k,6.49k and 25.5k) 
*/

//----- defining some values:-------------------------------------------------
#define TXDATA    0         // Pin used to transmit data.
#define ADIN      1         // pin used to read the analog value.
#define BITTIME   93        // Adjusted with PROTEUS to obtain 9600 bauds.
#define DEBOUNCE  5         // number of detections before key validation.

//----------variables:--------------------------------------------------------
  int lastkey= -1;          // No key.
  int key;                  // key value
  boolean released= true;   // No key pressed estatus.
  boolean  newline= true;   // flag to clean screen before new value entry.
  int validkey=0;           // used as debounce counter.
  int analog;               // value of the analog pin.
  char dispbuff[]= "-   ";
//============================================================================
void setup() {                
  pinMode(TXDATA, OUTPUT);   // initialize the TXDATA pin as an output.
  digitalWrite(TXDATA,HIGH); // TXDATA = 5V when is resting.
  delay(10);                 //Wait for Serial Display startup.
  sendChar('v');             //Reset the display 0x76.
}

//----------------------------------------------------------------------------
void sendChar(char c){
  delayMicroseconds(BITTIME*2);          // wait 2 Stop bits.
  digitalWrite(TXDATA,LOW);              // TXDATA=0.
  delayMicroseconds(BITTIME);            // wait Start bit.
  for (int i=0; i<8;i++){
    digitalWrite(TXDATA,bitRead(c, i));  // bit out.
    delayMicroseconds(BITTIME);          // wait bit
  }
   digitalWrite(TXDATA,HIGH);            //TXDATA=1.
}

//--------------------------------------------------------------------------
void show(String s){
  for(int i=0;i<4;i++){
    sendChar(s[i]);
  }
}

//--------------------------------------------------------------------------
void checkey(){
  analog= analogRead(ADIN);		
  key=-1;					        // no key pressed.
  if(analog<524) key=1;
  if(analog<508) key=4;
  if(analog<491) key=7;	
  if(analog<472) key=10;	// '*' key
  if(analog<453) key=2;
  if(analog<432) key=5;
  if(analog<409) key=8;
  if(analog<385) key=0;	
  if(analog<359) key=3;
  if(analog<330) key=6;
  if(analog<299) key=9;
  if(analog<265) key=11;	// '#' key

  if (key!=lastkey){
    validkey=0;
    lastkey=key;
   }
  validkey++;
  if(validkey > DEBOUNCE){
    validkey=0;
    if (key<0){
      released= true;
      return;
    }
    else if (released == true){
      released=false;
      return; 
    }
  }
  key=-1;
}

//--------------------------------------------------------------------------
void clrbuff(){
  dispbuff[0]= '-';
  dispbuff[1]= ' ';
  dispbuff[2]= ' ';
  dispbuff[3]= ' ';
  newline= false;
}
//--------------------------------------------------------------------------
void action(){
  dispbuff[0]= 'd';
  dispbuff[1]= 'o';
  dispbuff[2]= 'n';
  dispbuff[3]= 'e';
  newline= true;
}

//==========================================================================
void loop() {
  show(dispbuff);     //Show content of the array dispbuff in the display
  checkey();
  if(key>=0){
    if(key==10) clrbuff();
    if(key==11) action();
    if(key<10){
     if (newline==true) clrbuff();
     dispbuff[0]= dispbuff[1];    //buffer shift (display shift to the left)
     dispbuff[1]= dispbuff[2];
     dispbuff[2]= dispbuff[3];
     dispbuff[3]=char(key+'0');
    }
  }
  delay(5);         // experimental, 5 works fine. (10 is to slow).
}

The video is in YouTube:

Follow

Get every new post delivered to your Inbox.