Good morning, I hope they are succeeding in their projects.
I am currently working with an arm 9DOF controlled by three accelerometers and newly acquired my adafruit 16-channel PWM / servo driver.The problem is I dont know how to adapt to the code to append my adafruit.
How to send the signal in degrees? and as stated servos?
9DOF arm controlled by three MPU, and adafruit servo drive
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- KafkaRaro
- Posts: 9
- Joined: Wed Apr 15, 2015 11:39 pm
9DOF arm controlled by three MPU, and adafruit servo drive
Last edited by KafkaRaro on Tue Apr 21, 2015 10:37 am, edited 1 time in total.
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: 9DOF arm controlled by three MPU, and adafruit servo dri
Once you calibrate your servos, you can use the map function to convert your degrees into a pulse length for the PWM driver:
https://learn.adafruit.com/16-channel-p ... our-servos
https://learn.adafruit.com/16-channel-p ... our-servos
Code: Select all
pulse = map(degrees, 0, 180, SERVOMIN, SERVOMAX);
pwm.setPWM(n, 0, pulse );
- KafkaRaro
- Posts: 9
- Joined: Wed Apr 15, 2015 11:39 pm
Re: 9DOF arm controlled by three MPU, and adafruit servo dri
ok perfect, I will start working on it, just one more question, as stated 6 servos individually using the library adafruit?
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: 9DOF arm controlled by three MPU, and adafruit servo dri
The example code for the library shows how to initialize the driver and move a servo.
https://github.com/adafruit/Adafruit-PW ... /servo.pde
The first parameter to setPWM is the servo number, so you can address your servos as 0-5.
https://github.com/adafruit/Adafruit-PW ... /servo.pde
The first parameter to setPWM is the servo number, so you can address your servos as 0-5.
Code: Select all
pwm.setPWM(0, 0, pulse ); // this moves servo #0
pwm.setPWM(1, 0, pulse ); // this moves servo #1
pwm.setPWM(2, 0, pulse ); // this moves servo #2
pwm.setPWM(3, 0, pulse ); // this moves servo #3
pwm.setPWM(4, 0, pulse ); // this moves servo #4
pwm.setPWM(5, 0, pulse ); // this moves servo #5
- KafkaRaro
- Posts: 9
- Joined: Wed Apr 15, 2015 11:39 pm
Re: 9DOF arm controlled by three MPU, and adafruit servo dri
Hello, good afternoon, perform modifications to my code, for adding my adafruit, in doing so emerged new doubts me.
In this part I do not know how to write the value of the corresponding angle, leave the anterior part of code to explain better
Beforehand thank you for the help you have given me
In this part I do not know how to write the value of the corresponding angle, leave the anterior part of code to explain better
Code: Select all
Angle[0] = 0.98 *(Angle[0]+Gy[0]*0.010) + 0.02*Acc[0];
Angle[1] = 0.98 *(Angle[1]+Gy[1]*0.010) + 0.02*Acc[1];
//servo1.write(Angle[0]+90);
//servo2.write(Angle[1]+90);
pwm.setPWM(0, 0, map(180, 0, 180, SERVOMIN, SERVOMAX));
pwm.setPWM(1, 0, map(180, 0, 180, SERVOMIN, SERVOMAX));
Last edited by KafkaRaro on Tue Apr 21, 2015 10:41 am, edited 2 times in total.
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: 9DOF arm controlled by three MPU, and adafruit servo dri
This will always resiult in the same angle because you are always passing 180 as the input to the map function:
[/code][/code]
You need to pass the angle in degrees as in the example above.
http://www.arduino.cc/en/reference/map
Code: Select all
pwm.setPWM(0, 0, map(180, 0, 180, SERVOMIN, SERVOMAX));[code][code]
You need to pass the angle in degrees as in the example above.
http://www.arduino.cc/en/reference/map
- KafkaRaro
- Posts: 9
- Joined: Wed Apr 15, 2015 11:39 pm
Re: 9DOF arm controlled by three MPU, and adafruit servo dri
Thanks, achieves write the angle, in the line of code mentioned.
But the adafruit does not respond well when connected, 2 or more I2C devices,
accelerometers in my case, not if it is because rewrote this part of the code
and leave only this
This somehow affects the response of adafruit? or is a general problem and not respond well when working together with other I2C devices?
But the adafruit does not respond well when connected, 2 or more I2C devices,
accelerometers in my case, not if it is because rewrote this part of the code
Code: Select all
void setServoPulse(uint8_t n, double pulse) {
double pulselength;
pulselength = 1000000; // 1,000,000 us per second
pulselength /= 60; // 60 Hz
Serial.print(pulselength); Serial.println(" us per period");
pulselength /= 4096; // 12 bits of resolution
Serial.print(pulselength); Serial.println(" us per bit");
pulse *= 1000;
pulse /= pulselength;
Serial.println(pulse);
pulse = map(degrees, 0, 180, SERVOMIN, SERVOMAX);
pwm.setPWM(n, 0, pulse);
}
Code: Select all
void setServoPulse(uint8_t n, double pulse) {
double pulselength;
pulselength = map(degrees, 0, 180, SERVOMIN, SERVOMAX);
pwm.setPWM(n, 0, pulselength);
}
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: 9DOF arm controlled by three MPU, and adafruit servo dri
I don't see anything in your code related to another i2c device. What device are you using?
As long as the devices have different i2c addresses they should be compatible on the bus.
As long as the devices have different i2c addresses they should be compatible on the bus.
- KafkaRaro
- Posts: 9
- Joined: Wed Apr 15, 2015 11:39 pm
Re: 9DOF arm controlled by three MPU, and adafruit servo dri
I don't see anything in your code related to another i2c device
Code: Select all
//address I2C of the IMU
#define MPU 0x68
#define MPU2 0x69
I run the I2C code scanner, connecting only the adafruit to the arduino, and this is what shows two I2C addresses, is this normal?
this is what says thehttps://learn.adafruit.com/downloads/pd ... driver.pdf
i do not know if you can see the picture, but that is what shows upThe I2C base address for each board is
0x40.
Scanning...
I2C device found at address 0x40 !
I2C device found at address 0x70 !
done
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: 9DOF arm controlled by three MPU, and adafruit servo dri
Those are the addresses of the PWM servo controller. 0x40 is the base address and 0x70 is the "all-call" address. Neither should conflict with your IMU addresses.Scanning...
I2C device found at address 0x40 !
I2C device found at address 0x70 !
done
Please be positive and constructive with your questions and comments.