tsl2561 arduino Lib crashing teensy

Status
Not open for further replies.

Brendon Shaw

Active member
I am using a tsl2561 light sensor with the adafruit lib, but it crashs the teensy code. I think the problem is the need to use events and process.

Can anyone recommend a fix or straight driver for the tsl2561 device, as all I can find is the adafruit one. Or is there a way to get events working on teensy?
 
There isn't anything regarding "events" or "process" in that lib.
For me, it compiles perfectly.
Could you post the errormessage ?

A minor issue: Did you add "#include <Wire.h>" to your sketch ?
 
Have you added 4k7 pullups to the I2C-Bus, or are they "on board" of this sensor ?
Pullups are needed for I2C on Teensy
 
Yes I have added the pull up 4.7k to 3.3 on both lines. This is copy of the code, it's the standard code from adafruit but I think it crashes the teensy as I do no get any serial prints our



#include <SPI.h>
#include "Adafruit_BLE_UART.h"
#include "IOSControllerTeensyForBluefruit.h"
//#include <Process.h>
#include <Wire.h>
#include <AM2321.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_TSL2561_U.h>
#include <Adafruit_BMP085_U.h>

void TSL2561_sensor_read(void);
void TSL2561_configureSensor(void);
void bmp180_pressure(void);
void readByAM2321(void);


Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);
Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);

setup()
{
Serial.begin(9600);
Wire.begin();
TSL2561_configureSensor();

}


loop()
{

TSL2561_sensor_read();
Serial.println(LightLevel);

delay(10000);
}



void TSL2561_sensor_read(void)
{
/* Get a new sensor event */
sensors_event_t event;
tsl.getEvent(&event);
if (event.light)
{
Light_level = event.light;

}

}


void TSL2561_configureSensor(void)
{
tsl.enableAutoRange(true); /* Auto-gain ... switches automatically between 1x and 16x */
tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS); /* fast but low resolution */
}
 
Put this code into setup before the configure and it will wait for USB Serial to come online. It may also pause the Teensy long enough for the TSL2561_configureSensor(); to work. You'll at least see the LED blink to show you it is running. You may need a bit more delay before the configure as well as the Teensy powers up running surprisingly fast..

Code:
#define qBlink() (digitalWriteFast(LED_BUILTIN, !digitalReadFast(LED_BUILTIN) ))
void setup() {
  Serial.begin(38400);
  digitalWrite(LED_BUILTIN, HIGH);
  pinMode(LED_BUILTIN, OUTPUT);
  while (!Serial && (millis () <= 4000))
    qBlink();
}
 
Thanks for all the help, I managed to fix it by reinstalling the lib and adding a delay in the start up. Still not quite sure what was the really problem, but it's now fixed.

Another potential problem was the bread broad and lose hook up wire to the pull up resistors.

Many thanks for all the help and support
 
Yup, this is almost certainly another sensor with a startup time. Normal Arduino boards have slow boot times, so by the time setup() finally runs, these types of sensors are ready to talk. Teensy boots up very fast. It's a common problem, where you need a delay before initializing the sensor.
 
Status
Not open for further replies.
Back
Top