I'm having issues with the Adafruit LTR390-UV. I'm using it with a Raspberry Pi Pico and the Arduino IDE interface. I have the SDA connected to the GP0 and SCL to the GP1 pin. When I run this setup in the CircuitPython environment and the example along with correct configuration of the pins it works perfect. When I try this with the Adafruit Arduino example it doesn't get past the "Couldn't find LTR sensor!" part. When I temporarily disconnect the jumper cables and plug in the SHTC3 sensor with the SHTC3 example code it works perfectly so I know it's not a problem with the hardware or the Rapberry Pi working in the Arduino environment.
Here is my CircuitPython code which worked perfectly:
Code: Select all
# SPDX-FileCopyrightText: 2021 by Bryan Siepert, written for Adafruit Industries
#
# SPDX-License-Identifier: Unlicense
import time
import busio
import board
import adafruit_ltr390
myI2C = busio.I2C(scl=board.GP13, sda=board.GP12)
ltr = adafruit_ltr390.LTR390(myI2C)
while True:
print("UV:", ltr.uvs, "\t\tAmbient Light:", ltr.light)
print("UVI:", ltr.uvi, "\t\tLux:", ltr.lux)
time.sleep(1.0)
Here is how I have the SHTC3 configured which worked perfectly with the GP0, GP1 setup when I wanted to make sure the GP0 and GP1 pins were at least configured correctly in the Arduino IDE:
Code: Select all
/***************************************************
This is an example for the SHTC3 Humidity & Temp Sensor
Designed specifically to work with the SHTC3 sensor from Adafruit
----> https://www.adafruit.com/products/4636
These sensors use I2C to communicate, 2 pins are required to
interface
****************************************************/
#include "Adafruit_SHTC3.h"
#include <Wire.h>
TwoWire Wire_00(i2c0, 0,1); // SDA, SCL for TMP102
Adafruit_SHTC3 shtc3 = Adafruit_SHTC3();
void setup() {
Serial.begin(9600);
while (!Serial)
delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("SHTC3 test");
if (! shtc3.begin(&Wire_00)) {
Serial.println("Couldn't find SHTC3");
while (1) delay(1);
}
Serial.println("Found SHTC3 sensor");
}
void loop() {
sensors_event_t humidity, temp;
shtc3.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data
Serial.print("Temperature: "); Serial.print(temp.temperature); Serial.println(" degrees C");
Serial.print("Humidity: "); Serial.print(humidity.relative_humidity); Serial.println("% rH");
delay(1000);
}
Here is what my LTR390 code looks like and I configured the GP0 and GP1 similar to how I had done for the SHTC3 however this is not making it past the "Couldn't find LTR sensor!" part of the code.
Code: Select all
/***************************************************
This is an example for the LTR390 UV Sensor
Designed specifically to work with the LTR390 UV sensor from Adafruit
----> https://www.adafruit.com
These sensors use I2C to communicate, 2 pins are required to
interface
****************************************************/
#include "Adafruit_LTR390.h"
#include <Wire.h>
TwoWire Wire_00(i2c0, 0,1); // SDA, SCL for Afafruit LTR390
Adafruit_LTR390 ltr = Adafruit_LTR390();
void setup() {
delay(10000);
Serial.begin(9600);
Serial.println("Adafruit LTR-390 test");
Wire_00.begin();
if ( ! ltr.begin(&Wire_00) ) {
Serial.println("Couldn't find LTR sensor!");
while (1) delay(10);
}
Serial.println("Found LTR sensor!");
ltr.setMode(LTR390_MODE_UVS);
if (ltr.getMode() == LTR390_MODE_ALS) {
Serial.println("In ALS mode");
} else {
Serial.println("In UVS mode");
}
ltr.setGain(LTR390_GAIN_3);
Serial.print("Gain : ");
switch (ltr.getGain()) {
case LTR390_GAIN_1: Serial.println(1); break;
case LTR390_GAIN_3: Serial.println(3); break;
case LTR390_GAIN_6: Serial.println(6); break;
case LTR390_GAIN_9: Serial.println(9); break;
case LTR390_GAIN_18: Serial.println(18); break;
}
ltr.setResolution(LTR390_RESOLUTION_18BIT);
Serial.print("Resolution : ");
switch (ltr.getResolution()) {
case LTR390_RESOLUTION_13BIT: Serial.println(13); break;
case LTR390_RESOLUTION_16BIT: Serial.println(16); break;
case LTR390_RESOLUTION_17BIT: Serial.println(17); break;
case LTR390_RESOLUTION_18BIT: Serial.println(18); break;
case LTR390_RESOLUTION_19BIT: Serial.println(19); break;
case LTR390_RESOLUTION_20BIT: Serial.println(20); break;
}
ltr.setThresholds(100, 1000);
ltr.configInterrupt(true, LTR390_MODE_UVS);
}
void loop() {
if (ltr.newDataAvailable()) {
Serial.print("UV data: ");
Serial.print(ltr.readUVS());
}
Serial.print("UV data: ");
Serial.print(ltr.readUVS());
delay(100);
}
Does anyone know if I'm doing something obviously wrong or is there perhaps some modification I need to make to the Adafruit LTR390 library? I was thinking it would work similar to the SHTC3 in how to configure it but perhaps I'm not understanding something. I strongly want to make this work in the Arduino environment since I'm using other sensors from Adafruit that I already got working in Arduino.