0

I took a simple A2320 temperature sensor and connected it not to A4/A5, but to A1/A0 pins. SDA => A1, SCL => A0. (In C code they are number 15 and 14). But I can't call the library to take these pins.

The basic example from the library uses the default values, probably from some tutorial.

I read the .h and .cpp files and see these definitions:

Adafruit_AM2320::Adafruit_AM2320(TwoWire *theI2C, int32_t tempSensorId,
                                 int32_t humiditySensorId)
    : _temp(this, tempSensorId), _humidity(this, humiditySensorId),
      _i2c(theI2C) {}

bool Adafruit_AM2320::begin() { _i2caddr = 0x5C; // fixed addr _i2c->begin(); return true; }

I just tried to make types match. Not even port number.

I declared a TwoWire instance and passed it to AM2320 constructor, but without success:

#include "Wire.h"
...
TwoWire mywire();
Adafruit_AM2320 am2320 = Adafruit_AM2320(mywire, -1, -1); // as the default values

Outputs in error log:

error: no matching function for call to 'Adafruit_AM2320::Adafruit_AM2320(TwoWire (*)(), int, int)'
    Adafruit_AM2320 am2320 = Adafruit_AM2320(&mywire, -1, -1);
In file included from testproj.ino:2:0:
...Adafruit_AM2320.h:52:3: note: candidate: Adafruit_AM2320::Adafruit_AM2320(TwoWire*, int32_t, int32_t)
   Adafruit_AM2320(TwoWire *theI2C = &Wire, int32_t tempSensorId = -1,
   ^~~~~~~~~~~~~~~
...Adafruit_AM2320.h:52:3: note:   no known conversion for argument 1 from 'TwoWire (*)()' to 'TwoWire*'

What am I doing wrong?

1 Answers1

1

Two problems:

  1. When you create an object instance with no parameters you must not have parentheses. You should construct thus:
TwoWire mywire;
  1. The constructor expects a pointer to an object, not an object. Just take the address of the object with & and pass that:
Adafruit_AM2320 am2320 = Adafruit_AM2320(&mywire, -1, -1); // as the default values

However

Most Arduino boards have the I2C pins hard-wired internal to the chip and can't be changed. You would need to use some form of software implementation that is also a polymorphic child of the TwoWire class. If such a thing exists.

Majenko
  • 105,851
  • 5
  • 82
  • 139