One function I need, which is very basic, is to detect when it is dark a and the object is moving an led will flash. I hope to be making allot this project and need to keep size and costs down.
What would be better to use:
Adafruit VEML7700 Lux Sensor - I2C Light Sensor
or
Photoresistor SKU: SEN-09088
I also need mini switches: (example- SKU: FIT0179
Brand: DFRobot
1: as an ON/OFF latching single pole switch
2: as a momentary(pulse) non-latching switch
as small as possible the better.
The MPU6050 unfortunately isnt able to measure speed, rather its acceleration.
As for keeping everything as compact and cheap as possible Iād probably switch out the Adafruit parts and go for the PiicoDev equivalents, theyāll be a bit cheaper and use the same mounting holes so you can stack them up,
Also switching dev boards to the RPi Pico might get the price down a bit as well, just note there are limits at the moment re: silicon shortage. (also features a button on the top you could use as the momentary one). I searched for ālatching buttonā
for it to pop up.
Hereās a small button I found as well.
Thanks for the info. I donāt donāt need to measure speed, just an accelerometer which I have coded and tested using a Nano33BLE. But I have found too many limitations at the moment with that board in lack of support. So I am switching back to the nano board with the additional MPU and daylight switch. It is a pity I have to now change my power system from 3.3V to a 5v because of the difference in the boards. Hopefully I can get a battery charging board that fits my current design
I take it that the Pico range works with Arduino like adafruit does? I am still new to these products so not sure with what is compatible with each other yet. But they are cheaper and smaller, even the TOF as I am using Adafruit TOF atm. I will have to redo all the mountings in my cad design but Iād rather do it now once and get it right. Thanks again.
Sorry Liam didnāt get the link to the button. I will stay with Arduino for now, happy with that format. So will need one latching(power on/off) and one non-latching(to select modes) mini switch about 6mm x 6mm to 8mm x 8mm in dimensions.
The PiicoDev range of sensors all use the I2C communication protocol, which will work with Arduino or Pi Pico microcontrollers.
We have a guide for I2C with Arduino devices you can find here:
I have my VEML6030and VL53L1X Piico sensors connected in i2C, which I am using with an Arduino Nano33BLE and Adafruit 2MB FX board using UART triggers.
I have looked at the i2C tutorial and what I can find on Piico sensors but I am still confused.
Is there any tutorials or guides for use of Piico and Arduino with some example codes?
Other than wire.h library is there need of any other libraries when using these and other Piico sensors?
I already have code written for a Adafruit VL53L0X but changed to Piico after being recommended it to bring project costs down and so I can use i2C to connect multiple sensors, which at the moment is just the Piico TOF and LUXsensors(as listed above). Do I just use the code as I have(below)?
this is an extract of my code just for the measurement part of the project.
> #include "Adafruit_VL53L0X.h"
>
> void setup()
>
> Serial.println("Adafruit VL53L0X test");
> if (!lox.begin())
> {
> Serial.println(F("Failed to boot VL53L0X"));
> while (1);
> }
> // power
> Serial.println(F("VL53L0X API Simple Ranging example\n\n"));
> }
>
> void loop()
>
> Serial.print("Reading a measurement... ");
> lox.rangingTest(&measure, false); // pass in 'true' to get debug data printout
>
>
> /*==============================================
> Print Laser measurment to Serial Monitor
> ===================================================*/
>
> if (measure.RangeStatus != 4) { // phase failures have incorrect data
> Serial.print("Distance (mm): "); Serial.println(measure.RangeMilliMeter);
> //LaserMeasurement = measure.RangeMilliMeter;
> } else {
> Serial.println(" out of range ");
> }
>
> delay(100);
I am also still a bit unsure how to code these sensors using i2C with Arduino, could you please explain simply, maybe just an example code will clarify it for me.
Is there the possibility to have some Arduino tutorial video utilising the Piico range to help newbies like me.
Sorry I missed that link there, looks like Trent managed to track down one that should work though.
Unfortunately there arent any Arduino guides for the two PiicoDev sensors at the moment(Core has been going all out to make the MicroPython implementation as seemless as possible).
To get them working ASAP Iād use another couple libraries for the same chips:
The libraries will let you use calls to different functions, letting you read measurements super easily.
Getting an I2C device working usually requires a couple of steps:
Initialisation - where the devices parameters are set
Reading the device - Requesting the bits from registers on the sensors
For some sensors you can also add interupts - See the MPU and DS3231
With regards to the coding for i2C, I have watched a few YouTube videos as well as the info provided here but I just canāt seem to grasp it yet. The videos I could find only talk about connecting one device and the ones for multiple devices I didnāt find clear. Can you suggest any for a dummie
A rough analogy for I2C is like an email. (Inside the brackets is what happens in electronics)
You need an email address, for who its addressed to (senors I2C address - these can be found in the datasheet of the sensors).
The contents of the email, whether it is simply mentioning that you have to open the window (changing some configuration on the sensor itself), sometimes the contents of the email can request a return message like, the window is letting in XXX amount of light (the sensor will then send back a response over the data wire).
Regardless of how many devices are connected to the I2C connections an address is still required as that is packed into the protocol itself.
Do I need pullup resistors when using a nano33ble with 2 slaves on I2C, i have read yes and no. Definitely when using more slaves and longer runs. My items are basically stacked on top of each other, no distance to acknowledge.
I could be wrong but as I understand it you cannot have ālonger runsā with I2C. One or two metres probably Max. I donāt recall seeing published any definitive figure but I think the system was designed for comms between ICs on the same board or in the same box. To go any further requires another system.
Cheers Bob
I found this in regards to pull up resistors, I was confused with or without needing them as I was watching how toās on other Arduino boards.
I2C pins: As opposed to other Arduino Nano boards, pins A4 and A5 have an internal pull up and default to be used as an I2C Bus so usage as analog inputs is not recommended.
And as an alternative in reply to your original post, hereās some info on using a photoresistor with Arduino for light detection. A little more hands on and raw electronics!
I am having trouble with the example code for the piico VL53L1X and VEML6030 with my Nano33BLE. Can you help me get through these issues please?
For the VEML6030:
>
> /*
> This example code will walk you through how to read ambient light values.
> Chances are good that you'll use this sensor in various environments so it'll
> also walk you through setting the gain and integration time that allow for
> different ranges of lux values. For example using the default gain of 100ms
> gives you a maximum reading of 30,199 Lux. This is great for daylight
> readings but not DIRECT sun. Higher integration times mean higher
> resoultions but lower lux values and vice versa: the lowest integration time
> and lowest gain should be used for mid day direct light. Check our hookup
> guide for more information.
>
> SparkFun Electronics
> Author: Elias Santistevan
> Date: July 2019
>
> License: This code is public domain but if you use this and we meet someday, get me a beer!
>
> Feel like supporting our work? Buy a board from Sparkfun!
> https://www.sparkfun.com/products/15436
>
> */
> #include <Arduino_LSM9DS1.h>
> #include <Wire.h>
> #include "SparkFun_VEML6030_Ambient_Light_Sensor.h"
>
> #define AL_ADDR 0x48
>
> SparkFun_Ambient_Light light(AL_ADDR);
>
> // Possible values: .125, .25, 1, 2
> // Both .125 and .25 should be used in most cases except darker rooms.
> // A gain of 2 should only be used if the sensor will be covered by a dark
> // glass.
> float gain = .125;
>
> // Possible integration times in milliseconds: 800, 400, 200, 100, 50, 25
> // Higher times give higher resolutions and should be used in darker light.
> int time = 100;
> long luxVal = 0;
>
> void setup(){
>
> Wire.begin();
> Serial.begin(115200);
>
> if(light.begin())
> Serial.println("Ready to sense some light!");
> else
> Serial.println("Could not communicate with the sensor!");
>
> // Again the gain and integration times determine the resolution of the lux
> // value, and give different ranges of possible light readings. Check out
> // hoookup guide for more info.
> light.setGain(gain);
> light.setIntegTime(time);
>
> Serial.println("Reading settings...");
> Serial.print("Gain: ");
> float gainVal = light.readGain();
> Serial.print(gainVal, 3);
> Serial.print(" Integration Time: ");
> int timeVal = light.readIntegTime();
> Serial.println(timeVal);
>
> }
>
> void loop()
I get the following error message in Arduino IDE:
> Arduino: 1.8.16 (Windows Store 1.8.51.0) (Windows 10), Board: "Arduino Nano 33 BLE"
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> Example1_Read_Ambient_Basics:38:5: error: 'int time' redeclared as different kind of symbol
>
> int time = 100;
>
> ^~~~
>
> In file included from c:\users\kevb\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\stdio.h:29:0,
>
> from C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\cores\arduino/mbed/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/components/libraries/util/app_error.h:54,
>
> from C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\cores\arduino/mbed/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/components/libraries/util/app_util_platform.h:60,
>
> from C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\cores\arduino/mbed/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/integration/nrfx/nrfx_glue.h:182,
>
> from C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\cores\arduino/mbed/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/modules/nrfx/nrfx.h:46,
>
> from C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\cores\arduino/mbed/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_15_0/modules/nrfx/hal/nrf_gpio.h:44,
>
> from C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\cores\arduino/mbed/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/TARGET_ARDUINO_NANO33BLE/PinNames.h:23,
>
> from C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\variants\ARDUINO_NANO33BLE/pinmode_arduino.h:17,
>
> from C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\cores\arduino/Arduino.h:26,
>
> from sketch\Example1_Read_Ambient_Basics.ino.cpp:1:
>
> c:\users\kevb\documents\arduinodata\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\arm-none-eabi\include\time.h:59:11: note: previous declaration 'time_t time(time_t*)'
>
> time_t _EXFUN(time, (time_t *_timer));
>
> ^
>
> C:\Users\KevB\AppData\Local\Temp\arduino_modified_sketch_713293\Example1_Read_Ambient_Basics.ino: In function 'void setup()':
>
> Example1_Read_Ambient_Basics:55:26: error: invalid conversion from 'time_t (*)(time_t*) {aka long long int (*)(long long int*)}' to 'uint16_t {aka short unsigned int}' [-fpermissive]
>
> light.setIntegTime(time);
>
> ^
>
> In file included from C:\Users\KevB\AppData\Local\Temp\arduino_modified_sketch_713293\Example1_Read_Ambient_Basics.ino:24:0:
>
> C:\Users\KevB\Documents\Arduino\libraries\SparkFun_Ambient_Light_Sensor_Arduino_Library-master\src/SparkFun_VEML6030_Ambient_Light_Sensor.h:95:10: note: initializing argument 1 of 'void SparkFun_Ambient_Light::setIntegTime(uint16_t)'
>
> void setIntegTime(uint16_t time);
>
> ^~~~~~~~~~~~
>
> C:\Users\KevB\AppData\Local\Temp\arduino_modified_sketch_713293\Example1_Read_Ambient_Basics.ino: At global scope:
>
> Example1_Read_Ambient_Basics:67:11: error: expected initializer at end of input
>
> void loop()
>
> ^
>
> exit status 1
>
> 'int time' redeclared as different kind of symbol
>
>
>
> This report would have more information with
> "Show verbose output during compilation"
> option enabled in File -> Preferences.
```````````````````````````````````````````````````````````````````
**For the VL53L1X:**
```````````````````````````````````````````````````````````````````````
/*
This example takes range measurements with the VL53L1X and displays additional
details (status and signal/ambient rates) for each measurement, which can help
you determine whether the sensor is operating normally and the reported range is
valid. The range is in units of mm, and the rates are in units of MCPS (mega
counts per second).
*/
#include <Wire.h>
#include <VL53L1X.h>
VL53L1X sensor;
void setup()
{
Serial.begin(115200);
Wire.begin();
Wire.setClock(400000); // use 400 kHz I2C
sensor.setTimeout(500);
if (!sensor.init())
{
Serial.println("Failed to detect and initialize sensor!");
while (1);
}
// Use long distance mode and allow up to 50000 us (50 ms) for a measurement.
// You can change these settings to adjust the performance of the sensor, but
// the minimum timing budget is 20 ms for short distance mode and 33 ms for
// medium and long distance modes. See the VL53L1X datasheet for more
// information on range and timing limits.
sensor.setDistanceMode(VL53L1X::Long);
sensor.setMeasurementTimingBudget(50000);
// Start continuous readings at a rate of one measurement every 50 ms (the
// inter-measurement period). This period should be at least as long as the
// timing budget.
sensor.startContinuous(50);
}
void loop()
{
sensor.read();
Serial.print("range: ");
Serial.print(sensor.ranging_data.range_mm);
Serial.print("\tstatus: ");
Serial.print(VL53L1X::rangeStatusToString(sensor.ranging_data.range_status));
Serial.print("\tpeak signal: ");
Serial.print(sensor.ranging_data.peak_signal_count_rate_MCPS);
Serial.print("\tambient: ");
Serial.print(sensor.ranging_data.ambient_count_rate_MCPS);
Serial.println();
}
``````````````````````````````````````````````````````````````````````````````````````
**I get the following errors:**
``````````````````````````````````````````````````````````````````````````````````````
> Arduino: 1.8.16 (Windows Store 1.8.51.0) (Windows 10), Board: "Arduino Nano 33 BLE"
>
> C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master\VL53L1X.cpp: In member function 'void VL53L1X::writeReg32Bit(uint16_t, uint32_t)':
>
> C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master\VL53L1X.cpp:188:34: error: call of overloaded 'write(long unsigned int)' is ambiguous
>
> bus->write((value >> 24) & 0xFF); // value highest byte
>
> ^
>
> In file included from C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master\VL53L1X.h:4:0,
>
> from C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master\VL53L1X.cpp:6:
>
> C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\libraries\Wire/Wire.h:59:20: note: candidate: virtual size_t arduino::MbedI2C::write(uint8_t)
>
> virtual size_t write(uint8_t data);
>
> ^~~~~
>
> C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\libraries\Wire/Wire.h:60:20: note: candidate: virtual size_t arduino::MbedI2C::write(int)
>
> virtual size_t write(int data) {
>
> ^~~~~
>
> C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master\VL53L1X.cpp:189:34: error: call of overloaded 'write(long unsigned int)' is ambiguous
>
> bus->write((value >> 16) & 0xFF);
>
> ^
>
> In file included from C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master\VL53L1X.h:4:0,
>
> from C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master\VL53L1X.cpp:6:
>
> C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\libraries\Wire/Wire.h:59:20: note: candidate: virtual size_t arduino::MbedI2C::write(uint8_t)
>
> virtual size_t write(uint8_t data);
>
> ^~~~~
>
> C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\libraries\Wire/Wire.h:60:20: note: candidate: virtual size_t arduino::MbedI2C::write(int)
>
> virtual size_t write(int data) {
>
> ^~~~~
>
> C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master\VL53L1X.cpp:190:34: error: call of overloaded 'write(long unsigned int)' is ambiguous
>
> bus->write((value >> 8) & 0xFF);
>
> ^
>
> In file included from C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master\VL53L1X.h:4:0,
>
> from C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master\VL53L1X.cpp:6:
>
> C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\libraries\Wire/Wire.h:59:20: note: candidate: virtual size_t arduino::MbedI2C::write(uint8_t)
>
> virtual size_t write(uint8_t data);
>
> ^~~~~
>
> C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\libraries\Wire/Wire.h:60:20: note: candidate: virtual size_t arduino::MbedI2C::write(int)
>
> virtual size_t write(int data) {
>
> ^~~~~
>
> C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master\VL53L1X.cpp:191:34: error: call of overloaded 'write(long unsigned int)' is ambiguous
>
> bus->write( value & 0xFF); // value lowest byte
>
> ^
>
> In file included from C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master\VL53L1X.h:4:0,
>
> from C:\Users\KevB\Documents\Arduino\libraries\vl53l1x-arduino-master\VL53L1X.cpp:6:
>
> C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\libraries\Wire/Wire.h:59:20: note: candidate: virtual size_t arduino::MbedI2C::write(uint8_t)
>
> virtual size_t write(uint8_t data);
>
> ^~~~~
>
> C:\Users\KevB\Documents\ArduinoData\packages\arduino\hardware\mbed_nano\2.3.1\libraries\Wire/Wire.h:60:20: note: candidate: virtual size_t arduino::MbedI2C::write(int)
>
> virtual size_t write(int data) {
>
> ^~~~~
>
> exit status 1
>
> Error compiling for board Arduino Nano 33 BLE.
>
>
>
> This report would have more information with
> "Show verbose output during compilation"
> option enabled in File -> Preferences.
``````````````````````````````````````````````````````````````````````````````