Skip to content

Commit e67897e

Browse files
authored
Merge pull request #14 from sciosense/2.0.4
- updated README.md - added SPI examples for ENS160/ENS161
2 parents 4b7a58a + fbd0f6f commit e67897e

File tree

9 files changed

+154
-138
lines changed

9 files changed

+154
-138
lines changed

README.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ScioSense ENS16x Arduino Library
2-
Arduino library for the ENS16x digital four channel MOX gas sensors with I2C interface from ScioSense.
2+
Arduino library for the ENS16x digital four channel MOX gas sensors with I2C/SPI interface from ScioSense.
33

44
<img src="images/ens16x.png" width="400">
55

@@ -43,9 +43,9 @@ For the installation of the ESP32 in the Arduino IDE, see [Arduino ESP32 Install
4343
Please make sure that you use the correct supply voltage:
4444
- The ENS16x runs at VDD = 1.8 V. If you are using the Sciosense ENS16x breakout board, you can use VDD = 3.3 V thanks
4545
to the onboard LDO.
46-
- The I2C communication is 3.3 V tolerant.
46+
- The I2C/SPI communication is 3.3 V tolerant.
4747

48-
### Example with ESP32
48+
### I²C example with ESP32
4949
This example shows how to wire a [ESP32DevKitC](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/hw-reference/esp32/get-started-devkitc.html#get-started-esp32-devkitc-board-front)
5050
with the ENS16x breakout board for I2C communication.
5151

@@ -56,7 +56,22 @@ with the ENS16x breakout board for I2C communication.
5656
| SDA | G21 |
5757
| SCL | G22 |
5858

59-
<img src="images/ens16x_pin_out_esp32.png" width="1000">
59+
<img src="images/ESP32_I2C.png" width="1000">
60+
61+
### SPI example with ESP32
62+
This example shows how to wire a [ESP32DevKitC](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/hw-reference/esp32/get-started-devkitc.html#get-started-esp32-devkitc-board-front)
63+
with the ENS16x breakout board for SPI communication. Make sure you modify the evaluation board by opening solderbridge J3 according application note [SC-002530-AN](www.sciosense.com/wp-content/uploads/2025/02/ENS160-ENS161-Evaluation-Board-Application-Note.pdf).
64+
65+
| ENS16x breakout board | ESP32 |
66+
|:---------------------:|:-----:|
67+
| VDD | 3V3 |
68+
| GND | GND |
69+
| MOSI | G23 |
70+
| MISO | G19 |
71+
| SCK | G18 |
72+
| CS | G05 |
73+
74+
<img src="images/ESP32_SPI.png" width="1000">
6075

6176
## Build an example
6277
To build an example sketch
@@ -69,5 +84,3 @@ To build an example sketch
6984
This library is developed for ScioSense by [at² GmbH](https://www.at2-software.com/en/)
7085

7186
@at2software
72-
73-
### ScioSense is a Joint Venture of ams AG
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
Basic example for ScioSense ENS160 using SPI Interface on ESP32 DevMod
3+
*/
4+
5+
#include <Arduino.h>
6+
#include <ScioSense_ENS16x.h>
7+
8+
9+
//#define USE_INTERRUPT
10+
#define PIN_INTN 2 // define pin for interrupt
11+
#define PIN_CS 5 // define pin for chip select
12+
13+
ENS160 ens160;
14+
15+
void setup()
16+
{
17+
Serial.begin(9600);
18+
ens160.enableDebugging(Serial);
19+
20+
SPI.begin();
21+
ens160.begin(&SPI, PIN_CS);
22+
23+
Serial.println("begin..");
24+
while (ens160.init() != true)
25+
{
26+
Serial.print(".");
27+
delay(1000);
28+
}
29+
Serial.println("success");
30+
31+
#ifdef USE_INTERRUPT
32+
ens160.setInterruptPin(INTN);
33+
ens160.writeConfiguration
34+
(
35+
ENS16X_CONFIGURATION_INTERRUPT_ENABLE
36+
| ENS16X_CONFIGURATION_NEW_GENERAL_PURPOSE_DATA
37+
| ENS16X_CONFIGURATION_NEW_DATA
38+
);
39+
#endif
40+
41+
ens160.startStandardMeasure();
42+
}
43+
44+
void loop()
45+
{
46+
ens160.wait();
47+
48+
// Enable Tools->Serial Plotter to see the sensor output as a graph
49+
50+
if (ens160.update() == RESULT_OK)
51+
{
52+
if (ens160.hasNewData())
53+
{
54+
Serial.print("AQI UBA:"); Serial.print((uint8_t)ens160.getAirQualityIndex_UBA());
55+
56+
Serial.print("\tTVOC:"); Serial.print(ens160.getTvoc());
57+
Serial.print("\tECO2:"); Serial.println(ens160.getEco2());
58+
}
59+
60+
if (ens160.hasNewGeneralPurposeData())
61+
{
62+
Serial.print("RS0:"); Serial.print(ens160.getRs0());
63+
Serial.print("\tRS1:"); Serial.print(ens160.getRs1());
64+
Serial.print("\tRS2:"); Serial.print(ens160.getRs2());
65+
Serial.print("\tRS3:"); Serial.println(ens160.getRs3());
66+
}
67+
}
68+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
Basic example for ScioSense ENS161 using SPI Interface on ESP32 DevMod
3+
*/
4+
5+
#include <Arduino.h>
6+
#include <ScioSense_ENS16x.h>
7+
8+
//#define USE_INTERRUPT
9+
#define PIN_INTN 2 // define pin for interrupt
10+
#define PIN_CS 5 // define pin for chip select
11+
12+
ENS161 ens161;
13+
14+
void setup() {
15+
Serial.begin(9600);
16+
ens161.enableDebugging(Serial);
17+
18+
SPI.begin();
19+
ens161.begin(&SPI, PIN_CS);
20+
21+
Serial.println("begin..");
22+
while (ens161.init() != true) {
23+
Serial.print(".");
24+
delay(1000);
25+
}
26+
Serial.println("success");
27+
28+
#ifdef USE_INTERRUPT
29+
ens161.setInterruptPin(PIN_INTN);
30+
ens161.writeConfiguration(
31+
ENS16X_CONFIGURATION_INTERRUPT_ENABLE
32+
| ENS16X_CONFIGURATION_NEW_GENERAL_PURPOSE_DATA
33+
| ENS16X_CONFIGURATION_NEW_DATA);
34+
#endif
35+
36+
ens161.startStandardMeasure();
37+
}
38+
39+
void loop() {
40+
ens161.wait();
41+
42+
// Enable Tools->Serial Plotter to see the sensor output as a graph
43+
44+
if (ens161.update() == RESULT_OK) {
45+
if (ens161.hasNewData()) {
46+
Serial.print("AQI UBA:");
47+
Serial.print((uint8_t)ens161.getAirQualityIndex_UBA());
48+
49+
Serial.print("\tTVOC:");
50+
Serial.print(ens161.getTvoc());
51+
Serial.print("\tECO2:");
52+
Serial.println(ens161.getEco2());
53+
}
54+
55+
if (ens161.hasNewGeneralPurposeData()) {
56+
Serial.print("RS0:");
57+
Serial.print(ens161.getRs0());
58+
Serial.print("\tRS1:");
59+
Serial.print(ens161.getRs1());
60+
Serial.print("\tRS2:");
61+
Serial.print(ens161.getRs2());
62+
Serial.print("\tRS3:");
63+
Serial.println(ens161.getRs3());
64+
}
65+
}
66+
}

images/ESP32_I2C.png

356 KB
Loading

images/ESP32_SPI.png

372 KB
Loading

images/ens16x_pin_out_esp32.png

-615 KB
Binary file not shown.

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=ScioSense_ENS16x
2-
version=2.0.3
2+
version=2.0.4
33
author=ScioSense
44
maintainer=ScioSense
55
sentence=Arduino library for the ENS16x digital four channel MOX gas sensor family with I2C interface from ScioSense

src/lib/io/ScioSense_IOInterface_Arduino_Ens220_SPI.h

Lines changed: 0 additions & 74 deletions
This file was deleted.

src/lib/io/ScioSense_IOInterface_Arduino_Serial.h

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)