Add a TSL4531 driver and example
This commit is contained in:
parent
813477aa8a
commit
8b5ee93b55
6 changed files with 291 additions and 2 deletions
3
examples/tsl4531/Makefile
Normal file
3
examples/tsl4531/Makefile
Normal file
|
@ -0,0 +1,3 @@
|
|||
PROGRAM=tsl4531_example
|
||||
EXTRA_COMPONENTS = extras/i2c extras/tsl4531
|
||||
include ../../common.mk
|
55
examples/tsl4531/tsl4531_example.c
Normal file
55
examples/tsl4531/tsl4531_example.c
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* This sample code is in the public domain.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "esp/uart.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "i2c/i2c.h"
|
||||
#include "task.h"
|
||||
#include "tsl4531/tsl4531.h"
|
||||
|
||||
/* An example using the TSL4531 light sensor
|
||||
* to read and print lux values from a sensor
|
||||
* attached to GPIO pin 2 (SCL) and GPIO pin 0 (SDA)
|
||||
* Connect 3.3v from the ESP to Vin and GND to GND
|
||||
*/
|
||||
|
||||
#define SCL_PIN (2)
|
||||
#define SDA_PIN (0)
|
||||
|
||||
void tsl4531MeasurementTask(void *pvParameters)
|
||||
{
|
||||
tsl4531_t lightSensor;
|
||||
lightSensor.i2c_addr = TSL4531_I2C_ADDR;
|
||||
tsl4531_init(&lightSensor);
|
||||
|
||||
tsl4531_set_integration_time(&lightSensor, TSL4531_INTEGRATION_400MS);
|
||||
tsl4531_set_power_save_skip(&lightSensor, true);
|
||||
|
||||
uint16_t lux = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (tsl4531_read_lux(&lightSensor, &lux))
|
||||
{
|
||||
printf("Lux: %u\n", lux);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Could not read data from TSL4531\n");
|
||||
}
|
||||
|
||||
// 0.05 second delay
|
||||
vTaskDelay(50 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
void user_init(void)
|
||||
{
|
||||
uart_set_baud(0, 115200);
|
||||
i2c_init(SCL_PIN, SDA_PIN);
|
||||
|
||||
xTaskCreate(tsl4531MeasurementTask, "tsl4531MeasurementTask", 256, NULL, 2, NULL);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue