I run this code but the servo does not work. there is no error and the code uploads successfully but the servo does not work. can any one help me?
yes
#include <HCPCA9685.h>
#include "HCPCA9685.h"
/* I2C slave address for the device/module. For the HCMODU0097 the default I2C address
is 0x40 */
#define I2CAdd 0x40
/* Create an instance of the library */
HCPCA9685 HCPCA9685(I2CAdd);
void setup()
{
/* Initialise the library and set it to 'servo mode' */
HCPCA9685.Init(SERVO_MODE);
/* Wake the device up */
HCPCA9685.Sleep(false);
unsigned int Pos;
#
for(Pos = 0; Pos< 150; Pos++)
{
HCPCA9685.Servo(0, Pos);
delay(10);
}
//HCPCA9685.Servo(0, 150);
}
void loop()
{
/* Sweep the servo back and forth from its minimum to maximum position. If your servo is hitting its end stops then you should adjust the values so that the servo can sweep though its full range without hitting the end stops. You can adjust the min & max positions by altering the trim values in the libraries HCPCA9685.h file*/
}
tank you. this is my code
you copy it from internet, delete some lines and now it not work, but why?
follow this tutorial:
https://forum.hobbycomponents.com/viewtopic.php?t=2034
A month ago, this code was working, but now it is not working
you just switch your device on and it not work now or you uploaded sketch again and now device not work ?
I must say that a month ago I deleted Arduino and now I have reinstalled it
i uploaded sketch again and now device not work
so, obvious you add some error to the sketch. where you get it?
this sketch have no errors too.
savvy?
But my code was working a month ago. I did not change it at all
any proves? let us check. where you got this sketch one month ago?
From the example in the hcpca9685 library
i don't have such lib, could you post that example?
/* FILE: HCPCA9685_Servo_Example
DATE: 10/06/16
VERSION: 0.1
AUTHOR: Andrew Davies
Sketch created by Hobby Components Ltd (HOBBYCOMPONENTS.COM)
10/06/16 version 0.1: Original version
This example demonstrates how to use the HCPCA9685 library together with the PCA9685
to control up to 16 servos. The sketch will initialise the library putting it into
'servo mode' and then will continuously sweep one servo connected to PWM output 0
back and forth. The example has been written particularly for the 16 Channel 12-bit
PWM Servo Motor Driver Module (HCMODU0097) available from hobbycomponents.com
To use the module connect it to your Arduino as follows:
PCA9685...........Uno/Nano
GND...............GND
OE................N/A
SCL...............A5
SDA...............A4
VCC...............5V
External 5V Power for the servo(s) can be supplied by the V+ and GND input of the
screw terminal block.
PLEASE NOTE: Depending on your servo it is possible for this sketch to attempt
drive the servo beyond its end stops. If your servo is hitting its end stops then
you should adjust the the min and max values in this sketch.
You may copy, alter and reuse this code in any way you like, but please leave
reference to HobbyComponents.com in your comments if you redistribute this code.
This software may not be used directly for the purpose of selling products that
directly compete with Hobby Components Ltd's own range of products.
THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER
EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES,
INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
REASON WHATSOEVER.
*/
/* Include the HCPCA9685 library */
#include "HCPCA9685.h"
/* I2C slave address for the device/module. For the HCMODU0097 the default I2C address
is 0x40 */
#define I2CAdd 0x40
/* Create an instance of the library */
HCPCA9685 HCPCA9685(I2CAdd);
void setup()
{
/* Initialise the library and set it to 'servo mode' */
HCPCA9685.Init(SERVO_MODE);
/* Wake the device up */
HCPCA9685.Sleep(false);
}
void loop()
{
unsigned int Pos;
/* Sweep the servo back and forth from its minimum to maximum position.
If your servo is hitting its end stops then you should adjust the
values so that the servo can sweep though its full range without hitting
the end stops. You can adjust the min & max positions by altering
the trim values in the libraries HCPCA9685.h file*/
for(Pos = 10; Pos < 450; Pos++)
{
/* This function sets the servos position. It takes two parameters,
* the first is the servo to control, and the second is the servo
* position. */
HCPCA9685.Servo(0, Pos);
delay(10);
}
for(Pos = 450; Pos >= 10; Pos--)
{
HCPCA9685.Servo(0, Pos);
delay(10);
}
}
this is the example in hcpca9685 library. i upload this example too but it doesn't work too
then i have bad news for you
or not so bad if you broke only wiring
I use the Adafruit PWM servo driver available in the Arduino library repository.
This code works for me. Connect servo to servo 0.
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
#define SERVOMIN 150 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX 600 // this is the 'maximum' pulse length count (out of 4096)
uint8_t servonum = 0;
void setup() {
Serial.begin(38400);
Serial.println("16 channel Servo test!");
pwm.begin();
pwm.setPWMFreq(60); // Analog servos run at ~60 Hz updates
yield();
}
void loop() {
for (uint16_t pulselen = SERVOMIN; pulselen < SERVOMAX; pulselen++) {
pwm.setPWM(servonum, 0, pulselen);
}
delay(500);
for (uint16_t pulselen = SERVOMAX; pulselen > SERVOMIN; pulselen--) {
pwm.setPWM(servonum, 0, pulselen);
}
delay(500);
}