# \[gelöst\] Wire.begin beeinflusst oneWire

**URL:** <https://forum.arduino.cc/t/gelost-wire-begin-beeinflusst-onewire/942227>\
**Category:** Deutsch\
**Created:** [January 2, 2022, 4:55pm UTC](https://forum.arduino.cc/t/gelost-wire-begin-beeinflusst-onewire/942227 "2022-01-02T16:55:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![luzie](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/luzie/32/1147479_2.png) [@luzie](https://forum.arduino.cc/u/luzie)\
**Post date:** [January 2, 2022, 4:55pm UTC](https://forum.arduino.cc/t/gelost-wire-begin-beeinflusst-onewire/942227/1 "2022-01-02T16:55:54Z")

</div>

Hallo,

ich sitze hier vor einem kleinem Problem mit OneWire und dem Wire.begin

lasse ich den Wire.begin Befehl weg funktioniert der OneWire und erkennt auch den Sensor.

```cpp
#include <OneWire.h>
#include <Wire.h>
OneWire ds(2); // on pin 2 (a 4.7K resistor is necessary)

void setup() {
// Wire.begin(); // enable I2C port.
  Serial.begin(9600); // Start serial comunication at baud=115200
  Serial1.begin(115200); // Start serial comunication at baud=115200
}

void loop() {
  byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius;
  
  if ( !ds.search(addr)) {
    Serial.println("No more addresses.");
    Serial.println();
    ds.reset_search();
    delay(250);
    return;
  }

  /*
    Serial.print("ROM =");
    for( i = 0; i < 8; i++) {
      Serial.write(' ');
      Serial.print(addr[i], HEX);
    }
  */

  if (OneWire::crc8(addr, 7) != addr[7]) {
    Serial.println("CRC is not valid!");
    return;
  }
  Serial.println();

  // the first ROM byte indicates which chip
  switch (addr[0]) {
    case 0x10:
      type_s = 1;
      break;
    case 0x28:
      type_s = 0;
      break;
    case 0x22:
      type_s = 0;
      break;
    default:
      return;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44, 1); // start conversion, with parasite power on at the end

  delay(1000); // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.

  present = ds.reset();
  ds.select(addr);
  ds.write(0xBE); // Read Scratchpad
  for ( i = 0; i < 9; i++) { // we need 9 bytes
    data[i] = ds.read();
  }

  // Convert the data to actual temperature
  // because the result is a 16 bit signed integer, it should
  // be stored to an "int16_t" type, which is always 16 bits
  // even when compiled on a 32 bit processor.
  int16_t raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // "count remain" gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    // at lower res, the low bits are undefined, so let's zero them
    if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
    //// default is 12 bit resolution, 750 ms conversion time
  }
  celsius = (float)raw / 16.0;
  Serial.print("Temperature = ");
  Serial.print(celsius);
  Serial.println();
}

```

sobald ich aber Wire.begin einbinde Funktioniert OneWire nicht mehr, es werden keine Sensoren erkannt.  
was muss ich anstellen um das Problem zu lösen?

---

<div class="post-metadata">

**Author:** ![my\_xy\_projekt](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/my_xy_projekt/32/810062_2.png) [@my\_xy\_projekt](https://forum.arduino.cc/u/my_xy_projekt)\
**Post date:** [January 2, 2022, 5:23pm UTC](https://forum.arduino.cc/t/gelost-wire-begin-beeinflusst-onewire/942227/2 "2022-01-02T17:23:17Z")

</div>

> [@luzie](#):
>
> sobald ich aber Wire.begin einbinde Funktioniert OneWire nicht mehr, es werden keine Sensoren erkannt.

Auf was für nem Board?

---

<div class="post-metadata">

**Author:** ![luzie](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/luzie/32/1147479_2.png) [@luzie](https://forum.arduino.cc/u/luzie)\
**Post date:** [January 2, 2022, 5:27pm UTC](https://forum.arduino.cc/t/gelost-wire-begin-beeinflusst-onewire/942227/3 "2022-01-02T17:27:07Z")

</div>

Auf einem Arduino Leonardo 32U4 Chip

---

<div class="post-metadata">

**Author:** ![my\_xy\_projekt](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/my_xy_projekt/32/810062_2.png) [@my\_xy\_projekt](https://forum.arduino.cc/u/my_xy_projekt)\
**Post date:** [January 2, 2022, 5:35pm UTC](https://forum.arduino.cc/t/gelost-wire-begin-beeinflusst-onewire/942227/4 "2022-01-02T17:35:26Z")

</div>

> [@luzie](#):
>
> Leonardo

Schade, bin ich raus ;( Nano (168/328), Uno, Mega geht. Sorry...

---

<div class="post-metadata">

**Author:** ![luzie](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/luzie/32/1147479_2.png) [@luzie](https://forum.arduino.cc/u/luzie)\
**Post date:** [January 2, 2022, 5:47pm UTC](https://forum.arduino.cc/t/gelost-wire-begin-beeinflusst-onewire/942227/5 "2022-01-02T17:47:26Z")

</div>

OK ich habe es gefunden.  
Am Leonardo kann der I2C Bus auch an Pin2 und 3 genutzt werden. Da ich den oneWire auch auf Pim 2 hatte ging das aber nicht. Nun habe ich diesen auf Pin10 gelegt und es geht auch sofort.

---

<div class="post-metadata">

**Author:** ![my\_xy\_projekt](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/my_xy_projekt/32/810062_2.png) [@my\_xy\_projekt](https://forum.arduino.cc/u/my_xy_projekt)\
**Post date:** [January 2, 2022, 5:48pm UTC](https://forum.arduino.cc/t/gelost-wire-begin-beeinflusst-onewire/942227/6 "2022-01-02T17:48:06Z")

</div>

> [@luzie](#):
>
> OK ich habe es gefunden.

Kannst Dir nen Lösungsklick geben 🙂

---

<div class="post-metadata">

**Author:** ![uwefed](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/uwefed/32/213736_2.png) [@uwefed](https://forum.arduino.cc/u/uwefed)\
**Post date:** [January 3, 2022, 9:52am UTC](https://forum.arduino.cc/t/gelost-wire-begin-beeinflusst-onewire/942227/7 "2022-01-03T09:52:31Z")

</div>

I2C bzw SDA und SCL auf einem Arduino Board ist immer eine doppelte Herausführung von anderen Pins die als Digitale herausgeführt sind. Praktisch 2 Pins für den gleichen Anschluß mit verschiedener Beschriftung. Gleiches gilt fur SPI auf den 6Poligen ICSP-Stecker. Welches die Digitalen Pins nun sind, die diese Zweitfunktion haben (I2C oder SPI) ist entweder dem Datenblatt des Controllers oder der Beschreibung der I2C bzw SPI Schnittstelle auf der Arduino Referenz zu entnehmen.  
zB: für I2C: [Wire - Arduino Reference](https://www.arduino.cc/en/Reference/Wire) oder [SPI - Arduino Reference](https://www.arduino.cc/en/Reference/SPI)

Grüße Uwe

---

<div class="post-metadata">

**Author:** ![luzie](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/luzie/32/1147479_2.png) [@luzie](https://forum.arduino.cc/u/luzie)\
**Post date:** [January 3, 2022, 4:30pm UTC](https://forum.arduino.cc/t/gelost-wire-begin-beeinflusst-onewire/942227/8 "2022-01-03T16:30:31Z")

</div>

Danke @uwefed. Das ist mir dann auch eingefallen, aber im Eifer des Gefechts völlig vergessen gehabt.  
Hatte nur den Test meines selber entwickeltem Boards vor Augen und das wesentliche Ausgeblendet.  
Aber nun Funktioniert ja alles wie es geplant war.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [July 2, 2022, 4:31pm UTC](https://forum.arduino.cc/t/gelost-wire-begin-beeinflusst-onewire/942227/9 "2022-07-02T16:31:30Z")

</div>

Closed on July 2, 2022, 4:31pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
