GithubHelp home page GithubHelp logo

Comments (6)

Bolukan avatar Bolukan commented on May 9, 2024 4

I got your code working, including reading prescale value 105=>106*4096 (instead of 255) with the following three changes:

  1. Add ESC:: to all wrapper functions in cpp:
uint8_t ESC::readPrescale(void)
{
	return myESC.readPrescale();
}
  1. 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)

  2. 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.

Bolukan avatar Bolukan commented on May 9, 2024 1

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.

photodude avatar photodude commented on May 9, 2024

@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

I2C_control_Test.zip

from adafruit-pwm-servo-driver-library.

photodude avatar photodude commented on May 9, 2024

@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.

photodude avatar photodude commented on May 9, 2024

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.

photodude avatar photodude commented on May 9, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.