Sparkfun triad AS7265X does not work on Teensy 4.1

kmgr

New member
hello, i'm trying to use more AS7265X sensors with a Teensy 4.1. i'm using a TCA9548A as i2c multiplexer because the sensor have the same address. I need to use also a MPU6050 that i prefer to connect separately.
i have connected the MPU6050 to pin 19 and 18(sda scl - WIRE),and the multiplexer to pin 17 and 16(sda1 scl1- WIRE1). in this situation i couldn't start the AS7265X sensor, getting an error during the initialization. The MPU6050 worked correctly.
i tried a lot of configuration to test the sensor and the multiplexer, and i tried to connect the sensor directly to pin 18 and 19 but without result. i'm trying with a simple example but it didn't work.

Code:
#include "SparkFun_AS7265X.h"
AS7265X sensor;
#include <Wire.h>

void setup()
{
  Serial.begin(115200);
  Serial.println("AS7265x Spectral Triad Example");
  Wire.begin();
  delay (500);

  if (sensor.begin() == false)
  {
    Serial.println("Sensor does not appear to be connected. Please check wiring. Freezing...");
    while (1)
      ;
  }

  //Once the sensor is started we can increase the I2C speed
  Wire.setClock(400000);
  sensor.disableIndicator();
  Serial.println("A,B,C,D,E,F,G,H,R,I,S,J,T,U,V,W,K,L");
}

void loop()
{
  sensor.takeMeasurementsWithBulb(); //This is a hard wait while all 18 channels are measured

  Serial.print(sensor.getCalibratedA()); //410nm
 
//......

  Serial.println();
}
I would like to specify that the same sensor on the Arduino works perfectly, both with the multiplexer and without. I thought that it could be the Arduino spark libraries not compatible with the Teensy 4.1.
here the code with the multiplexer and the MPU. the libraries of the MPU use Wire and they work:
Code:
#include <Wire.h>

#include "SparkFun_AS7265X.h"
#define GYRO_CONFIG_Register 0x1B
#define ACCEL_CONFIG_Register 0x1C
#define ACCEL_XOUT_H_Register 0x3B
#define PWR_MGMT_1_Register 0x6B

uint8_t _i2cAddress = 0x68;
uint8_t receiveBuffer[14];
int nReceived;

int16_t accelX, accelY, accelZ;
int16_t gyroX, gyroY, gyroZ;
int16_t temp;

String header = "distance_s1, distance_s2, $ACC,$GYR,$TMP";
bool open =false;

const int numSens =1;
AS7265X sensors[numSens];

void setup() {
  Serial.begin(115200);

  // Setup device
  SetupMPU6050();

 for (int i = 0; i < numSens; i++) {
    TCA9548A(i);
    //Serial.println();
    if (sensors[i].begin() == false) {
      Serial.println("Sensor does not appear to be connected. Please check wiring. Freezing...");
      while (1)
      ;
    }
    setSensorParam(sensors[i], 70, AS7265X_GAIN_16X, AS7265X_MEASUREMENT_MODE_4CHAN_2);
    Serial.println("Sensor "); Serial.println(i); + Serial.println(" configured");
  }
}

void loop() {

  readMPU6050(&accelX, &accelY, &accelZ, &gyroX, &gyroY, &gyroZ, &temp);

  // Update the User
  //Serial.print("$ACC,\t");
  Serial.print(accelX * 2.0f / 32768, 3);
 ......

  delay(100);

   for (int i = 0; i < numSens; i++) {
    TCA9548A(i);

    sensors[i].takeMeasurements();  //This is a hard wait while all 18 channels are measured
    printData(sensors[i], i, distance_cm, lux);
  }

}

void TCA9548A(uint8_t bus) {

  Wire1.beginTransmission(0x70);  // TCA9548A address is 0x70
  Wire1.write(1 << bus);
  Wire1.endTransmission();
}

i receive the error "Sensor does not appear to be connected. Please check wiring. Freezing..", when sensor is initialized

Can anyone give me information?
thank you
 
The teensy 4.1 has 3 different i2c buses.

Check the pinout to find what they are. You wont need to use a multiplexer then. Your looking for the matching pair of sda and scl pins.

My guess is your wiring is not correct

Connect your module up and run an i2c scan. Details are https://learn.adafruit.com/scanning-i2c-addresses/arduino

If your not using the standard i2c bus you need to refer to them as wire1 or wire2

  • Wire to address the I2C bus on pins 18, 19;
  • Wire1 to address the I2C bus on pins 17, 16; (and)
  • Wire2 to address the I2C bus on pins 25, 24.
 
Thank you for your quick response
I need a multiplexer to Connect 5 sensors with the salme address. I would like to use pins 19 and 18 for tre IMU and pins 17 e 16 for multiplexer with 5 sensors.
I tried also the minimum configuration of teensy + 1 sensor on pins 19 and 18 but it does not work.
The imu on the same pins works correctly. Thank you
 

Attachments

  • 1000071373.jpg
    1000071373.jpg
    500.3 KB · Views: 94
Last edited:
i tried the scanning of the i2c connecting the sensor and i receive this response
08:09:21.030 -> Scanning...
08:09:21.031 -> I2C device found at address 0x49 !
08:09:21.031 -> done
08:09:21.031 ->
 
It seems a bit odd. It's finding it on the i2c bus.

Are you connecting it to Wire1?

Pins 16 and 17 are wire1

You can pass the i2c your using through the begin method
(sensor.begin(Wire1)
 
i have connected the MPU6050 to pin 19 and 18(sda scl - WIRE),and the multiplexer to pin 17 and 16(sda1 scl1- WIRE1).
The connections should be WIRE: pin 18 SDA, pin 19 SDL and WIRE1: pin 17 SDA, pin 16 SCL.
Your text is indicating that you have the WIRE (0) connections the wrong way round.

Try using an I2C scanner to show attached devices.
The PJRC Advanced Scanner can be found on Windows at (for Arduino 1.8.19):
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\i2c_t3\examples\advanced_scanner
 
The connections should be WIRE: pin 18 SDA, pin 19 SDL and WIRE1: pin 17 SDA, pin 16 SCL.
Your text is indicating that you have the WIRE (0) connections the wrong way round.

Try using an I2C scanner to show attached devices.
The PJRC Advanced Scanner can be found on Windows at (for Arduino 1.8.19):
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\i2c_t3\examples\advanced_scanner
thank you. i tried another AS7265X sensor on PINS 19-18 , and the result of the scan is

13:14:13.681 -> Scanning...
13:14:13.760 -> I2C device found at address 0x49 !
13:14:13.760 -> done

but when i try to print the data from sensor using its library the function sensor.begin() or sensor.begin(Wire) returns false. maybe should i use another function? here is my code(at the moment i have only one sensor):

Code:
#include "SparkFun_AS7265X.h" //Click here to get the library: http://librarymanager/All#SparkFun_AS7265X
AS7265X sensor;

#include <Wire.h>

void setup()
{
  Serial.begin(115200);
  Serial.println("AS7265x Spectral Triad Example");

  if (sensor.begin() == false)
  {
    Serial.println("Sensor does not appear to be connected. Please check wiring. Freezing...");
    while (1)
      ;
  }

  //Once the sensor is started we can increase the I2C speed
  Wire.setClock(400000);

  sensor.disableIndicator();

  Serial.println("A,B,C,D,E,F,G,H,R,I,S,J,T,U,V,W,K,L");
}

void loop()
{
  sensor.takeMeasurements(); //This is a hard wait while all 18 channels are measured

  Serial.print(sensor.getA()); //410nm
  //............

  Serial.println();
}

and this is the begin function of the AS7265X spark fun sensor

Code:
boolean AS7265X::begin(TwoWire &wirePort)
{
  _i2cPort = &wirePort;
  _i2cPort->begin(); //This resets any setClock() the user may have done

  if (isConnected() == false)
    return (false); //Check for sensor presence

  //Check to see if both slaves are detected
  uint8_t value = virtualReadRegister(AS7265X_DEV_SELECT_CONTROL);
  if ((value & 0b00110000) == 0)
    return (false); //Test if Slave1 and 2 are detected. If not, bail.

  setBulbCurrent(AS7265X_LED_CURRENT_LIMIT_12_5MA, AS7265x_LED_WHITE);
  setBulbCurrent(AS7265X_LED_CURRENT_LIMIT_12_5MA, AS7265x_LED_IR);
  setBulbCurrent(AS7265X_LED_CURRENT_LIMIT_12_5MA, AS7265x_LED_UV);

  disableBulb(AS7265x_LED_WHITE); //Turn off bulb to avoid heating sensor
  disableBulb(AS7265x_LED_IR);
  disableBulb(AS7265x_LED_UV);

  setIndicatorCurrent(AS7265X_INDICATOR_CURRENT_LIMIT_8MA); //Set to 8mA (maximum)
  enableIndicator();

  setIntegrationCycles(49); //50 * 2.8ms = 140ms. 0 to 255 is valid.
  //If you use Mode 2 or 3 (all the colors) then integration time is double. 140*2 = 280ms between readings.

  setGain(AS7265X_GAIN_64X); //Set gain to 64x

  setMeasurementMode(AS7265X_MEASUREMENT_MODE_6CHAN_ONE_SHOT); //One-shot reading of VBGYOR

  enableInterrupt();

  return (true); //We're all setup!
}

and the function isConnected which returns false:

Code:
boolean AS7265X::isConnected()
{
  //Give IC 660ms for startup - max 1000ms
  for (uint8_t x = 0; x < 100; x++)
  {
    _i2cPort->beginTransmission((uint8_t)AS7265X_ADDR);
#ifdef ENERGIA
    _i2cPort->write(0x00); //See issue: https://github.com/sparkfun/SparkFun_AS7265x_Arduino_Library/issues/4
#endif
    if (_i2cPort->endTransmission() == 0)
      return (true); //Sensor ACK'd
    delay(10);
  }
  return (false); //Sensor did not ACK
}
 
Back
Top