# Sensirion I²C SGP43 Arduino Library

This is the Sensirion SGP43 library for Arduino allowing you to
communicate with a SGP43 sensor
over I²C.

<img src="images/sgp4x-evalkit.png" width="226" alt="Image of the SGP4x eval kit">

Click [here](https://sensirion.com/products/catalog/SGP41/) to learn more about the Sensirion SGP43 sensor.

Air Quality Sensor for VOC and NOx Measurements.

The default I²C address of [SGP43](https://sensirion.com/products/catalog/SGP41/) is **0x59**.

## Installation of the library

This library can be installed using the Arduino Library manager:
Start the [Arduino IDE](http://www.arduino.cc/en/main/software) and open
the Library Manager via

`Sketch` ➔ `Include Library` ➔ `Manage Libraries...`

Search for the `Sensirion I2C SGP43` library in the `Filter
your search...` field and install it by clicking the `install` button.

If you cannot find it in the library manager, download the latest release as .zip file
and add it to your [Arduino IDE](http://www.arduino.cc/en/main/software) via

`Sketch` ➔ `Include Library` ➔ `Add .ZIP Library...`

Don't forget to **install the dependencies** listed below the same way via library
manager or `Add .ZIP Library`

#### Dependencies

* [Sensirion Core](https://github.com/Sensirion/arduino-core)

## Connect the sensor

Use the following pin description to connect your SGP43 to the standard I²C bus of your Arduino board:

<img src="images/sgp41_pinout.jpg" width="223" alt="The pinout of the SGP43 sensor.">

| *Pin* | *Cable Color* | *Name* | *Description*                   | *Comments*                                                 |
|-------|---------------|:------:|---------------------------------|------------------------------------------------------------|
| 1     | red           |  VDD   | Supply Voltage                  | 1.7V to 3.6V                                               |
| 2     | black         |  GND   | Ground                          |                                                            |
| 3     | green         |  SDA   | I2C: Serial data input / output |                                                            |
| 4     | blue          |   NC   | Do not connect                  |                                                            |
| 5     |               |  VDDH  |                                 | Supply voltage hotplate; see data sheet on how to connect. |
| 6     | yellow        |  SCL   | I2C: Serial clock input         |                                                            |

The recommended voltage is 3.3V.

### Board specific wiring

You will find pinout schematics for recommended board models below:

<details><summary>SparkFun ESP32-C6 Qwiic Pocket</summary>
<p>
<img src="images/SparkFun-ESP32-C6-Qwiic-Pocket.png" width="300px" alt="A photo of the SparkFun ESP32-C6 Qwiic Pocket" >
</p>

<p>
Qwiic connection (no soldering):

- The SparkFun ESP32-C6 Qwiic Pocket has a 4-pin Qwiic connector (JST-SH) that is wired to the I²C bus at 3.3V. The
  SGP43 sensor uses I²C at address 0x59.
- Simply plug a Qwiic cable between the board and the SGP43 eval kit. Power the board over USB-C. No additional wiring
  is required.
- If your SGP43 board exposes a STEMMA QT/Qwiic port, use a standard Qwiic-to-Qwiic cable. If it only exposes header
  pins, use a Qwiic adapter cable to break out to 3.3V, GND, SDA and SCL.

Notes:

- The Pocket board provides the required pull-ups on the I²C lines.
- The default Wire instance is used by this library; the Qwiic connector is on the default I²C pins, so no pin
  configuration is needed in code.

<img src="images/sparkfun-pocket-with-sgp4x-evalkit.png" width="600px" alt="SparkFun ESP32-C6 Qwiic Pocket with SGP43 eval kit">

Arduino IDE board support (Espressif) and board selection:

1) Install ESP32 boards by Espressif Systems
    - Open Arduino IDE ➔ File ➔ Preferences ➔ Additional Boards Manager URLs and add:
      https://espressif.github.io/arduino-esp32/package_esp32_index.json
    - Then go to Tools ➔ Board ➔ Boards Manager…, search for “esp32” by “Espressif Systems” and click Install.

2) Select the correct board
    - Once you have installed the Espressif ESP32 board package, choose: Tools ➔ Board ➔ esp32 ➔ “SparkFun ESP32-C6
      Qwiic Pocket”.
    - Optionally you can also use the generic Espressif definition: Tools ➔ Board ➔ esp32 ➔ “ESP32C6 Dev Module”. This
      works well for the examples in this library.

After selecting the board, set the upload port under Tools ➔ Port, open File ➔ Examples ➔ Sensirion I2C SGP43 ➔
exampleSGP43Classifier, and upload. Open Tools ➔ Serial Monitor at 115200 baud to see readings.

</p>
</details>

<details><summary>Arduino Uno</summary>
<p>

| *SGP43* | *SGP43 Pin* | *Cable Color* | *Board Pin* |
|:-------:|-------------|---------------|-------------|
|   VDD   | 1           | red           | 3.3V        |
|   GND   | 2           | black         | GND         |
|   SDA   | 3           | green         | D18/SDA     |
|  VDDH   | 5           |               |             |
|   SCL   | 6           | yellow        | D19/SCL     |

<img src="images/Arduino-Uno-Rev3-i2c-pinout-3.3V.png" width="600px" alt="Arduino UNO pinout image">
</p>
</details>




<details><summary>Arduino Nano</summary>
<p>

| *SGP43* | *SGP43 Pin* | *Cable Color* | *Board Pin* |
|:-------:|-------------|---------------|-------------|
|   VDD   | 1           | red           | 3.3V        |
|   GND   | 2           | black         | GND         |
|   SDA   | 3           | green         | A4          |
|  VDDH   | 5           |               |             |
|   SCL   | 6           | yellow        | A5          |

<img src="images/Arduino-Nano-i2c-pinout-3.3V.png" width="600px" alt="Arduino Nano pinout image">
</p>
</details>




<details><summary>Arduino Micro</summary>
<p>

| *SGP43* | *SGP43 Pin* | *Cable Color* | *Board Pin* |
|:-------:|-------------|---------------|-------------|
|   VDD   | 1           | red           | 3.3V        |
|   GND   | 2           | black         | GND         |
|   SDA   | 3           | green         | D2/SDA      |
|  VDDH   | 5           |               |             |
|   SCL   | 6           | yellow        | ~D3/SCL     |

<img src="images/Arduino-Micro-i2c-pinout-3.3V.png" width="600px" alt="Arduino Micro pinout image">
</p>
</details>




<details><summary>Arduino Mega 2560</summary>
<p>

| *SGP43* | *SGP43 Pin* | *Cable Color* | *Board Pin* |
|:-------:|-------------|---------------|-------------|
|   VDD   | 1           | red           | 3.3V        |
|   GND   | 2           | black         | GND         |
|   SDA   | 3           | green         | D20/SDA     |
|  VDDH   | 5           |               |             |
|   SCL   | 6           | yellow        | D21/SCL     |

<img src="images/Arduino-Mega-2560-Rev3-i2c-pinout-3.3V.png" width="600px" alt="Arduino Mega 2560 pinout image">
</p>
</details>




<details><summary>ESP32 DevKitC</summary>
<p>

| *SGP43* | *SGP43 Pin* | *Cable Color* | *Board Pin* |
|:-------:|-------------|---------------|-------------|
|   VDD   | 1           | red           | 3V3         |
|   GND   | 2           | black         | GND         |
|   SDA   | 3           | green         | GPIO 21     |
|  VDDH   | 5           |               |             |
|   SCL   | 6           | yellow        | GPIO 22     |

<img src="images/esp32-devkitc-i2c-pinout-3.3V.png" width="600px" alt="ESP32 DevKitC pinout image">
</p>
</details>

## ML-based smell detection

For instructions on using the **SEK-SGP4x** evaluation board for machine learning-based smell detection, please read
application note **GAS_AN_SGP43** in combination with the [documentation of the dedicated example](./examples/exampleSGP43Classifier/README.md).

## Contributing

**Contributions are welcome!**

This Sensirion library uses
[`clang-format`](https://releases.llvm.org/download.html) to standardize the
formatting of all our `.cpp` and `.h` files. Make sure your contributions are
formatted accordingly:

The `-i` flag will apply the format changes to the files listed.

```bash
clang-format -i src/*.cpp src/*.h
```

Note that differences from this formatting will result in a failed build until
they are fixed.
:

## License

See [LICENSE](LICENSE).
