Skip to content

Issue with returned values when a second ADS instance is added #12

@davgibbs

Description

@davgibbs

Subject of the issue

Hello, thanks for supporting this open source library, it has been really useful for my project. I have a question/observation if anyone could try to reproduce it. It may be a bug or else just my mis-use of the library. There are workarounds, so not of a critical issue. The core of the issue is that "getX()" returns an incorrect value (doubled) when an unrelated begin() call is made in a separate instance.

Your workbench

  • What platform are you using? - Arduino IDE running on Ubuntu with an Arduino Nano 33 BLE
  • What version of the device are you using? Is there a firmware version? Not sure, firmware not updated since delivery of flex sensor
  • How is the device wired to your platform? via i2c
  • How is everything being powered? via the USB serial port on the Arduino and then from the 3.3V output pin on Arduino.
  • Are there any additional details that may help us help you? I think there may be an issue for this use case with the "begin()" call.

Steps to reproduce

I want to connect two flex sensors (one 1-axis and one 2-axis) on the same i2c bus. However, I can reproduce this issue using just one 1-axis flex sensor so for ease to reproduce I just had one flex sensor (1-axis) connected to my Arduino Nano. I took the code from the Example1_1Axis_BasicReadings.ino example and edited as below. Full gist with issue is here:

Add in a second instance of ADS in the file

ADS myFlexSensorTwoAxis;
if (myFlexSensorTwoAxis.begin(0x13) == false) {
    Serial.println(F("No sensor two detected. Check wiring. Freezing..."));
}

Replace:
if (myFlexSensor.begin() == false)
with (to be explicit with the 1-axis sensor at i2c 0x12).
if (myFlexSensor.begin(0x12) == false)

Expected behaviour

The "getX()" in the code below returns an similar value to the angle it is placed at. For example if I put the flex at 90 degrees, the value returned approx 90 degrees. The "myFlexSensorTwoAxis.begin()" for a unrelated sensor does not impact the rest of the code. For example:

15:11:20.274 -> -93.44
15:11:20.274 -> -93.44
15:11:20.274 -> -92.26
15:11:20.308 -> -89.80
15:11:20.308 -> -88.15

Actual behaviour

The flex values returned for ".getX()" are doubled. When I put the flex at 90 degrees, the value returned is 180 degrees. When I put the flex at 180 degrees, the value returned is 360 degrees. The "myFlexSensorTwoAxis.begin()" seems to impact the rest of the code by doubling the values. I'm not sure why this happens.

15:12:22.455 -> -177.72
15:12:22.488 -> -176.69
15:12:22.488 -> -177.53
15:12:22.488 -> -187.03
15:12:22.521 -> -187.66

Workaround:

Can either:

  1. Switch the order of defining the begin() function. So ensure that the one-axis instance (myFlexSensor) runs the begin() first.
  2. Remove the "0x13" when running begin() on the myFlexSensorTwoAxis instance. But this is less explicit than including the "0x13". Note that the same issue occurs if 19 decimal is used for hex 0x13 and 18 decimal in place of 0x12.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions