Skip to content

issue on wemos d1 r2 mini #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 6 additions & 77 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,82 +1,11 @@
SparkFun APDS9960 RGB and Gesture Sensor Arduino Library
SparkFun APDS9960 RGB and Gesture Sensor Arduino Library -- Modified for esp8266
=========================================================

![Avago APDS-9960 Breakout Board - SEN-12787 ](https://cdn.sparkfun.com/r/92-92/assets/parts/9/6/0/3/12787-01.jpg)
Made a few changes to get this to work with esp8266.

[*Avago APDS-9960 Breakout Board (SEN-12787)*](https://www.sparkfun.com/products/12787)
The main two are:
* Removing wire.begin() from SparkFun_APDS9960.cpp and moving it into the examples so that the pins it uses can be specified in your sketch

Getting Started
---------------
* Changed the LED_BOOST_300 to LED_BOOST_100 in SparkFun_APDS9960.cpp as I couldn't get the gesture sensor to work without changing this

* Download the Git repository as a ZIP ("Download ZIP" button)
* Unzip
* Copy the entire library directory (APDS-9960_RGB_and_Gesture_Sensor_Arduino_Library
) to \<Arduino installation directory\>/libraries
* Open the Arduino program
* Select File -> Examples -> SparkFun_APDS9960 -> GestureTest
* Plug in your Arduino and APDS-9960 with the following connections

*-OR-*

* Use the library manager

| Arduino Pin | APDS-9960 Board | Function |
|---|---|---|
| 3.3V | VCC | Power |
| GND | GND | Ground |
| A4 | SDA | I2C Data |
| A5 | SCL | I2C Clock |
| 2 | INT | Interrupt |

* Go to Tools -> Board and select your Arduino board
* Go to Tools -> Serial Port and select the COM port of your Arduino board
* Click "Upload"
* Go to Tools -> Serial Monitor
* Ensure the baud rate is set at 9600 baud
* Swipe your hand over the sensor in various directions!

Repository Contents
-------------------

* **/examples** - Example sketches for the library (.ino). Run these from the Arduino IDE.
* **/src** - Source files for the library (.cpp, .h).
* **library.properties** - General library properties for the Arduino package manager.

Documentation
--------------

* **[Installing an Arduino Library Guide](https://learn.sparkfun.com/tutorials/installing-an-arduino-library)** - Basic information on how to install an Arduino library.
* **[Product Repository](https://github.com/sparkfun/APDS-9960_RGB_and_Gesture_Sensor)** - Main repository (including hardware files) for the SparkFun_APDS9960 RGB and Gesture Sensor.
* **[Hookup Guide](https://learn.sparkfun.com/tutorials/apds-9960-rgb-and-gesture-sensor-hookup-guide)** - Basic hookup guide for the sensor.

Products that use this Library
---------------------------------

* [SEN-12787](https://www.sparkfun.com/products/12787)- Avago APDS-9960

Version History
---------------
* [V_1.4.1](https://github.com/sparkfun/SparkFun_APDS-9960_Sensor_Arduino_Library/tree/V_1.4.1) - Removing blank files, updating library.properties file.
* [V_1.4.0](https://github.com/sparkfun/APDS-9960_RGB_and_Gesture_Sensor_Arduino_Library/tree/V_1.4.0) - Updated to new library structure
* V_1.3.0 - Implemented disableProximitySensor(). Thanks to jmg5150 for catching that!
* V_1.2.0 - Added pinMode line to GestureTest demo to fix interrupt bug with some Arduinos
* V_1.1.0 - Updated GestureTest demo to not freeze with fast swipes
* V_1.0.0: Initial release
* Ambient and RGB light sensing implemented
* Ambient light interrupts working
* Proximity sensing implemented
* Proximity interrupts working
* Gesture (UP, DOWN, LEFT, RIGHT, NEAR, FAR) sensing implemented

License Information
-------------------

This product is _**open source**_!

The **code** is beerware; if you see me (or any other SparkFun employee) at the local, and you've found our code helpful, please buy us a round!

Please use, reuse, and modify these files as you see fit. Please maintain attribution to SparkFun Electronics and release anything derivative under the same license.

Distributed as-is; no warranty is given.

- Your friends at SparkFun.
See Sparkfun's original library here https://github.com/sparkfun/SparkFun_APDS-9960_Sensor_Arduino_Library for usage.
32 changes: 20 additions & 12 deletions examples/AmbientLightInterrupt/AmbientLightInterrupt.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ Hardware Connections:

IMPORTANT: The APDS-9960 can only accept 3.3V!

Arduino Pin APDS-9960 Board Function
Wemos Pin APDS-9960 Board Function

3.3V VCC Power
GND GND Ground
A4 SDA I2C Data
A5 SCL I2C Clock
2 INT Interrupt
13 - LED
D3 SDA I2C Data
D1 SCL I2C Clock
D6 INT Interrupt
D7 - LED

Resources:
Include Wire.h and SparkFun_APDS-9960.h
Expand All @@ -37,14 +37,19 @@ employee) at the local, and you've found our code helpful, please
buy us a round!

Distributed as-is; no warranty is given.

Modified for ESP8266 by Jon Ulmer Nov 2016
****************************************************************/

#include <Wire.h>
#include <SparkFun_APDS9960.h>

// Pins
#define APDS9960_INT 2 // Needs to be an interrupt pin
#define LED_PIN 13 // LED for showing interrupt
// Pins on wemos D1 mini
#define APDS9960_INT D6 //AKA GPIO12 -- Interupt pin
#define APDS9960_SDA D3 //AKA GPIO0
#define APDS9960_SCL D1 //AKA GPIO5
#define LED_PIN D7 //AKA GPIO13 -- LED for showing interrupt


// Constants
#define LIGHT_INT_HIGH 1000 // High light level for interrupt
Expand All @@ -56,24 +61,27 @@ uint16_t ambient_light = 0;
uint16_t red_light = 0;
uint16_t green_light = 0;
uint16_t blue_light = 0;
int isr_flag = 0;
volatile bool isr_flag = 0;
uint16_t threshold = 0;

void setup() {

//Start I2C with pins defined above
Wire.begin(APDS9960_SDA,APDS9960_SCL);

// Set LED as output
pinMode(LED_PIN, OUTPUT);
pinMode(APDS9960_INT, INPUT);

// Initialize Serial port
Serial.begin(9600);
Serial.begin(115200);
Serial.println();
Serial.println(F("-------------------------------------"));
Serial.println(F("SparkFun APDS-9960 - Light Interrupts"));
Serial.println(F("-------------------------------------"));

// Initialize interrupt service routine
attachInterrupt(0, interruptRoutine, FALLING);
attachInterrupt(APDS9960_INT, interruptRoutine, FALLING);

// Initialize APDS-9960 (configure I2C and initial values)
if ( apds.init() ) {
Expand Down Expand Up @@ -158,4 +166,4 @@ void loop() {

void interruptRoutine() {
isr_flag = 1;
}
}
19 changes: 14 additions & 5 deletions examples/ColorSensor/ColorSensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ Hardware Connections:

IMPORTANT: The APDS-9960 can only accept 3.3V!

Arduino Pin APDS-9960 Board Function
Wemos Pin APDS-9960 Board Function

3.3V VCC Power
GND GND Ground
A4 SDA I2C Data
A5 SCL I2C Clock
D3 SDA I2C Data
D1 SCL I2C Clock

Resources:
Include Wire.h and SparkFun_APDS-9960.h
Expand All @@ -33,11 +33,17 @@ employee) at the local, and you've found our code helpful, please
buy us a round!

Distributed as-is; no warranty is given.

Modified for ESP8266 by Jon Ulmer Nov 2016
****************************************************************/

#include <Wire.h>
#include <SparkFun_APDS9960.h>

// Pins on wemos D1 mini
#define APDS9960_SDA D3 //AKA GPIO0
#define APDS9960_SCL D1 //AKA GPIO5

// Global Variables
SparkFun_APDS9960 apds = SparkFun_APDS9960();
uint16_t ambient_light = 0;
Expand All @@ -46,9 +52,12 @@ uint16_t green_light = 0;
uint16_t blue_light = 0;

void setup() {

//Start I2C with pins defined above
Wire.begin(APDS9960_SDA,APDS9960_SCL);

// Initialize Serial port
Serial.begin(9600);
Serial.begin(115200);
Serial.println();
Serial.println(F("--------------------------------"));
Serial.println(F("SparkFun APDS-9960 - ColorSensor"));
Expand Down Expand Up @@ -93,4 +102,4 @@ void loop() {

// Wait 1 second before next reading
delay(1000);
}
}
33 changes: 20 additions & 13 deletions examples/GestureTest/GestureTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ Hardware Connections:

IMPORTANT: The APDS-9960 can only accept 3.3V!

Arduino Pin APDS-9960 Board Function
Wemos Pin APDS-9960 Board Function

3.3V VCC Power
GND GND Ground
A4 SDA I2C Data
A5 SCL I2C Clock
2 INT Interrupt
D3 SDA I2C Data
D1 SCL I2C Clock
D6 INT Interrupt
D7 - LED

Resources:
Include Wire.h and SparkFun_APDS-9960.h
Expand All @@ -43,34 +44,40 @@ employee) at the local, and you've found our code helpful, please
buy us a round!

Distributed as-is; no warranty is given.

Modified for ESP8266 by Jon Ulmer Nov 2016
****************************************************************/

#include <Wire.h>
#include <SparkFun_APDS9960.h>

// Pins
#define APDS9960_INT 2 // Needs to be an interrupt pin

// Pins on wemos D1 mini
#define APDS9960_INT D6 //AKA GPIO12 -- Interupt pin
#define APDS9960_SDA D3 //AKA GPIO0
#define APDS9960_SCL D1 //AKA GPIO5
// Constants

// Global Variables
SparkFun_APDS9960 apds = SparkFun_APDS9960();
int isr_flag = 0;
volatile bool isr_flag = 0;

void setup() {

//Start I2C with pins defined above
Wire.begin(APDS9960_SDA,APDS9960_SCL);

// Set interrupt pin as input
pinMode(APDS9960_INT, INPUT);

// Initialize Serial port
Serial.begin(9600);
Serial.begin(115200);
Serial.println();
Serial.println(F("--------------------------------"));
Serial.println(F("SparkFun APDS-9960 - GestureTest"));
Serial.println(F("--------------------------------"));

// Initialize interrupt service routine
attachInterrupt(0, interruptRoutine, FALLING);
attachInterrupt(APDS9960_INT, interruptRoutine, FALLING);

// Initialize APDS-9960 (configure I2C and initial values)
if ( apds.init() ) {
Expand All @@ -89,10 +96,10 @@ void setup() {

void loop() {
if( isr_flag == 1 ) {
detachInterrupt(0);
detachInterrupt(APDS9960_INT);
handleGesture();
isr_flag = 0;
attachInterrupt(0, interruptRoutine, FALLING);
attachInterrupt(APDS9960_INT, interruptRoutine, FALLING);
}
}

Expand Down Expand Up @@ -125,4 +132,4 @@ void handleGesture() {
Serial.println("NONE");
}
}
}
}
31 changes: 19 additions & 12 deletions examples/ProximityInterrupt/ProximityInterrupt.ino
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ Hardware Connections:

IMPORTANT: The APDS-9960 can only accept 3.3V!

Arduino Pin APDS-9960 Board Function
Wemos Pin APDS-9960 Board Function

3.3V VCC Power
GND GND Ground
A4 SDA I2C Data
A5 SCL I2C Clock
2 INT Interrupt
13 - LED
D3 SDA I2C Data
D1 SCL I2C Clock
D6 INT Interrupt
D7 - LED

Resources:
Include Wire.h and SparkFun_APDS-9960.h
Expand All @@ -35,14 +35,18 @@ employee) at the local, and you've found our code helpful, please
buy us a round!

Distributed as-is; no warranty is given.

Modified for ESP8266 by Jon Ulmer Nov 2016
****************************************************************/

#include <Wire.h>
#include <SparkFun_APDS9960.h>

// Pins
#define APDS9960_INT 2 // Needs to be an interrupt pin
#define LED_PIN 13 // LED for showing interrupt
// Pins on wemos D1 mini
#define APDS9960_INT D6 //AKA GPIO12 -- Interupt pin
#define APDS9960_SDA D3 //AKA GPIO0
#define APDS9960_SCL D1 //AKA GPIO5
#define LED_PIN D7 //AKA GPIO13 -- LED for showing interrupt

// Constants
#define PROX_INT_HIGH 50 // Proximity level for interrupt
Expand All @@ -51,23 +55,26 @@ Distributed as-is; no warranty is given.
// Global variables
SparkFun_APDS9960 apds = SparkFun_APDS9960();
uint8_t proximity_data = 0;
int isr_flag = 0;
volatile bool isr_flag = 0;

void setup() {

//Start I2C with pins defined above
Wire.begin(APDS9960_SDA,APDS9960_SCL);

// Set LED as output
pinMode(LED_PIN, OUTPUT);
pinMode(APDS9960_INT, INPUT);

// Initialize Serial port
Serial.begin(9600);
Serial.begin(115200);
Serial.println();
Serial.println(F("---------------------------------------"));
Serial.println(F("SparkFun APDS-9960 - ProximityInterrupt"));
Serial.println(F("---------------------------------------"));

// Initialize interrupt service routine
attachInterrupt(0, interruptRoutine, FALLING);
attachInterrupt(APDS9960_INT, interruptRoutine, FALLING);

// Initialize APDS-9960 (configure I2C and initial values)
if ( apds.init() ) {
Expand Down Expand Up @@ -126,4 +133,4 @@ void loop() {

void interruptRoutine() {
isr_flag = 1;
}
}
Loading