Comments (6)
I got your code working, including reading prescale value 105=>106*4096 (instead of 255) with the following three changes:
- Add
ESC::
to all wrapper functions in cpp:
uint8_t ESC::readPrescale(void)
{
return myESC.readPrescale();
}
-
Only have default values for parameters in the definitions (.h) and not implementation (.cpp):
void setPin(uint8_t num, uint16_t val, bool invert = false);
void ESC::setPin(uint8_t num, uint16_t val, bool invert)
-
Move the initiation of the myESC object to the initalisation of the ESC class:
Adafruit_PWMServoDriver myESC = Adafruit_PWMServoDriver(oBoard);
->
Adafruit_PWMServoDriver myESC;
to the class initalisation:
oBoard = I2C_Address; // The I2C address on the TwoWire interface
myESC = Adafruit_PWMServoDriver(oBoard);
And after these changes the code compiled and reported:
I2C Controller Test with ESC
255 Current Prescale value
read Current Prescale value cleared
105 Current Prescale value
which is ok, because the first read was before myESC.begin();
ps: myESC.begin(>0) sets the external oscillator, which standard is not available.
from adafruit-pwm-servo-driver-library.
I went through your code, but could not find the obvious fault. Please add 'return's in your wrapper
return myESC.getPWM(num);
return myESC.readPrescale();
and use myESC.readPrescale right after myESC.setPWMFreq(60)
and myESC.speed(1064);
and what do you get?
from adafruit-pwm-servo-driver-library.
@Bolukan I made the requested changes (oops forgot those returns
the first time ::facepalm:: )
I get a prescale of 255
I tried setting the frequency via serial parsing from the serial monitor, I still get a prescale of 255 every time
Expected frequency:: 60
Actual prescale:: 255
Expected frequency:: 55
Actual prescale:: 255
Expected frequency:: 2
Actual prescale:: 255
Expected frequency:: 1000
Actual prescale:: 255
from adafruit-pwm-servo-driver-library.
@Bolukan I also tried setting the prescale in the begin()
, in the sketch with myESC.begin(105);
still got 255 for the prescale.
My best guess is something is happening when the private library object is created in header and that something is what's locking the prescale/frequency valuse to 255.
from adafruit-pwm-servo-driver-library.
Wholely smokes, I didn't even think to separate the library object Adafruit_PWMServoDriver myESC;
in the header from the object initialization and put that in the CPP myESC = Adafruit_PWMServoDriver(oBoard);
I had previously tried moving the whole thing, but not separated. Absolutely brilliant.
It's working as expected with that one minor change (the other changes I had already done, but I guess I had uploaded an old version of the library from earlier attempt).
I can now change the frequency on the fly and it's working as expected. Thank you.
(probably should include this solution in some kind of guide)
from adafruit-pwm-servo-driver-library.
I've updated the Forum discussion with the solution from here. Between this and the Forum (and following correct OOP design) anyone else who tries to wrap this library should be able to figure out what to do.
Closing as solution provided
from adafruit-pwm-servo-driver-library.
Related Issues (20)
- Weird bug: need to explicitly pass in pointer to Wire HOT 7
- Argument to begin should not set external clock HOT 2
- Method for setting push pull/open drain mode HOT 3
- getPWM returns random numbers HOT 19
- passing I2C address when creating Adafruit_PWMServoDriver resets Arduino HOT 8
- Regarding sleep-mode HOT 2
- ¿se puede evitar que salga esto en la verificación o subida de un codigo de arduino? => ATENCIÓN: .github Espúrias carpetas en librería 'Adafruit PWM Servo Driver Library' HOT 1
- Change constructor arguments HOT 5
- controlling servo speed
- Wire Arduino with Adafruit pwm servo driver HOT 1
- _oscillator_freq not initialized? HOT 1
- Program may freeze if hardware fails. HOT 2
- writeMicroseconds(uint8_t num, uint16_t Microseconds) sends wrong number of PCA9685 ticks HOT 1
- Doesn't build HOT 4
- Servo timing is wrong in example for regular servo's like sg90.
- Convert to BusIO HOT 1
- Issue with constructor when a custom i2c bus is used.
- Adafruit_PWMServoDriver::setPWM returns 0 not endTransmission response HOT 4
- setPWM description is incomplete/misleading
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from adafruit-pwm-servo-driver-library.