The 1st code is from the example program "Servo"
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
pwm.begin();
pwm.setPWM(servonum, 0, pulselen);
This 2nd code is from a sketch that I have been tasked with making work. It is supposed to drive 2 servo motors based upon a satellites position in the sky. This bit is a small portion of a sub-program of an enormous sketch. The sub-probram exceeds the 9000 character limit here.
The 1st difference that I noticed was between these 2 lines plus others that were similar construct.
pwm.begin();
pwm->begin();
the m.begin vs m->begin
I dont know if that has any impact.
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver *pwm;
pwm->setPWM(mip->servo_num, 0, mip→pos/US_PER_BIT);
pwm = new Adafruit_PWMServoDriver(GIMBAL_I2C_ADDR);
pwm->begin();
pwm->setPWMFreq(SERVO_FREQ);
Neither of them compile for me.
GypsumFantastic:
Neither of them compile for me.
Thanks Gypsum, and they wouldn't as you don't have the complete sketch. The 1st is a sample titled "Servo" and it should compile ok.
hextejas:
Thanks Gypsum, and they wouldn't as you don't have the complete sketch.
Then you need to post the complete programs.
...R
The '.' is used for object instances. The '->' is used for object pointers. Perhaps the pointer is not pointing to a valid instance. That would cause the second exmple to not work.
johnwasser:
The '.' is used for object instances. The '->' is used for object pointers. Perhaps the pointer is not pointing to a valid instance. That would cause the second exmple to not work.
Expanding on that thought, if this is what your code really looks like:
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver *pwm;
pwm->setPWM(mip->servo_num, 0, mip→pos/US_PER_BIT);
pwm = new Adafruit_PWMServoDriver(GIMBAL_I2C_ADDR);
Then you're calling a method using the pointer pwm BEFORE you actually instantiate an object and have pwm point to it. That MIGHT work if setPWM is a static method. But, it smells bad.
EDIT:
It's simple enough to look in Adafruit_PWMServoDriver.h and see that setPWM is not static:
void setPWM(uint8_t num, uint16_t on, uint16_t off);
If the actual code is really huge, then it's time to learn how to make a post an MRE.
Re posting the full sketches:
Robin2:
Then you need to post the complete programs.
...R
For the example sketches as well ? I thought that they were available for everyone with the Arduino IDE installed.
In any respect here it is: Its named "Servo".
/***************************************************
This is an example for our Adafruit 16-channel PWM & Servo driver
Servo test - this will drive 8 servos, one after the other on the
first 8 pins of the PCA9685
Pick one up today in the adafruit shop!
------> http://www.adafruit.com/products/815
These drivers use I2C to communicate, 2 pins are required to
interface.
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
****************************************************/
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);
// you can also call it with a different address and I2C interface
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40, Wire);
// Depending on your servo make, the pulse width min and max may vary, you
// want these to be as small/large as possible without hitting the hard stop
// for max range. You'll have to tweak them as necessary to match the servos you
// have!
#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)
#define USMIN 600 // This is the rounded 'minimum' microsecond length based on the minimum pulse of 150
#define USMAX 2400 // This is the rounded 'maximum' microsecond length based on the maximum pulse of 600
#define SERVO_FREQ 50 // Analog servos run at ~50 Hz updates
// our servo # counter
uint8_t servonum = 0;
void setup() {
Serial.begin(9600);
Serial.println("8 channel Servo test!");
pwm.begin();
/*
* In theory the internal oscillator (clock) is 25MHz but it really isn't
* that precise. You can 'calibrate' this by tweaking this number until
* you get the PWM update frequency you're expecting!
* The int.osc. for the PCA9685 chip is a range between about 23-27MHz and
* is used for calculating things like writeMicroseconds()
* Analog servos run at ~50 Hz updates, It is importaint to use an
* oscilloscope in setting the int.osc frequency for the I2C PCA9685 chip.
* 1) Attach the oscilloscope to one of the PWM signal pins and ground on
* the I2C PCA9685 chip you are setting the value for.
* 2) Adjust setOscillatorFrequency() until the PWM update frequency is the
* expected value (50Hz for most ESCs)
* Setting the value here is specific to each individual I2C PCA9685 chip and
* affects the calculations for the PWM update frequency.
* Failure to correctly set the int.osc value will cause unexpected PWM results
*/
pwm.setOscillatorFrequency(27000000);
pwm.setPWMFreq(SERVO_FREQ); // Analog servos run at ~50 Hz updates
delay(10);
}
// You can use this function if you'd like to set the pulse length in seconds
// e.g. setServoPulse(0, 0.001) is a ~1 millisecond pulse width. It's not precise!
void setServoPulse(uint8_t n, double pulse) {
double pulselength;
pulselength = 1000000; // 1,000,000 us per second
pulselength /= SERVO_FREQ; // Analog servos run at ~60 Hz updates
Serial.print(pulselength); Serial.println(" us per period");
pulselength /= 4096; // 12 bits of resolution
Serial.print(pulselength); Serial.println(" us per bit");
pulse *= 1000000; // convert input seconds to us
pulse /= pulselength;
Serial.println(pulse);
pwm.setPWM(n, 0, pulse);
}
void loop() {
// Drive each servo one at a time using setPWM()
Serial.println(servonum);
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);
// Drive each servo one at a time using writeMicroseconds(), it's not precise due to calculation rounding!
// The writeMicroseconds() function is used to mimic the Arduino Servo library writeMicroseconds() behavior.
for (uint16_t microsec = USMIN; microsec < USMAX; microsec++) {
pwm.writeMicroseconds(servonum, microsec);
}
delay(500);
for (uint16_t microsec = USMAX; microsec > USMIN; microsec--) {
pwm.writeMicroseconds(servonum, microsec);
}
delay(500);
servonum++;
if (servonum > 7) servonum = 0; // Testing the first 8 servo channels
}
hextejas:
In any respect here it is: Its named "Servo".
The code segment you originally asked about:
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver *pwm;
pwm->setPWM(mip->servo_num, 0, mip→pos/US_PER_BIT);
pwm = new Adafruit_PWMServoDriver(GIMBAL_I2C_ADDR);
pwm->begin();
pwm->setPWMFreq(SERVO_FREQ);
Does not appear in the sketch you just posted. So, it's unclear to me how you're going to get any help with it.
For the example sketches as well ? I thought that they were available for everyone with the Arduino IDE installed.
No, you're talking about the "Examples from Custom Libraries" block in the Examples pull down menu. Unless you install the Adafruit library, the sketch you reference will not be available... only the native Servo examples, "Knob" and "Sweep". So it's just as well that you posted it.
But what I was looking for and Jowhvasser and bfvalvo addressed. It was what the difference was between
pwm.begin();
pwm->begin();
the m.begin vs m->begin
I dont know if that has any impact.
Here is my original sketch but the problem lies in one of the additional .ccp (gimbal.cpp)or .h files of which there are 17.
I saw no benefit in trying to post it(them) or using the MRE method.
/* Autonomous Satellite Tracker.
*
* Connections on Adafruit ESP8266 Huzzah:
* Servo controller connects to SDA and SCL
* GPS TX connects to 16, RX to 2
*
*/
#include "AutoSatTracker-ESP.h"
#include "NV.h"
#include "Sensor.h"
#include "Circum.h"
#include "Gimbal.h"
#include "Target.h"
#include "Webpage.h"
NV *nv;
Sensor *sensor;
Circum *circum;
Gimbal *gimbal;
Target *target;
Webpage *webpage;
/* called first and once
*/
void
setup()
{
// init serial monitor
Serial.begin (115200);
delay(500);
// this just resets the soft timeout, the hard timeout is still 6 seconds
ESP.wdtDisable();
// scan for I2C devices
resetWatchdog();
Serial.println();
Serial.print (F("Scanning I2C:"));
for (uint8_t a = 1; a < 127; a++) {
Wire.beginTransmission(a);
if (Wire.endTransmission() == 0) {
Serial.print (' '); Serial.print (a, HEX);
}
}
Serial.println();
// instantiate each module
Serial.println (F("making NV"));
nv = new NV();
Serial.println (F("making Sensor"));
sensor = new Sensor();
Serial.println (F("making Circum"));
circum = new Circum();
Serial.println (F("making Gimbal"));
gimbal = new Gimbal();
Serial.println (F("making Target"));
target = new Target();
Serial.println (F("making Webpage"));
webpage = new Webpage();
// all set to go.. see you in loop()
Serial.println (F("Ready"));
}
/* called repeatedly forever
*/
void
loop()
{
// check for ethernet activity
webpage->checkEthernet();
// check for new GPS info
circum->checkGPS();
// follow the target
target->track();
}
void
resetWatchdog()
{
ESP.wdtFeed();
yield();
}
hextejas:
I saw no benefit in trying to post it(them) or using the MRE method.
Then what is your question?
gfvalvo,, I thought that I was clear in what I was looking for. If not, here it is again.
But what I was looking for and Jowhvasser and bfvalvo addressed. It was what the difference was between
pwm.begin();
pwm->begin();
the m.begin vs m->begin
I dont know if that has any impact.
=============================
And then the original .cpp file that is causing the trouble exceeds the 9000 character limit,
I suggest that if you are interested in the original program with all the sub programs and .h files, it is available for down load here:
Autosattracker
hextejas:
gfvalvo,, I thought that I was clear in what I was looking for. If not, here it is again.
But what I was looking for and Jowhvasser and bfvalvo addressed. It was what the difference was between
pwm.begin();
pwm->begin();
the m.begin vs m->begin
I dont know if that has any impact.
And then the original .cpp file that is causing the trouble exceeds the 9000 character limit,
I suggest that if you are interested in the original program with all the sub programs and .h files, it is available for down load here:
[Autosattracker](http://clearskyinstitute.com/ham/AST/)
Actually, you weren't clear as I still don't see a question. And, I have no intention of wading through a large program that I have no interest in analyzing. So, unless you're willing and able to post a short, concise MRE that demonstrates your problem, all I can offer is generic advise: It appears that you don't understand dynamic object creation or pointers to objects. There are plenty of resources available on the web that will instruct you in these techniques.