sparkfun / sparkfun_displacement_sensor_arduino_library Goto Github PK
View Code? Open in Web Editor NEWAn Arduino library to interface to the angular displacement sensor (flex) from Bend Labs.
License: Other
An Arduino library to interface to the angular displacement sensor (flex) from Bend Labs.
License: Other
Hello,does anyone know how to use the example calibrate? I use the example setI2CAddress to detect the sensor address, but when I use the calibrate example, it appears No sensor detected. Check wiring. Freezing...?
Does anyone know why?
Thanks!
Examples are missing call to .poll() function in setup() which is why these examples are failing to produce data.
One needs to add a call to .poll() function for each instance of ADS. Current examples are missing this. So this is the fix:
#include <Wire.h>
#include "SparkFun_Displacement_Sensor_Arduino_Library.h"
ADS myFlexSensor; //Create instance of the Angular Displacement Sensor (ADS) class
ADS myFlexSensor2; //Create instance of the Angular Displacement Sensor (ADS) class
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("SparkFun Displacement Sensor Example");
Wire.begin();
if (myFlexSensor.begin() == false) {
Serial.println(F("No sensor detected. Check wiring. Freezing..."));
while (1)
;
}
if (myFlexSensor2.begin(0x15) == false) {
Serial.println(F("No sensor detected. Check wiring. Freezing..."));
while (1)
;
}
myFlexSensor.poll(); // <--- add a call to .poll function in the library
myFlexSensor2.poll(); //<--- add a call to .poll function in the library
}
void loop() {
if (myFlexSensor.available() == true) {
Serial.print("#1: ");
Serial.print(myFlexSensor.getX());
Serial.println();
} else {
Serial.println("non available");
}
if (myFlexSensor2.available() == true) {
Serial.print("#2: ");
Serial.print(myFlexSensor2.getX());
Serial.println();
} else {
Serial.println("non available");
}
delay(10);
}
The examples should be clear and work 'out of the box.'
The examples fail to poll the sensor(s) as a call to .poll() is not included.
When verifying/compiling example sketches in Arduino IDE 1.8.9 the code does not compile with error message: invalid conversion from 'uint8_t {aka unsigned char}' to 'ADS_DEV_IDS_T'
Verifying any of the provided example sketches (i.e. Example1_1Axis_BasicReadings, Example2_TestDeviceType) with the Arduino IDE will result in compiler error messages. The issue appears to derive from the SparkFun_Displacement_Sensor_Arduino_Library.cpp file on line 57. Simply casting the result from readDeviceType() to type 'ADS_DEV_IDS_T' seemed to make the compiler happy and resolve the issue.
Working code, and a happy user.
Compiler errors and a sad user.
I worked with bendlabs' library for this sensors. This library gives me 2 kind of data from one-axis sensor: bending and stretching. But in your library I can't to give stretching data. Maybe I didn't find special function for that. Where can I find it?
Can you tell me, how I can get this data or maybe you can give me some docs about your code. Thank you!
PS: my English is so bad, SORRY! I'm working on it!
Thank you very much!
@nseidle
Hello,I have some questions.May I ask?
I have purchased the product with part number 100080101-01-EVAL, which is listed as part number 2190-100080101-01-EVAL-ND. I encountered an issue where I need to change the sensor address. For example, I want to change the original sensor address from 18 to 30. Initially, I was able to successfully update the address, but after connecting via Bluetooth and powering off, the previously set sensor address reverted back to the default value and I am unable to change the address anymore. What could be the cause of this issue? How should I proceed if I still need to change the address?
I have encountered the same issue with both the Bluetooth module on the Bluno Beetle v1.1 and the HC-06 Bluetooth module connected to the Arduino UNO board. After modifying the address, it reverts back to the default address and cannot be changed again. Does this sensor support address modification? Currently, I have two devices with the address set to 18, but I need to modify three different addresses: 18, 30, and 40. How should I proceed to handle this?
I'm using this code to change the address. However, when I try to modify it, it doesn't change successfully in one attempt. I need to repeatedly refresh and modify it to make the change successful.I used the Example6_SetI2CAddress code file provided to make the modification.
Another issue I encountered is that I can successfully change the address when I set it to 18, but any other address setting fails.
It is possible that the sensor's address modification is locked or restricted??
I want to read angle position of two 1-axis sensors, wired to the same I2C bus. Your example works great (after changing the default addresses of both sensors) for the initialization, but the data acquisition is not working correctly. Data from both sensors coming out the same value, although the sensors are not in the same "position".
I am using ESP32 dev kit v4 (at 3V3) and two 1-axis sensors.
The connections are the 4 wires from the board to the sensors (VCC, GND, SDA, SCK) leaving unplugged the interrupt pins of the sensors, as I am using poll method)
My code is:
#include <Wire.h>
#include "SparkFun_Displacement_Sensor_Arduino_Library.h"
ADS myFlexSensor1; //Create object of the ADS class
ADS myFlexSensor2; //Create object of the ADS class
void setup(){
Serial.begin(115200);
Serial.println("SparkFun Displacement Sensor Example");
Wire.begin(18, 19);
//Setup first sensor - look for it at the default address of 0x13 = 19
if (myFlexSensor1.begin(16) == false){
Serial.println(F("First sensor not detected. Check wiring. Freezing..."));
while (1);
}
//Setup second sensor - look for it at the I2C address of 45. You should have set this up in example 6
if (myFlexSensor2.begin(21) == false){
Serial.println(F("Second sensor not detected. Check wiring. Freezing..."));
while (1);
}
delay(100);
}
void loop(){
if (myFlexSensor1.available() == true && myFlexSensor2.available() == true){
Serial.print("1:");
Serial.print(myFlexSensor1.getX());
Serial.print("\t2:");
Serial.println(myFlexSensor2.getX());
}
else {
Serial.println("...");
}
delay(100);
}
I believe I should see the two different values of the getX() functions
The output on the serial terminal is:
Port closed
Uploading to I/O board
Opening port
Port open
SparkFun Displacement Sensor Example
1:-28.15 2:-72.05
1:-88.05 2:-85.31
1:-81.16 2:-80.18
1:-80.18 2:-80.97
1:-80.97 2:-80.97
1:-80.97 2:-80.97
1:-80.97 2:-80.97
1:-80.97 2:-80.97
1:-80.97 2:-80.97
1:-80.97 2:-80.97
1:-80.97 2:-80.97
1:-80.97 2:-80.97
1:-80.97 2:-80.97
1:-80.97 2:-80.97
1:-80.97 2:-80.97
1:-80.97 2:-80.97
1:-80.97 2:-80.97
1:-80.97 2:-80.97
1:-80.97 2:-80.97
1:-80.97 2:-80.97
1:-80.97 2:-80.97
1:-80.97 2:-80.97
1:-80.97 2:-80.97
1:-80.97 2:-80.97
1:-80.97 2:-80.97
1:-80.97 2:-80.97
1:-80.97 2:-80.97
1:-80.97 2:-80.97
1:-80.97 2:-80.97
1:-80.97 2:-80.97
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.
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)
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
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
Can either:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.