GithubHelp home page GithubHelp logo

adafruit_vcnl4010's Introduction

Adafruit VCNL4010 LibraryBuild StatusDocumentation

This is the Adafruit VCNL4010 Proximity I2C sensor library

Tested and works great with the Aadafruit VCNL4010 Breakout Board

This chip uses I2C to communicate, 2 pins are required to interface

Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!

Written by Kevin Townsend/Limor Fried for Adafruit Industries.
BSD license, check license.txt for more information All text above must be included in any redistribution

To install, use the Arduino Library Manager to search for 'Adafruit VCNL4010' and install the library.

Compatibility

MCU Tested Works Doesn't Work Not Tested Notes
Atmega328 @ 16MHz X
Atmega328 @ 12MHz X
Atmega32u4 @ 16MHz X Use SDA/SCL on pins D2 & D3
Atmega32u4 @ 8MHz X Use SDA/SCL on pins D2 & D3
ESP8266 X SDA/SCL default to pins 4 & 5 but any two pins can be assigned as SDA/SCL using Wire.begin(SDA,SCL)
Atmega2560 @ 16MHz X Use SDA/SCL on pins 20 & 21
ATSAM3X8E X Use programming port.
ATSAM21D X Use SDA and SCL pins.
ATtiny85 @ 16MHz X
ATtiny85 @ 8MHz X
Intel Curie @ 32MHz X
STM32F2 X
  • ATmega328 @ 16MHz : Arduino UNO, Adafruit Pro Trinket 5V, Adafruit Metro 328, Adafruit Metro Mini
  • ATmega328 @ 12MHz : Adafruit Pro Trinket 3V
  • ATmega32u4 @ 16MHz : Arduino Leonardo, Arduino Micro, Arduino Yun, Teensy 2.0
  • ATmega32u4 @ 8MHz : Adafruit Flora, Bluefruit Micro
  • ESP8266 : Adafruit Huzzah
  • ATmega2560 @ 16MHz : Arduino Mega
  • ATSAM3X8E : Arduino Due
  • ATSAM21D : Arduino Zero, M0 Pro
  • ATtiny85 @ 16MHz : Adafruit Trinket 5V
  • ATtiny85 @ 8MHz : Adafruit Gemma, Arduino Gemma, Adafruit Trinket 3V

adafruit_vcnl4010's People

Contributors

andydoro avatar caternuson avatar drak7 avatar evaherrada avatar ladyada avatar siddacious avatar tdicola avatar tyeth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

adafruit_vcnl4010's Issues

Library keeps hanging in read8

When I put a motorshield on the arduino the code for the proximity sensor hangs.
I added some println's, "A", "B", "C", "D" etc.
I will print A, B and C but never reaches D.
So somewhere inside uint8_t rev = read8(VCNL4010_PRODUCTID); it hangs.

(On !Wire.available() eventaully...).

boolean Adafruit_VCNL4010::begin(uint8_t addr) {
   Serial.print("A");
  _i2caddr = addr;
  Serial.print("B");
  Wire.begin();
  Serial.print("C");

  **uint8_t rev = read8(VCNL4010_PRODUCTID);**
  Serial.print("D");
  //Serial.println(rev, HEX);
  if ((rev & 0xF0) != 0x20) {
  	Serial.print("E");
    return false;
  }
	
  Serial.print("F");  
  setLEDcurrent(20);
  Serial.print("G");
  setFrequency(VCNL4010_390K625);
  Serial.print("H");

  write8(VCNL4010_INTCONTROL, 0x08);
  Serial.print("I");
  return true;
}

No need to check Wire.available().

Four times the "while(!Wire.available());" is used. That is not needed. When Wire.requestFrom() has returned the I2C transmission has ended and the data is in the buffer.
I assume that TinyWire works the same.

No waiting for Wire.available() needed after Wire.requestFrom().

The while-loop for Wire.available() after Wire.requestFrom() is not needed. When the Wire.requestFrom() function returns, the I2C transmission has completely finished and the received bytes are in a buffer in the Wire library.
In the rare case of a I2C collision with mulitple Masters or when the sensor does not return data, the while-loop will wait forever. To check for that condition, the Wire.available() returns the number of bytes that are waiting in the receive-buffer inside the Wire library, but also the return value of Wire.requestFrom() returns the number of received bytes.

(I'm sorry, I just noticed that I did make the same issue as Issue #1, I was not trying to be rude, I just want to help Adafruit for free to make better and cleaner code).

Cannot run the code on ATTINY85 8mhz, fatal error: TinywireM.h: No such files in directory.

Hi I use the example code for this on the Arduino Uno, and it works fine. When I try to upload the code on my Bootloaded ATTINY85 im getting the error, i know the AdaFruit_VCNL4010 is compatible with ATTINY85. Please Help

Error im getting:
fatal error: TinywireM.h: No such files in directory.
#include<TinyWireM.h>

The code i use
#include <Wire.h>
#include "Adafruit_VCNL4010.h"

Adafruit_VCNL4010 vcnl;

#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
#define Serial SerialUSB
#endif

void setup() {
Serial.begin(9600);
Serial.println("VCNL4010 test");

if (! vcnl.begin()){
Serial.println("Sensor not found :(");
while (1);
}
Serial.println("Found VCNL4010");
}

void loop() {
Serial.print("Ambient: "); Serial.println(vcnl.readAmbient());
Serial.print("Proximity: "); Serial.println(vcnl.readProximity());
delay(100);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.