Difference between revisions of "SparkFun: QRD1114,Optical Detector/Phototransistor"
m (Updated grading comments) |
|||
Line 3: | Line 3: | ||
<pre style="color:red"> | <pre style="color:red"> | ||
− | Overview: 1, | + | Overview: 2 |
− | + | Wiring: 1, I'd rather see a picture with a bone | |
Code: 2 | Code: 2 | ||
git/Compiles with make: 0 put in git | git/Compiles with make: 0 put in git | ||
− | Demo: | + | Demo: 2 |
− | Total: | + | Total: 7/10 |
Comments: More details are needed. I think someone else in the class would have trouble | Comments: More details are needed. I think someone else in the class would have trouble | ||
reproducing what you have done. | reproducing what you have done. |
Revision as of 13:47, 17 October 2012
Overview: 2 Wiring: 1, I'd rather see a picture with a bone Code: 2 git/Compiles with make: 0 put in git Demo: 2 Total: 7/10 Comments: More details are needed. I think someone else in the class would have trouble reproducing what you have done.
Contents
Overview
The QRD1114 is a Optical Detector/Phototransistor that can be purchased from SparkFun. The datasheet describes it as:
This sensor uses an infrared emitted diode combined with an infrared phototransistor to detect the reflected infrared signal. Ideal for sensing black-to-white transitions or can be used to detect nearby objects (.5-1cm).
Inputs and Outputs
The QRD1114 takes a supply voltage (Vs) of 0-5 V, while outputs via serial terminal.
Connecting to the Bone
The QRD1114 connects directly to the Beaglebone via one of the Analog In pins namely ain0-ain5. (ain5 in this case) Also, with the other legs of the device connected to VDD_ADC(1.8V) and GND respectively.
Note: The only change thats is different from the image and on the bone: One of the legs is connected to the VDD_ADC(1.8V) pin on the bone (Pin 32) instead of the VDD_5V (pin 5) on the bone and the other shown is connected to GNDA_ADC (Pin 34) instead of the default pin 1.
Code
Sample C Code
/**************************************************************** ****************************************************************/ #include <errno.h> #include <string.h> #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <poll.h> #include <signal.h> #include <unistd.h> /**************************************************************** * Constants ****************************************************************/ #define MAX_BUF 64 /**************************************************************** * Global Variables ****************************************************************/ int keepgoing = 1; void signal_handler(int sig) { printf( "Ctrl-C pressed, cleaning up and exiting..\n" ); keepgoing = 0; } /**************************************************************** * read_ain ****************************************************************/ int read_ain(char* ain){ FILE *fp; char ainPath[MAX_BUF]; char ainRead[MAX_BUF]; snprintf(ainPath, sizeof ainPath, "/sys/devices/platform/omap/tsc/%s", ain); if((fp = fopen(ainPath, "r")) == NULL){ printf("Cannot open specified ain pin, %s\n", ain); return 1; } if(fgets(ainRead, MAX_BUF, fp) == NULL){ printf("Cannot read specified ain pin, %s\n", ain); } fclose(fp); return atoi(ainRead); } /**************************************************************** * Main ****************************************************************/ int main(int argc, char **argv){ int ainPin; char ain[MAX_BUF]; float duty_cycle = 0; float avgDutyCycle = 0; int avgCount = 1; if (argc < 2){ printf("Usage: ./MiniProject02 <ainpin>"); exit(-1); } signal(SIGINT, signal_handler); ainPin = atoi(argv[1]); snprintf(ain, sizeof ain, "ain%d", ainPin); while (keepgoing) { usleep(100000); duty_cycle = read_ain(ain); printf(" \r"); printf("Value: %d\r\n",(int)duty_cycle); fflush(stdout); } fflush(stdout); return 0; }
You must specify the ain pin number as the first argument when executing this code after it is compiled.
Results
From observation, the darker the room, the higher the value that is outputted and vice versa the lighter the room, the lower the value is that is outputted.