Added I2C and BMP280
i2c already running and functional, bmp280 code is still in the main and needs re-organisation Temperature readout works, pressure is not required at this stage
This commit is contained in:
+67
-62
@@ -33,7 +33,9 @@
|
||||
#include "driver/uart_select.h"
|
||||
#include "driver/gptimer.h"
|
||||
|
||||
#include "inc/bmp280.h"
|
||||
#include "inc/gpio.h"
|
||||
#include "inc/i2c.h"
|
||||
#include "inc/led_strip_encoder.h"
|
||||
#include "inc/ledmatrix.h"
|
||||
#include "inc/logger.h"
|
||||
@@ -49,8 +51,6 @@
|
||||
|
||||
#define RMT_LED_STRIP_RESOLUTION_HZ 10000000 // 10MHz resolution, 1 tick = 0.1us (led strip needs a high resolution)
|
||||
#define RMT_LED_STRIP_GPIO_NUM 0
|
||||
#define RMT_LED_STRIP_GPIO_AUX 1
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Type definitions
|
||||
@@ -81,32 +81,16 @@ static rmt_encoder_handle_t led_encoder = NULL;
|
||||
static LEDMatrix_Parameters_t ledmatrix_parameters =
|
||||
{
|
||||
LEDMATRIX_ORIENTATION_ROW_LEFT_RIGHT,
|
||||
LEDMATRIX_ORIENTATION_COLUM_UP_DOWN,
|
||||
LEDMATRIX_ORIENTATION_COLUM_DOWN_UP,
|
||||
LEDMATRIX_ORIENTATION_ROW,
|
||||
6,
|
||||
4,
|
||||
11,
|
||||
10,
|
||||
&led_chan,
|
||||
&led_encoder,
|
||||
&tx_config
|
||||
};
|
||||
|
||||
static rmt_channel_handle_t led_aux_chan = NULL;
|
||||
static rmt_transmit_config_t tx_aux_config;
|
||||
static rmt_encoder_handle_t led_aux_encoder = NULL;
|
||||
static LEDMatrix_Parameters_t ledmatrix_aux_parameters =
|
||||
{
|
||||
LEDMATRIX_ORIENTATION_ROW_LEFT_RIGHT,
|
||||
LEDMATRIX_ORIENTATION_COLUM_DOWN_UP,
|
||||
LEDMATRIX_ORIENTATION_COLUM,
|
||||
11,
|
||||
10,
|
||||
&led_aux_chan,
|
||||
&led_aux_encoder,
|
||||
&tx_aux_config
|
||||
};
|
||||
|
||||
static LEDMatrix matrix(&ledmatrix_parameters);
|
||||
static LEDMatrix aux(&ledmatrix_aux_parameters);
|
||||
|
||||
static Wordmap map(&matrix);
|
||||
|
||||
@@ -125,11 +109,28 @@ static bool timerCallback(gptimer_handle_t timer, const gptimer_alarm_event_data
|
||||
static void devTask(void* parameters);
|
||||
|
||||
static void colourMapTask(void* parameters);
|
||||
|
||||
static int bmp280_compensate_T_int32(int adc_T);
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Function definitions
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
int t_fine;
|
||||
uint16_t dig_T1 = 0x6AA3;
|
||||
int16_t dig_T2 = 0x6555;
|
||||
int16_t dig_T3 = 0x0032;
|
||||
int bmp280_compensate_T_int32(int adc_T)
|
||||
{
|
||||
int var1, var2, T;
|
||||
var1 = ((((adc_T>>3) - ((int)dig_T1<<1))) * ((int)dig_T2)) >> 11;
|
||||
var2 = (((((adc_T>>4) - ((int)dig_T1)) * ((adc_T>>4) - ((int)dig_T1))) >> 12) * ((int)dig_T3)) >> 14;
|
||||
t_fine = var1 + var2;
|
||||
T = (t_fine * 5 + 128) >> 8;
|
||||
return T;
|
||||
}
|
||||
|
||||
|
||||
extern "C" void app_main(void)
|
||||
{
|
||||
esp_log_level_set("*", ESP_LOG_WARN);
|
||||
@@ -164,12 +165,12 @@ extern "C" void app_main(void)
|
||||
//
|
||||
Logger logger(10, uartPort);
|
||||
|
||||
LOGGER_PRINT("-----------------------------------------------------------------------");
|
||||
LOGGER_PRINT("System Start");
|
||||
LOGGER_PRINT("");
|
||||
LOGGER_PRINT("WordClock");
|
||||
LOGGER_PRINT("Release: %f", RELEASE);
|
||||
LOGGER_PRINT("Compiled on %d %d", __TIME__, __DATE__);
|
||||
LOGGER_PRINT("\n\r-----------------------------------------------------------------------\n\r");
|
||||
LOGGER_PRINT("System Start\n\r");
|
||||
LOGGER_PRINT("\n\r");
|
||||
LOGGER_PRINT("WordClock\n\r");
|
||||
LOGGER_PRINT("Release: %f\n\r", RELEASE);
|
||||
LOGGER_PRINT("Compiled on %d %d\n\r\n\r\n\r", __TIME__, __DATE__);
|
||||
|
||||
|
||||
//--------------------------------------------
|
||||
@@ -202,38 +203,30 @@ extern "C" void app_main(void)
|
||||
|
||||
|
||||
//--------------------------------------------
|
||||
// RMT Channel
|
||||
// I2C
|
||||
//
|
||||
LOGGER_INFO("Create RMT TX channel");
|
||||
// memset(&tx_chan_config, 0, sizeof(tx_chan_config));
|
||||
// SourceClock: GPIO 8
|
||||
// SourceData: GPIO 9
|
||||
I2C i2c0(8, 9);
|
||||
|
||||
// tx_chan_config.clk_src = RMT_CLK_SRC_DEFAULT; // select source clock
|
||||
// tx_chan_config.gpio_num = RMT_LED_STRIP_GPIO_AUX;
|
||||
// tx_chan_config.mem_block_symbols = 64; // increase the block size can make the LED less flickering
|
||||
// tx_chan_config.resolution_hz = RMT_LED_STRIP_RESOLUTION_HZ;
|
||||
// tx_chan_config.trans_queue_depth = 4;
|
||||
|
||||
// ESP_ERROR_CHECK(rmt_new_tx_channel(&tx_chan_config, &led_aux_chan));
|
||||
|
||||
// LOGGER_INFO("Install led strip encoder");
|
||||
// led_strip_encoder_config_t encoder_aux_config;
|
||||
// memset(&encoder_aux_config, 0, sizeof(encoder_aux_config));
|
||||
// encoder_config.resolution = RMT_LED_STRIP_RESOLUTION_HZ;
|
||||
|
||||
// ESP_ERROR_CHECK(rmt_new_led_strip_encoder(&encoder_aux_config, &led_aux_encoder));
|
||||
|
||||
// LOGGER_INFO("Enable RMT TX channel");
|
||||
// ESP_ERROR_CHECK(rmt_enable(led_chan));
|
||||
|
||||
// memset(&tx_config, 0, sizeof(tx_config));
|
||||
// tx_config.loop_count = 0;
|
||||
uint8_t data[6];
|
||||
// Read BME280 ID register
|
||||
i2c0.read_register(0x76, 0xD0, data, 1);
|
||||
LOGGER_DEBUG("BMP280 ID: %02X", data[0]);
|
||||
// Read compensation values
|
||||
i2c0.read_register(0x76, 0x88, data, 6);
|
||||
// Set the oversampling to x1
|
||||
uint8_t writeData = 0x27;
|
||||
i2c0.write_register(0x76, 0xF4, &writeData, 1);
|
||||
|
||||
|
||||
//--------------------------------------------
|
||||
// LED Matrix
|
||||
//
|
||||
matrix.setGlobalColour(0x10, 0, 0x04);
|
||||
matrix.setGlobalColour(0x80, 0, 0x40);
|
||||
// matrix.setGlobalColour(0x80, 0, 0x40);
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------
|
||||
// GP Timer for automatic matrix re-draw trigger
|
||||
@@ -263,11 +256,11 @@ extern "C" void app_main(void)
|
||||
LOGGER_ERROR("Task not created");
|
||||
}
|
||||
|
||||
// // Create the colour Map task
|
||||
// if(xTaskCreate(colourMapTask, "ColourTask", 2048, NULL, 3, &colourMapTaskHandle) != pdPASS)
|
||||
// {
|
||||
// LOGGER_ERROR("Task not created");
|
||||
// }
|
||||
// Create the colour Map task
|
||||
if(xTaskCreate(colourMapTask, "ColourTask", 2048, NULL, 3, &colourMapTaskHandle) != pdPASS)
|
||||
{
|
||||
LOGGER_ERROR("Task not created");
|
||||
}
|
||||
|
||||
Wifi wifi;
|
||||
wifi.start_client();
|
||||
@@ -292,6 +285,18 @@ extern "C" void app_main(void)
|
||||
// Add a seconds indicator
|
||||
matrix.setPixelValue(10, 9, clock.getTime() % 2);
|
||||
|
||||
|
||||
i2c0.read_register(0x76, 0xF7, data, 3);
|
||||
LOGGER_DEBUG("BMP280 pressure: %02X %02X %02X", data[0], data[1], data[2]);
|
||||
|
||||
i2c0.read_register(0x76, 0xFA, data, 3);
|
||||
int32_t value = 0;
|
||||
value |= data[0] << 12;
|
||||
value |= data[1] << 4;
|
||||
value |= data[2] >> 4;
|
||||
int valueComp = bmp280_compensate_T_int32(value);
|
||||
LOGGER_DEBUG("BMP280 temperature: %02X %02X %02X -> %d", data[0], data[1], data[2], valueComp);
|
||||
|
||||
// Update the clock every second (1000 ms)
|
||||
vTaskDelay(1000);
|
||||
|
||||
@@ -314,9 +319,9 @@ static void devTask(void* parameters)
|
||||
|
||||
static void colourMapTask(void* parameters)
|
||||
{
|
||||
uint8_t red = 0;
|
||||
uint8_t red = 0x10;
|
||||
uint8_t green = 0;
|
||||
uint8_t blue = 0;
|
||||
uint8_t blue = 0x04;
|
||||
|
||||
uint32_t counter = 0;
|
||||
|
||||
@@ -325,10 +330,10 @@ static void colourMapTask(void* parameters)
|
||||
{
|
||||
matrix.setGlobalColour(red, green, blue);
|
||||
|
||||
red = counter & 0xFF;
|
||||
green = (counter >> 8) & 0xFF;
|
||||
blue = (counter >> 16) & 0xFF;
|
||||
counter++;
|
||||
// red = counter & 0xFF;
|
||||
// green = (counter >> 8) & 0xFF;
|
||||
// blue = (counter >> 16) & 0xFF;
|
||||
// counter++;
|
||||
vTaskDelay(30);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user