0

DESPERATE, ready to give up!
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

DESPERATE, ready to give up!

by prostreet on Sat Aug 17, 2019 12:43 pm

I have been attempting to build a self leveling platform. For way too long
SOOO disguised.
It only needs to turn on 1 axis, ( X )
I am using an Arduino UNO board
I have a ADXL345 by Adafruit
I am using a DSSERVO DS 3218 PRO
Enclosed is the code directly from the Adafruit website
https://learn.adafruit.com/adxl345-digi ... rogramming
I run the program while hooked up to the USB port on the PC & it works.
I would really like to increase the sensitivity ( I believe )
Sometime while rotating, the servo reacts, but sometime very slowly
Could anyone PLEASE try to assist me. If any advice is given, I need detailed advice being am at the end
ANY and ALL help would be forever grateful
Thank you
Jerome
Code: Select all | TOGGLE FULL SIZE
/*
 * Accelerator demo
 *
 */
#include <Servo.h>
#include <Adafruit_ADXL345_U.h>

// Create servo objects for x and y servos
Servo xServo;
Servo yServo;

// Used to level the platform, if needed
int xOffset = -7;
int yOffset = -1;

// Used to decrease sensitivity
int sensitivity = 50;

// Assign a unique ID to this sensor at the same time
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);


void setup() {
      Serial.begin(9600);
 
// Initialize sensor
      if(!accel.begin())
      {
// Sensor not detected
            Serial.println("No Sensor detected");
      while(1);

      }

// Connect servos to pins
      xServo.attach(9);
      yServo.attach(10);

// Setup sensor Range and datarate
      accel.setRange(ADXL345_RANGE_16_G);
      accel.setDataRate(ADXL345_DATARATE_25_HZ);

}

void loop() {
 
      sensors_event_t event;
      accel.getEvent(&event);

// Get x and y values from sensor
      int x = event.acceleration.x;
      int y = event.acceleration.y;

// map sensor value (-10 - 10) to servo position value (30 - 150)
      int x1 = map(x, -10, 10, 130, 50);
      int y1 = map(y, -10, 10, 50, 130);

// Troubleshoot info - show sensor reading and mapping
      Serial.print("X: "); Serial.print(x);
      Serial.print("\tY: "); Serial.print(y);
      Serial.print("\tX1: "); Serial.print(x1);
      Serial.print("\tY1: "); Serial.println(y1);

// move servos based on sensor mapping
      xServo.write(x1 + xOffset);
      yServo.write(y1 + yOffset);
      delay(sensitivity);         //delay to decrease sensitivity
}
Last edited by franklin97355 on Sat Aug 17, 2019 1:38 pm, edited 1 time in total.
Reason: Added code tags and merged two posts.

prostreet
 
Posts: 4
Joined: Sat Aug 17, 2019 12:36 pm

Re: DESPERATE, ready to give up!

by adafruit_support_bill on Sat Aug 17, 2019 1:46 pm

Enclosed is the code directly from the Adafruit website

You must have linked the wrong tutorial. Your code is quite a bit different than the code there. That tutorial does not deal with servo control.

Please post a link to the tutorial you are following.

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Re: DESPERATE, ready to give up!

by prostreet on Sat Aug 17, 2019 10:18 pm

Sorry for incorrect info.
It was from haxter.com
Sorry

https://www.hackster.io/mtashiro/level- ... ter-80a343

prostreet
 
Posts: 4
Joined: Sat Aug 17, 2019 12:36 pm

Re: DESPERATE, ready to give up!

by adafruit_support_bill on Sun Aug 18, 2019 9:15 am

I would really like to increase the sensitivity ( I believe )
Sometime while rotating, the servo reacts, but sometime very slowly

For quicker response, you can use a smaller number here.
// Used to decrease sensitivity
int sensitivity = 50;

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Re: DESPERATE, ready to give up!

by prostreet on Sun Aug 18, 2019 1:22 pm

Thank you
I will attempt it with a smaller number.
Like how smaller from 50 would you deviate, would you use
a 49 or 5?
Thank you.

prostreet
 
Posts: 4
Joined: Sat Aug 17, 2019 12:36 pm

Re: DESPERATE, ready to give up!

by adafruit_support_bill on Sun Aug 18, 2019 1:34 pm

Keep reducing it until you get the response speed you are looking for. You can reduce it all the way to zero. It won't hurt anything. At worst it will make it a bit twitchy.

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Re: DESPERATE, ready to give up!

by prostreet on Sun Aug 18, 2019 1:54 pm

Thanks
Greatly Appreciated.
Jerome

prostreet
 
Posts: 4
Joined: Sat Aug 17, 2019 12:36 pm

Please be positive and constructive with your questions and comments.