Skip to content

Commit 5312bfe

Browse files
committed
Add a working example for esp32_devkitc_v4
The driver in esp32 is not anymore working and will be replaced for all driver packages. For now we provide a dedicated example for sen66 and the device kit esp32_devkitc_v4. The example can be built and executed using idf.py
1 parent d2c461a commit 5312bfe

20 files changed

+3854
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
Language: Cpp
3+
BasedOnStyle: LLVM
4+
IndentWidth: 4
5+
AlignAfterOpenBracket: Align
6+
AllowShortBlocksOnASingleLine: false
7+
AllowShortCaseLabelsOnASingleLine: false
8+
AllowShortFunctionsOnASingleLine: false
9+
IndentCaseLabels: true
10+
SpacesBeforeTrailingComments: 2
11+
PointerAlignment: Left
12+
AlignEscapedNewlines: Left
13+
ForEachMacros: ['TEST_GROUP', 'TEST']
14+
...
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CompileFlags:
2+
Remove: [-m*, -f*]
3+
CompilationDatabase: build
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# The following lines of boilerplate have to be in your project's CMakeLists
2+
# in this exact order for cmake to work correctly
3+
cmake_minimum_required(VERSION 3.22)
4+
5+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
6+
project(sen66_i2c_example_usage)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
dependencies:
2+
idf:
3+
source:
4+
type: idf
5+
version: 6.0.0
6+
direct_dependencies:
7+
- idf
8+
manifest_hash: e44bf68eca6b7b264ddae08cd014cd3294c0473230381b6d6f88ed18ec879038
9+
target: esp32
10+
version: 2.0.0
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
idf_component_register(SRCS "sen66_i2c.c" "sen66_i2c_example_usage.c" "sensirion_common.c" "sensirion_i2c.c" "sensirion_i2c_hal.c"
2+
INCLUDE_DIRS ".")
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
menu "Configuration Esp32 WROVER Kit I2C V4"
2+
3+
orsource "$IDF_PATH/examples/common_components/env_caps/$IDF_TARGET/Kconfig.env_caps"
4+
5+
config I2C_MASTER_SCL
6+
int "SCL GPIO Num"
7+
range ENV_GPIO_RANGE_MIN ENV_GPIO_OUT_RANGE_MAX
8+
default 22
9+
help
10+
GPIO number for I2C Master clock line.
11+
12+
config I2C_MASTER_SDA
13+
int "SDA GPIO Num"
14+
range ENV_GPIO_RANGE_MIN ENV_GPIO_OUT_RANGE_MAX
15+
default 21
16+
help
17+
GPIO number for I2C Master data line.
18+
19+
config I2C_MASTER_FREQUENCY
20+
int "Master Frequency"
21+
default 400000
22+
help
23+
I2C Speed of Master device.
24+
25+
endmenu
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## IDF Component Manager Manifest File
2+
dependencies:
3+
## Required IDF version
4+
idf:
5+
version: ">=4.1.0"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../sen66_i2c.c
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../sen66_i2c.h
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* THIS FILE IS AUTOMATICALLY GENERATED
3+
*
4+
* Generator: sensirion-driver-generator 1.1.2
5+
* Product: sen66
6+
* Model-Version: 1.6.0
7+
*/
8+
/*
9+
* Copyright (c) 2025, Sensirion AG
10+
* All rights reserved.
11+
*
12+
* Redistribution and use in source and binary forms, with or without
13+
* modification, are permitted provided that the following conditions are met:
14+
*
15+
* * Redistributions of source code must retain the above copyright notice, this
16+
* list of conditions and the following disclaimer.
17+
*
18+
* * Redistributions in binary form must reproduce the above copyright notice,
19+
* this list of conditions and the following disclaimer in the documentation
20+
* and/or other materials provided with the distribution.
21+
*
22+
* * Neither the name of Sensirion AG nor the names of its
23+
* contributors may be used to endorse or promote products derived from
24+
* this software without specific prior written permission.
25+
*
26+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
30+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36+
* POSSIBILITY OF SUCH DAMAGE.
37+
*/
38+
#include "sen66_i2c.h"
39+
#include "sensirion_common.h"
40+
#include "sensirion_i2c_hal.h"
41+
#include <inttypes.h> // PRIx64
42+
#include <stdio.h> // printf
43+
44+
#define sensirion_hal_sleep_us sensirion_i2c_hal_sleep_usec
45+
46+
int app_main(void) {
47+
int16_t error = NO_ERROR;
48+
sensirion_i2c_hal_init();
49+
sen66_init(SEN66_I2C_ADDR_6B);
50+
51+
error = sen66_device_reset();
52+
if (error != NO_ERROR) {
53+
printf("error executing device_reset(): %i\n", error);
54+
return error;
55+
}
56+
sensirion_hal_sleep_us(1200000);
57+
int8_t serial_number[32] = {0};
58+
error = sen66_get_serial_number(serial_number, 32);
59+
if (error != NO_ERROR) {
60+
printf("error executing get_serial_number(): %i\n", error);
61+
return error;
62+
}
63+
printf("serial_number: %s\n", serial_number);
64+
error = sen66_start_continuous_measurement();
65+
if (error != NO_ERROR) {
66+
printf("error executing start_continuous_measurement(): %i\n", error);
67+
return error;
68+
}
69+
uint16_t mass_concentration_pm1p0 = 0;
70+
uint16_t mass_concentration_pm2p5 = 0;
71+
uint16_t mass_concentration_pm4p0 = 0;
72+
uint16_t mass_concentration_pm10p0 = 0;
73+
int16_t ambient_humidity = 0;
74+
int16_t ambient_temperature = 0;
75+
int16_t voc_index = 0;
76+
int16_t nox_index = 0;
77+
uint16_t co2 = 0;
78+
uint16_t repetition = 0;
79+
for (repetition = 0; repetition < 100; repetition++) {
80+
sensirion_hal_sleep_us(1000000);
81+
error = sen66_read_measured_values_as_integers(
82+
&mass_concentration_pm1p0, &mass_concentration_pm2p5,
83+
&mass_concentration_pm4p0, &mass_concentration_pm10p0,
84+
&ambient_humidity, &ambient_temperature, &voc_index, &nox_index,
85+
&co2);
86+
if (error != NO_ERROR) {
87+
printf("error executing read_measured_values_as_integers(): %i\n",
88+
error);
89+
continue;
90+
}
91+
printf("mass_concentration_pm1p0: %u ", mass_concentration_pm1p0);
92+
printf("mass_concentration_pm2p5: %u ", mass_concentration_pm2p5);
93+
printf("mass_concentration_pm4p0: %u ", mass_concentration_pm4p0);
94+
printf("mass_concentration_pm10p0: %u ", mass_concentration_pm10p0);
95+
printf("ambient_humidity: %i ", ambient_humidity);
96+
printf("ambient_temperature: %i ", ambient_temperature);
97+
printf("voc_index: %i ", voc_index);
98+
printf("nox_index: %i ", nox_index);
99+
printf("co2: %u\n", co2);
100+
}
101+
102+
error = sen66_stop_measurement();
103+
if (error != NO_ERROR) {
104+
return error;
105+
}
106+
return NO_ERROR;
107+
}

0 commit comments

Comments
 (0)