# STM32duino & I2C

Подсоедините датчик к отладочной плате по следующей схеме:

```
VCC             5V
GND             GND
SCL             PB6
SDA             PB7
```

![Схема подключения кота к сети](/files/LbT9QTnH9JiRBOMfijE2)

Теперь откроем тестовый скетч:

* Нажмите «Файл», затем «Примеры > Adafruit BMP280 Library > bmp280test».

Чтобы выбрать интерфейс I2C и настроить использование правильных ножек микроконтроллера, найдите следующие строки:&#x20;

```arduino
//if (!bmp.begin(BMP280_ADDRESS_ALT, BMP280_CHIPID)) {
if (!bmp.begin()) {
  Serial.println(F("Could not find a valid BMP280 sensor, check wiring or "
                    "try a different address!"));
  while (1) delay(10);
}
```

и вызовите перед ними следующие функции библиотеки Wire:

```arduino
  Wire.setSDA(PB7); // связываем сигналы с правильными ножками
  Wire.setSCL(PB6);
  Wire.begin();

  //if (!bmp.begin(BMP280_ADDRESS_ALT, BMP280_CHIPID)) {
  if (!bmp.begin()) {
    Serial.println(F("Could not find a valid BMP280 sensor, check wiring or "
                      "try a different address!"));
    while (1) delay(10);
  }
```

{% hint style="info" %}
Ножки PB7 и PB6 связаны с сигналами SDA и SCL периферийного блока I2C1.
{% endhint %}

В зависимости от реализации конкретного модуля BMP280, вам, возможно, придется работать с ним по альтернативному адресу. Для этого переделайте

```arduino
  //if (!bmp.begin(BMP280_ADDRESS_ALT, BMP280_CHIPID)) {
  if (!bmp.begin()) {
```

в&#x20;

```arduino
  if (!bmp.begin(BMP280_ADDRESS_ALT, BMP280_CHIPID)) {
  //if (!bmp.begin()) {
```

Мы готовы загружать скетч! Нажмите кнопку «загрузить», дождитесь окончания компиляции и загрузки, откройте Монитор порта. В нем вы должны увидеть примерно следующее:

```
Temperature = 24.08 *C
Pressure = 99341.86 Pa
Approx altitude = 166.43 m
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://voltbro.gitbook.io/vbcores/ustarevshee-oborudovanie/programming/stm32duino-programming-hints/stm32duino-and-i2c.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
