Difference between revisions of "Sensors: TSL2591"
(→Code) |
(→Code) |
||
Line 10: | Line 10: | ||
===Code=== | ===Code=== | ||
+ | <nowiki> | ||
//http://www.raspberrypi.org/forums/viewtopic.php?t=67979&p=496252 | //http://www.raspberrypi.org/forums/viewtopic.php?t=67979&p=496252 | ||
Line 58: | Line 59: | ||
gcc 2591_pi_2.cpp 2591a.cpp -lwiringPi -o 2591 | gcc 2591_pi_2.cpp 2591a.cpp -lwiringPi -o 2591 | ||
− | */ | + | */ </nowiki> |
Revision as of 16:00, 20 May 2015
TSL2591 library conversion
Procedure
- Stared with Adafruit's Adafruit_TSL2591_Library
- Replaced the Adrino's reads and writes with call to the wiringPi library
- Sanity checked the code against this JS program:
- Tested it and fixed a "bug".
Code
//http://www.raspberrypi.org/forums/viewtopic.php?t=67979&p=496252 // ALL COMMAND TSL2561 // Default I2C RPI address in (0x39) = FLOAT ADDR (Slave) Other [(0x49) = VCC ADDR / (0x29) = GROUND ADDR] #define TSL2561_ADDR_LOW (0x29) #define TSL2561_ADDR_FLOAT (0x39) #define TSL2561_ADDR_HIGH (0x49) #include "2591a.h" #include <unistd.h> int main(){ Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591); // pass in a number for the sensor identifier (for your use later) int fd = 0; fd = wiringPiI2CSetup(0x29); uint16_t ch0,ch1; uint32_t visible_and_ir, lux; visible_and_ir = tsl.Adafruit_TSL2591::getFullLuminosity (fd); sleep(1); visible_and_ir = tsl.Adafruit_TSL2591::getFullLuminosity (fd); // Reads two byte value from channel 0 (visible + infrared) ch0 = (visible_and_ir & 0xFFFF); // Reads two byte value from channel 1 (infrared) ch1 = (visible_and_ir >> 16); lux = tsl.Adafruit_TSL2591::calculateLux(ch0, ch1); printf("TSL2591 Full Spectrum: %zu\n",ch0); printf("TSL2591 Infrared: %zu\n",ch1); if ( ch0 >= ch1 ) printf("TSL2591 Visible: %zu\n",ch0-ch1); printf("TSL2591 Lux: %zu\n", lux); } /* NOTE: To compile programs with wiringPi, you need to add: -lwiringPi to your compile line(s) To use the Gertboard, MaxDetect, etc. code (the devLib), you need to also add: -lwiringPiDev to your compile line(s). gcc 2591_pi_2.cpp 2591a.cpp -lwiringPi -o 2591 */