SpectralSensor Spectral Sensor Spektroskop + test wyświetlacza
This commit is contained in:
90
LeonardoProMicro/DiagInterrupt/DiagInterrupt.ino
Normal file
90
LeonardoProMicro/DiagInterrupt/DiagInterrupt.ino
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
//#include <avr/eeprom.h>
|
||||||
|
//#include <Servo.h> // model servo: DS3218 PRO
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <Adafruit_GFX.h>
|
||||||
|
#include <Adafruit_SSD1306.h>
|
||||||
|
|
||||||
|
#define Version "0"
|
||||||
|
//ostatnia zmiana: zmiana na PCB, dostrajanie
|
||||||
|
////2DO:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define SCREEN_WIDTH 128
|
||||||
|
#define SCREEN_HEIGHT 64
|
||||||
|
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
|
||||||
|
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
|
||||||
|
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||||
|
#define PinInSpeed 0 //on board: RXI
|
||||||
|
#define ServoSwitch 4 //on board: 4
|
||||||
|
#define ServoPin 8 //on board: 8
|
||||||
|
#define BrakingLight 9 //on board: 9 BrakingLight
|
||||||
|
#define PinLED 10 //on board: 10 ORANGE loop signal
|
||||||
|
#define Btn1 18 //on board: A0 Button0
|
||||||
|
#define Btn2 19 //on board: A1 Button1
|
||||||
|
|
||||||
|
#define ServoMaxAngle 130
|
||||||
|
#define MaxAngle 179
|
||||||
|
#define MinAngle 1
|
||||||
|
#define MaxGear 8
|
||||||
|
#define MinGear 1
|
||||||
|
#define WheelCircumference 2.130
|
||||||
|
#define MagnetsCnt 4
|
||||||
|
#define ms2kmh 3.6
|
||||||
|
#define Pi 3.1416
|
||||||
|
#define TimeToSleep 180000 //3 min
|
||||||
|
|
||||||
|
|
||||||
|
//SPEED
|
||||||
|
int interpt_cnt = 0;
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
//SERVO
|
||||||
|
|
||||||
|
//
|
||||||
|
// Serial.begin(9600);
|
||||||
|
|
||||||
|
//DIPLAY settings
|
||||||
|
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
|
||||||
|
Serial.println(F("SSD1306 allocation failed"));
|
||||||
|
for (;;); // Don't proceed, loop forever
|
||||||
|
}
|
||||||
|
display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setTextColor(WHITE);
|
||||||
|
display.setRotation(0);
|
||||||
|
display.setTextSize(3);
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
display.println("Version:");
|
||||||
|
display.setCursor(0, 25);
|
||||||
|
display.println(Version);
|
||||||
|
display.display();
|
||||||
|
delay(5);
|
||||||
|
//INPUT
|
||||||
|
pinMode(PinInSpeed, INPUT_PULLUP);
|
||||||
|
pinMode(9, INPUT_PULLUP);
|
||||||
|
//Interrupts
|
||||||
|
attachInterrupt(digitalPinToInterrupt(PinInSpeed), diag, FALLING);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
int local_interpt_cnt = 0;
|
||||||
|
noInterrupts();
|
||||||
|
local_interpt_cnt = interpt_cnt;
|
||||||
|
interrupts();
|
||||||
|
|
||||||
|
display.clearDisplay();
|
||||||
|
display.println("Interupts cnt: ");
|
||||||
|
display.setCursor(0, 20);
|
||||||
|
display.println(local_interpt_cnt);
|
||||||
|
display.setTextSize(2);
|
||||||
|
display.display();
|
||||||
|
delay(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
void diag(){
|
||||||
|
interpt_cnt = interpt_cnt +1;
|
||||||
|
}
|
||||||
44
LeonardoProMicro/DisplayTest/DisplayTest.ino
Normal file
44
LeonardoProMicro/DisplayTest/DisplayTest.ino
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
#include <SPI.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <Adafruit_GFX.h>
|
||||||
|
#include <Adafruit_SSD1306.h>
|
||||||
|
|
||||||
|
Adafruit_SSD1306 display(4);
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
|
||||||
|
display.clearDisplay();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
digitalWrite(5, LOW);
|
||||||
|
delay(10);
|
||||||
|
digitalWrite(5, HIGH);
|
||||||
|
delay(3);
|
||||||
|
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setTextSize(1);
|
||||||
|
display.setTextColor(WHITE);
|
||||||
|
display.drawLine(0, 0, 120, 32, WHITE);
|
||||||
|
display.drawRect(1, 1, 126, 30, WHITE);
|
||||||
|
display.setCursor(4, 4);
|
||||||
|
display.println("ELEKTRONIKA.PL");
|
||||||
|
display.display();
|
||||||
|
delay(2000);
|
||||||
|
display.setCursor(10, 16);
|
||||||
|
|
||||||
|
display.println("SKLEP Z ELEKTRONIKA");
|
||||||
|
display.display();
|
||||||
|
display.clearDisplay();
|
||||||
|
delay(3000);
|
||||||
|
display.setCursor(4, 16);
|
||||||
|
display.println("SUBSKRYBUJ TEN KANAL");
|
||||||
|
display.display();
|
||||||
|
delay(3000);
|
||||||
|
|
||||||
|
display.drawPixel(120, 30, WHITE);
|
||||||
|
display.display();
|
||||||
|
|
||||||
|
}
|
||||||
BIN
LeonardoProMicro/SpectralSensor/AS7262.pdf
Normal file
BIN
LeonardoProMicro/SpectralSensor/AS7262.pdf
Normal file
Binary file not shown.
128
LeonardoProMicro/SpectralSensor/Example1_BasicReadings..txt
Normal file
128
LeonardoProMicro/SpectralSensor/Example1_BasicReadings..txt
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
/*
|
||||||
|
This is a library written for the AS726X Spectral Sensor (Visible or IR) with I2C firmware
|
||||||
|
specially loaded. SparkFun sells these at its website: www.sparkfun.com
|
||||||
|
|
||||||
|
Written by Nathan Seidle & Andrew England @ SparkFun Electronics, July 12th, 2017
|
||||||
|
|
||||||
|
https://github.com/sparkfun/Qwiic_Spectral_Sensor_AS726X
|
||||||
|
|
||||||
|
Do you like this library? Help support SparkFun. Buy a board!
|
||||||
|
|
||||||
|
Development environment specifics:
|
||||||
|
Arduino IDE 1.8.1
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
---AVAILABLE FUNCTIONS---
|
||||||
|
AS726X(TwoWire &wirePort = Wire, byte gain = 3, byte measurementMode = 3);
|
||||||
|
void takeMeasurements();
|
||||||
|
void takeMeasurementsWithBulb();
|
||||||
|
void printMeasurements();
|
||||||
|
byte getTemperature();
|
||||||
|
float getTemperatureF();
|
||||||
|
void setMeasurementMode(byte mode);
|
||||||
|
boolean dataAvailable();
|
||||||
|
void enableIndicator();
|
||||||
|
void disableIndicator();
|
||||||
|
void setIndicatorCurrent(byte current);
|
||||||
|
void enableBulb();
|
||||||
|
void disableBulb();
|
||||||
|
void setBulbCurrent(byte current);
|
||||||
|
void softReset();
|
||||||
|
void setGain(byte gain);
|
||||||
|
void setIntegrationTime(byte integrationValue);
|
||||||
|
void enableInterrupt();
|
||||||
|
void disableInterrupt();
|
||||||
|
|
||||||
|
//Get the various color readings
|
||||||
|
int getViolet();
|
||||||
|
int getBlue();
|
||||||
|
int getGreen();
|
||||||
|
int getYellow();
|
||||||
|
int getOrange();
|
||||||
|
int getRed();
|
||||||
|
|
||||||
|
//Get the various NIR readings
|
||||||
|
int getR();
|
||||||
|
int getS();
|
||||||
|
int getT();
|
||||||
|
int getU();
|
||||||
|
int getV();
|
||||||
|
int getW();
|
||||||
|
|
||||||
|
//Returns the various calibration data
|
||||||
|
float getCalibratedViolet();
|
||||||
|
float getCalibratedBlue();
|
||||||
|
float getCalibratedGreen();
|
||||||
|
float getCalibratedYellow();
|
||||||
|
float getCalibratedOrange();
|
||||||
|
float getCalibratedRed();
|
||||||
|
|
||||||
|
float getCalibratedR();
|
||||||
|
float getCalibratedS();
|
||||||
|
float getCalibratedT();
|
||||||
|
float getCalibratedU();
|
||||||
|
float getCalibratedV();
|
||||||
|
float getCalibratedW();
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "AS726X.h"
|
||||||
|
|
||||||
|
AS726X sensor;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Wire.begin();
|
||||||
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
sensor.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
sensor.takeMeasurements();
|
||||||
|
//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();
|
||||||
|
}
|
||||||
129
LeonardoProMicro/SpectralSensor/SpectralSensor.ino
Normal file
129
LeonardoProMicro/SpectralSensor/SpectralSensor.ino
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
/*
|
||||||
|
This is a library written for the AS726X Spectral Sensor (Visible or IR) with I2C firmware
|
||||||
|
specially loaded. SparkFun sells these at its website: www.sparkfun.com
|
||||||
|
|
||||||
|
Written by Nathan Seidle & Andrew England @ SparkFun Electronics, July 12th, 2017
|
||||||
|
|
||||||
|
https://github.com/sparkfun/Qwiic_Spectral_Sensor_AS726X
|
||||||
|
|
||||||
|
Do you like this library? Help support SparkFun. Buy a board!
|
||||||
|
|
||||||
|
Development environment specifics:
|
||||||
|
Arduino IDE 1.8.1
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
---AVAILABLE FUNCTIONS---
|
||||||
|
AS726X(TwoWire &wirePort = Wire, byte gain = 3, byte measurementMode = 3);
|
||||||
|
void takeMeasurements();
|
||||||
|
void takeMeasurementsWithBulb();
|
||||||
|
void printMeasurements();
|
||||||
|
byte getTemperature();
|
||||||
|
float getTemperatureF();
|
||||||
|
void setMeasurementMode(byte mode);
|
||||||
|
boolean dataAvailable();
|
||||||
|
void enableIndicator();
|
||||||
|
void disableIndicator();
|
||||||
|
void setIndicatorCurrent(byte current);
|
||||||
|
void enableBulb();
|
||||||
|
void disableBulb();
|
||||||
|
void setBulbCurrent(byte current);
|
||||||
|
void softReset();
|
||||||
|
void setGain(byte gain);
|
||||||
|
void setIntegrationTime(byte integrationValue);
|
||||||
|
void enableInterrupt();
|
||||||
|
void disableInterrupt();
|
||||||
|
|
||||||
|
//Get the various color readings
|
||||||
|
int getViolet();
|
||||||
|
int getBlue();
|
||||||
|
int getGreen();
|
||||||
|
int getYellow();
|
||||||
|
int getOrange();
|
||||||
|
int getRed();
|
||||||
|
|
||||||
|
//Get the various NIR readings
|
||||||
|
int getR();
|
||||||
|
int getS();
|
||||||
|
int getT();
|
||||||
|
int getU();
|
||||||
|
int getV();
|
||||||
|
int getW();
|
||||||
|
|
||||||
|
//Returns the various calibration data
|
||||||
|
float getCalibratedViolet();
|
||||||
|
float getCalibratedBlue();
|
||||||
|
float getCalibratedGreen();
|
||||||
|
float getCalibratedYellow();
|
||||||
|
float getCalibratedOrange();
|
||||||
|
float getCalibratedRed();
|
||||||
|
|
||||||
|
float getCalibratedR();
|
||||||
|
float getCalibratedS();
|
||||||
|
float getCalibratedT();
|
||||||
|
float getCalibratedU();
|
||||||
|
float getCalibratedV();
|
||||||
|
float getCalibratedW();
|
||||||
|
*/
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <Adafruit_GFX.h>
|
||||||
|
#include <Adafruit_SSD1306.h>
|
||||||
|
#include "AS726X.h"
|
||||||
|
|
||||||
|
AS726X sensor;
|
||||||
|
Adafruit_SSD1306 display(4);
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Wire.begin();
|
||||||
|
Serial.begin(115200);
|
||||||
|
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
|
||||||
|
display.clearDisplay();
|
||||||
|
sensor.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setTextSize(1);
|
||||||
|
display.setTextColor(WHITE);
|
||||||
|
sensor.takeMeasurements();
|
||||||
|
//Prints all measurements
|
||||||
|
//Visible readings
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
display.println("R:");
|
||||||
|
display.setCursor(10, 0);
|
||||||
|
display.println(sensor.getCalibratedRed(), 1);
|
||||||
|
display.setCursor(0, 10);
|
||||||
|
display.println("G:");
|
||||||
|
display.setCursor(10, 10);
|
||||||
|
display.println(sensor.getCalibratedGreen(), 1);
|
||||||
|
display.setCursor(0, 20);
|
||||||
|
display.println("B:");
|
||||||
|
display.setCursor(10, 20);
|
||||||
|
display.println(sensor.getCalibratedBlue(), 1);
|
||||||
|
|
||||||
|
display.setCursor(60, 0);
|
||||||
|
display.println("O:");
|
||||||
|
display.setCursor(70, 0);
|
||||||
|
display.println(sensor.getCalibratedOrange(), 1);
|
||||||
|
display.setCursor(60, 10);
|
||||||
|
display.println("Y:");
|
||||||
|
display.setCursor(70, 10);
|
||||||
|
display.println(sensor.getCalibratedYellow(), 1);
|
||||||
|
display.setCursor(60, 20);
|
||||||
|
display.println("V:");
|
||||||
|
display.setCursor(70, 20);
|
||||||
|
display.println(sensor.getCalibratedViolet(), 1);
|
||||||
|
|
||||||
|
display.display();
|
||||||
|
delay(500);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user