Skip to content

Commit

Permalink
updating examples, removing serial and wire begin from inside of lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew England committed Jun 21, 2019
1 parent a12f0cc commit f722e31
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 106 deletions.
43 changes: 42 additions & 1 deletion examples/Example1_BasicReadings/Example1_BasicReadings.ino
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,51 @@
AS726X sensor;

void setup() {
Wire.begin();
Serial.begin(115200);

sensor.begin();
}

void loop() {
sensor.takeMeasurements();
sensor.printMeasurements();
//Prints all measurements
if (sensor.getVersion() == SENSORTYPE_AS7262)
{
//Visible readings
Serial.print(" Reading: V[");
Serial.print(sensor.getCalibratedViolet(), 2);
Serial.print("] B[");
Serial.print(sensor.getCalibratedBlue(), 2);
Serial.print("] G[");
Serial.print(sensor.getCalibratedGreen(), 2);
Serial.print("] Y[");
Serial.print(sensor.getCalibratedYellow(), 2);
Serial.print("] O[");
Serial.print(sensor.getCalibratedOrange(), 2);
Serial.print("] R[");
Serial.print(sensor.getCalibratedRed(), 2);
}
else if (sensor.getVersion() == SENSORTYPE_AS7263)
{
//Near IR readings
Serial.print(" Reading: R[");
Serial.print(sensor.getCalibratedR(), 2);
Serial.print("] S[");
Serial.print(sensor.getCalibratedS(), 2);
Serial.print("] T[");
Serial.print(sensor.getCalibratedT(), 2);
Serial.print("] U[");
Serial.print(sensor.getCalibratedU(), 2);
Serial.print("] V[");
Serial.print(sensor.getCalibratedV(), 2);
Serial.print("] W[");
Serial.print(sensor.getCalibratedW(), 2);
}

Serial.print("] tempF[");
Serial.print(sensor.getTemperatureF(), 1);
Serial.print("]");

Serial.println();
}
43 changes: 42 additions & 1 deletion examples/Example2_SensorSettings/Example2_SensorSettings.ino
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,51 @@ byte GAIN = 0;
byte MEASUREMENT_MODE = 0;

void setup() {
Wire.begin();
Serial.begin(115200);

sensor.begin(Wire, GAIN, MEASUREMENT_MODE);//Initializes the sensor with non default values
}

void loop() {
sensor.takeMeasurements();
sensor.printMeasurements();

if (sensor.getVersion() == SENSORTYPE_AS7262)
{
//Visible readings
Serial.print(" Reading: V[");
Serial.print(sensor.getCalibratedViolet(), 2);
Serial.print("] B[");
Serial.print(sensor.getCalibratedBlue(), 2);
Serial.print("] G[");
Serial.print(sensor.getCalibratedGreen(), 2);
Serial.print("] Y[");
Serial.print(sensor.getCalibratedYellow(), 2);
Serial.print("] O[");
Serial.print(sensor.getCalibratedOrange(), 2);
Serial.print("] R[");
Serial.print(sensor.getCalibratedRed(), 2);
}
else if (sensor.getVersion() == SENSORTYPE_AS7263)
{
//Near IR readings
Serial.print(" Reading: R[");
Serial.print(sensor.getCalibratedR(), 2);
Serial.print("] S[");
Serial.print(sensor.getCalibratedS(), 2);
Serial.print("] T[");
Serial.print(sensor.getCalibratedT(), 2);
Serial.print("] U[");
Serial.print(sensor.getCalibratedU(), 2);
Serial.print("] V[");
Serial.print(sensor.getCalibratedV(), 2);
Serial.print("] W[");
Serial.print(sensor.getCalibratedW(), 2);
}

Serial.print("] tempF[");
Serial.print(sensor.getTemperatureF(), 1);
Serial.print("]");

Serial.println();
}
41 changes: 40 additions & 1 deletion examples/Example3_BulbReadings/Example3_BulbReadings.ino
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,45 @@ void setup() {
}

void loop() {
Wire.begin();
Serial.begin(115200);

sensor.takeMeasurementsWithBulb();
sensor.printMeasurements();

if (sensor.getVersion() == SENSORTYPE_AS7262)
{
//Visible readings
Serial.print(" Reading: V[");
Serial.print(sensor.getCalibratedViolet(), 2);
Serial.print("] B[");
Serial.print(sensor.getCalibratedBlue(), 2);
Serial.print("] G[");
Serial.print(sensor.getCalibratedGreen(), 2);
Serial.print("] Y[");
Serial.print(sensor.getCalibratedYellow(), 2);
Serial.print("] O[");
Serial.print(sensor.getCalibratedOrange(), 2);
Serial.print("] R[");
Serial.print(sensor.getCalibratedRed(), 2);
}
else if (sensor.getVersion() == SENSORTYPE_AS7263)
{
//Near IR readings
Serial.print(" Reading: R[");
Serial.print(sensor.getCalibratedR(), 2);
Serial.print("] S[");
Serial.print(sensor.getCalibratedS(), 2);
Serial.print("] T[");
Serial.print(sensor.getCalibratedT(), 2);
Serial.print("] U[");
Serial.print(sensor.getCalibratedU(), 2);
Serial.print("] V[");
Serial.print(sensor.getCalibratedV(), 2);
Serial.print("] W[");
Serial.print(sensor.getCalibratedW(), 2);
}

Serial.print("] tempF[");
Serial.print(sensor.getTemperatureF(), 1);
Serial.print("]");
}
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=SparkFun AS726X
version=1.0.2
version=1.0.3
author=Andrew England
maintainer=SparkFun Electronics <sparkfun.com>
sentence=A library to drive the AMS AS726X NIR/VIS Spectrum Sensor
paragraph=See code for comments.
paragraph=The SparkFun AS726X Visible Spectral Sensor Breakout brings spectroscopy to the palm of your hand, making it easier than ever to measure and characterize how different materials absorb and reflect different wavelengths of light. The AS726X Breakout is unique in its ability to communicate by both an I2C interface and serial interface using AT commands. Hookup is easy, thanks to the Qwiic connectors attached to the board --- simply plug one end of the Qwiic cable into the breakout and the other into one of the Qwiic Shields, then stack the board on a development board. You’ll be ready to upload a sketch to start taking spectroscopy measurements in no time.
category=Sensors
url=https://github.com/sparkfun/SparkFun_AS726X_Arduino_Library
architectures=*
106 changes: 8 additions & 98 deletions src/AS726X.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ AS726X::AS726X()

}

