|
| 1 | +/* |
| 2 | + AS7263 color sensor |
| 3 | +
|
| 4 | + Reads light readings and temperature readings from AMS AS7263 sensor. |
| 5 | + Uses Sparkfun's AS726x library. Works with both Sparkfun and Adafruit |
| 6 | + breakout boards. |
| 7 | +
|
| 8 | + Datasheet: https://ams.com/documents/20143/36005/AS7263_DS000476_1-00.pdf/4bd22964-7fe0-2053-3e97-906f0836182f |
| 9 | + |
| 10 | + Near IR wavelengths: |
| 11 | + 610nm: R |
| 12 | + 680nm: S |
| 13 | + 730nm: T |
| 14 | + 760nm: U |
| 15 | + 810nm: V |
| 16 | + 860nm: W |
| 17 | +
|
| 18 | + According to the datasheet, all channels tested under 5700K White LED light. |
| 19 | +
|
| 20 | + based on Sparkfun libraries |
| 21 | + modified 16 Feb 2020 |
| 22 | + by Tom Igoe |
| 23 | +*/ |
| 24 | + |
| 25 | +#include <AS726X.h> |
| 26 | + |
| 27 | +// make an instance of the color sensor library: |
| 28 | +AS726X colorSensor; |
| 29 | + |
| 30 | +void setup() { |
| 31 | + // initialize serial and I2C communication: |
| 32 | + Serial.begin(9600); |
| 33 | + Wire.begin(); |
| 34 | + |
| 35 | + // initialize sensor: |
| 36 | + colorSensor.begin(); |
| 37 | + |
| 38 | + // optional sensor settings: |
| 39 | + //Set the measurement mode |
| 40 | + // 0: Continuous reading of STUV |
| 41 | + // 1: Continuous reading of RTUX |
| 42 | + // 2: Continuous reading of all channels (default) |
| 43 | + // 3: One-shot reading of all channels |
| 44 | + colorSensor.setMeasurementMode(2); |
| 45 | + |
| 46 | + // Integration time = time to get good readings. |
| 47 | + // number is in units of 2.8ms. |
| 48 | + // for measurement mode 2 or 3, you need 280ms, or integrationTime(100) |
| 49 | + // default is 50: |
| 50 | + colorSensor.setIntegrationTime(100); |
| 51 | + |
| 52 | + // gain sets sensitivity: |
| 53 | + // 0: 1x (default) |
| 54 | + // 1: 3.7x |
| 55 | + // 2: 16x |
| 56 | + // 3: 64x |
| 57 | + colorSensor.setGain(3); |
| 58 | +} |
| 59 | + |
| 60 | +void loop() { |
| 61 | + // read sensor: |
| 62 | + colorSensor.takeMeasurements(); |
| 63 | + |
| 64 | + // get results: |
| 65 | + // for uncalibrated readings use .getR(), .getS(), etc. |
| 66 | + // uncalibrated readings are ints, not floats. |
| 67 | + float cR = colorSensor.getCalibratedR(); |
| 68 | + float cS = colorSensor.getCalibratedS(); |
| 69 | + float cT = colorSensor.getCalibratedT(); |
| 70 | + float cU = colorSensor.getCalibratedU(); |
| 71 | + float cV = colorSensor.getCalibratedV(); |
| 72 | + float cW = colorSensor.getCalibratedW(); |
| 73 | + String readings = "IR-R: "; |
| 74 | + readings += String(cR); |
| 75 | + readings += ", IR-S:"; |
| 76 | + readings += String(cS); |
| 77 | + readings += ", IR-T:"; |
| 78 | + readings += String(cT); |
| 79 | + readings += ", IR-U: "; |
| 80 | + readings += String(cU); |
| 81 | + readings += ", IR-V:"; |
| 82 | + readings += String(cV); |
| 83 | + readings += ", IR-W:"; |
| 84 | + readings += String(cW); |
| 85 | + |
| 86 | + // get temperature in degrees C (for degrees F, use float .getTemperatureF()) |
| 87 | + readings += ", temp.: "; |
| 88 | + readings += String(colorSensor.getTemperature()); |
| 89 | + |
| 90 | + // print results: |
| 91 | + Serial.println(readings); |
| 92 | +} |
0 commit comments