chipKIT® Development Platform

Inspired by Arduino™

Max32, MPIDE 0023, Serial Monitor and loop exit

Created Tue, 22 Jul 2014 22:27:48 +0000 by mdsousa


mdsousa

Tue, 22 Jul 2014 22:27:48 +0000

Hi

I have an Adafruit 16-channel 12-bit I2C PWMServoDriver brd hooked up to my Max32 and am using MPIDE 0023-linux64-20140316. I've modified sample servo code from Adafruit so that I could experiment with just one servo. Below is my embellishment of Adafruit's servo demo. A couple of things:

The loop doesn't seem to exit after the 'return' command (servo keeps on moving) When I bring up the Serial Monitor, nothing ever shows up on it.

Any ideas?

Thanks...

[color=#007F00]/[/color] [color=#007F00]Control of the servos on the UAS[/color] [color=#007F00]/[/color] #include <[color=#FF8000]Wire[/color].h> #include <Adafruit_PWMServoDriver.h> [color=#007F00]// called this way, it uses the default address 0x40[/color] Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); [color=#007F00]// Depending on your servo make, the pulse width min and max may vary, you [/color] [color=#007F00]// want these to be as small/large as possible without hitting the hard stop[/color] [color=#007F00]// for max range. You'll have to tweak them as necessary to match the servos you[/color] [color=#007F00]// have![/color] #define SERVOMIN  200 [color=#007F00]// this is the 'minimum' pulse length count (out of 4096)[/color] #define SERVOMAX  300 [color=#007F00]// this is the 'maximum' pulse length count (out of 4096)[/color] [color=#007F00]// our servo # counter[/color] [color=#FF0000]uint8_t[/color] servonum = 0; [color=#FF0000]uint8_t[/color] servo1 = 0; [color=#FF0000]void[/color] [color=#FF8000]setup/color { [color=#8B308B]Serial[/color].[color=#FF8000]begin/color; [color=#FF8000]delay/color; [color=#8B308B]Serial[/color].[color=#FF8000]println[/color]([color=#0066FF]"16 channel Servo test!"[/color]); pwm.[color=#FF8000]begin/color; pwm.setPWMFreq(60);  [color=#007F00]// Analog servos run at ~60 Hz updates[/color] } [color=#FF0000]void[/color] [color=#FF8000]loop/color { pwm.setPWM(0,0,225); [color=#FF8000]delay/color; [color=#007F00]// two seconds[/color] pwm.setPWM(0,0,475); [color=#FF0000]return[/color]; }


majenko

Tue, 22 Jul 2014 22:57:30 +0000

The loop doesn't seem to exit after the 'return' command (servo keeps on moving)

Yes it does. It's called "loop" for a reason. Guess why...?