void AS726X::begin(TwoWire &wirePort, byte gain, byte measurementMode)
bool AS726X::begin(TwoWire &wirePort, byte gain, byte measurementMode)
{
_i2cPort = &wirePort;
_i2cPort->begin();
Serial.begin(115200);
_sensorVersion = virtualReadRegister(AS726x_HW_VERSION);
if (_sensorVersion != 0x3E && _sensorVersion != 0x3F) //HW version for AS7262 and AS7263
{
Serial.print("ID (should be 0x3E or 0x3F): 0x");
Serial.println(_sensorVersion, HEX);
return false;
}

setBulbCurrent(0b00); //Set to 12.5mA (minimum)
Expand All @@ -35,12 +32,14 @@ void AS726X::begin(TwoWire &wirePort, byte gain, byte measurementMode)

if (_sensorVersion == 0)
{
Serial.println("Sensor failed to respond. Check wiring.");
while (1); //Freeze!
return false;
}
return true;
}

if (_sensorVersion == SENSORTYPE_AS7262) Serial.println("AS7262 online!");
if (_sensorVersion == SENSORTYPE_AS7263) Serial.println("AS7263 online!");
uint8_t AS726X::getVersion()
{
return _sensorVersion;
}

//Sets the measurement mode
Expand Down Expand Up @@ -100,95 +99,6 @@ void AS726X::disableInterrupt()
virtualWriteRegister(AS726x_CONTROL_SETUP, value); //Write
}

//Prints all measurements
void AS726X::printMeasurements()
{
float tempF = getTemperatureF();

if (_sensorVersion == SENSORTYPE_AS7262)
{
//Visible readings
Serial.print(" Reading: V[");
Serial.print(getCalibratedViolet(), 2);
Serial.print("] B[");
Serial.print(getCalibratedBlue(), 2);
Serial.print("] G[");
Serial.print(getCalibratedGreen(), 2);
Serial.print("] Y[");
Serial.print(getCalibratedYellow(), 2);
Serial.print("] O[");
Serial.print(getCalibratedOrange(), 2);
Serial.print("] R[");
Serial.print(getCalibratedRed(), 2);
}
else if (_sensorVersion == SENSORTYPE_AS7263)
{
//Near IR readings
Serial.print(" Reading: R[");
Serial.print(getCalibratedR(), 2);
Serial.print("] S[");
Serial.print(getCalibratedS(), 2);
Serial.print("] T[");
Serial.print(getCalibratedT(), 2);
Serial.print("] U[");
Serial.print(getCalibratedU(), 2);
Serial.print("] V[");
Serial.print(getCalibratedV(), 2);
Serial.print("] W[");
Serial.print(getCalibratedW(), 2);
}

Serial.print("] tempF[");
Serial.print(tempF, 1);
Serial.print("]");

Serial.println();
}

void AS726X::printUncalibratedMeasurements()
{
float tempF = getTemperatureF();

if (_sensorVersion == SENSORTYPE_AS7262)
{
//Visible readings
Serial.print(" Reading: V[");
Serial.print(getViolet());
Serial.print("] B[");
Serial.print(getBlue());
Serial.print("] G[");
Serial.print(getGreen());
Serial.print("] Y[");
Serial.print(getYellow());
Serial.print("] O[");
Serial.print(getOrange());
Serial.print("] R[");
Serial.print(getRed());
}
else if (_sensorVersion == SENSORTYPE_AS7263)
{
//Near IR readings
Serial.print(" Reading: R[");
Serial.print(getR());
Serial.print("] S[");
Serial.print(getS());
Serial.print("] T[");
Serial.print(getT());
Serial.print("] U[");
Serial.print(getU());
Serial.print("] V[");
Serial.print(getV());
Serial.print("] W[");
Serial.print(getW());
}

Serial.print("] tempF[");
Serial.print(tempF, 1);
Serial.print("]");

Serial.println();
}

//Tells IC to take measurements and polls for data ready flag
void AS726X::takeMeasurements()
{
Expand Down
5 changes: 2 additions & 3 deletions src/AS726X.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
class AS726X {
public:
AS726X();
void begin(TwoWire &wirePort = Wire, byte gain = 3, byte measurementMode = 3);
bool begin(TwoWire &wirePort = Wire, byte gain = 3, byte measurementMode = 3);
void takeMeasurements();
uint8_t getVersion();
void takeMeasurementsWithBulb();
void printMeasurements();
void printUncalibratedMeasurements();
byte getTemperature();
float getTemperatureF();
void setMeasurementMode(byte mode);
Expand Down

0 comments on commit f722e31

Please sign in to comment.