I tried to port the Adafruit VCNL4010 library for the Photon and Core. My code compiles in the online IDE but does not seem to work. Maybe someone can have a look at it
That INT pin can be connected to any other pin, since itâs completely up to you which pin you want to use for attachInterrupt() to react on any interrupt triggered by the sensor.
But that lib doesnât give you any clue how to set up the interrupt - and the Adafruit docs seem to do neither.
So youâd need to go through the datasheet to do it yourself
How did you manage to publish in the dashboard? Mine is not working . What am I doing wrong?
//publish events in particle dashboard
Particle.publish(âAmbient:â, String(Ambient));
Particle.publish(âProimity:â, String(Proximity));
// This #include statement was automatically added by the Particle IDE.
#include <VCNL4010.h>
// EXAMPLE - an AT&T APN with no username or password in AUTOMATIC mode
#include "cellular_hal.h"
STARTUP(cellular_credentials_set("internet", "", "", NULL));
//////////////////////code for particle
VCNL4010 vcnl;
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("Proimity: "); Serial.println(vcnl.readProximity());
//publish events in particle dashboard
//Particle.publish("Ambient:", String(Ambient));
//Particle.publish("Proximity", String(Proximity));
delay(1000);
}
Ok, first of all, what does that mean? The statement, "not working" is the bane of forum helpers everywhere because it doesn't help to diagnose the problem. What specifically is you problem? Do you get nothing in the dashboard? Some show up, and some don't? Be specific, the more information you give us, the easier it is to help you fix the problem. @ScruffR asked you whether you are publishing more than once per second which is the limit allowed, and you are exceeding that, with 2/second. Either make your delay longer, or combine your two pieces of data into one publish event, and see if that fixes the problem.
Hi Ric! Thank you for your prompt reply. I am new to this community and promise to follow your advice regarding the post structure.
I am flashing the same code posted by @hl68fx, VCNL4010.ino
Could you please take a look at my code ? I have serial output and I have added delay(2000); now. However, there is nothing on the the dashboard. Is it something related to declaration of particle variable? Million thanks in advance.
//publish events in particle dashboard
Particle.publish(âAmbient:â, String(Ambient));
Particle.publish(âProximityâ, String(Proximity));
I don't see any Particle variable in that code, though you don't need one to publish. What I don't see anywhere are the variables, Ambient or Proximity. Do you have those in your code? When you say, there's nothing in the dashboard, do you mean you don't see the data you're sending, or that you don't see anything at all (no indication that the Publish occurred)? If it's the latter, then maybe there's something wrong with your dashboard. Do you see your devices listed there? Have you ever gotten anything to show up on your dashboard before?
Hi Eric! I have output of the others sensors in the dashboard. I am new in coding. I guess I am missing some important codes. Please take a look at the below code and errors:
// This #include statement was automatically added by the Particle IDE.
#include <VCNL4010.h>
//////////////////////code for particle
VCNL4010 vcnl;
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("Proimity: "); Serial.println(vcnl.readProximity());
//publish events in particle dashboard
Particle.publish("Ambient:", String(Ambient));
Particle.publish("Proximity", String(Proximity));
delay(1000);
}
Errors:
/src/app3_light.cpp: In function 'void loop()':
/src/app3_light.cpp:29:40: error: 'Ambient' was not declared in this scope
^
/src/app3_light.cpp:30:41: error: 'Proximity' was not declared in this scope
Serial.print("Ambient: "); Serial.println(vcnl.readAmbient());
^
make[1]: *** [../build/target/user/platform-10src/app3_light.o] Error 1
make: *** [user] Error 2
You donât have any variables named Ambient or Proximity (you really should use lowercase names for variables). You need to add them and set them equal to vcml.readAmbient and vcml.readProximity respectively.
Hi Ric! It works flawlessly! I have modified my others codes too.Thank you so much. I am glad to be the part of the community. Hope to contribute soon.