Arduino to Pololu Micro Maestro serial connection
hi all,
ive been trying use 6 potentiometers connected arduino uno connected via serial pololu micro maestro control 6 servo outputs , have been struggling code.
i found code online controls micro maestro fixed positions (http://www.quantumphysguy.com/2013/07/08/arduino-micro-maestro/)
in loop, there way add potentiometer instead of defined 180 degree rotation?
help appreciated, thanks.
ive been trying use 6 potentiometers connected arduino uno connected via serial pololu micro maestro control 6 servo outputs , have been struggling code.
i found code online controls micro maestro fixed positions (http://www.quantumphysguy.com/2013/07/08/arduino-micro-maestro/)
code: [select]
#include <softwareserial.h>
const int default_baud = 9600;
const int servo_controller_rx_pin = 11; // servo controller's rx pin.
const int servo_controller_tx_pin = 12; // servo controller's tx pin.
softwareserial servocontroller = softwareserial(servo_controller_rx_pin, servo_controller_tx_pin);
void setup()
{
servocontroller.begin(default_baud);
delay(500);
}
void moveservo(int servochannel, int target)
{
//656ms pwm pulse represents servo angle of 0 degrees.
//2000ms pwm pulse represents servo angele of 180 degrees.
//these values vary based on servo use, check servo's
//spec documentation , verify pwm pulses needed move it.
byte serialbytes[4]; //create byte array object hold communication packet.
target = (map(target, 0, 180, 656, 2000) * 4); //map target angle corresponding pwm pulse.
serialbytes[0] = 0x84; // command byte: set target.
serialbytes[1] = servochannel; // first byte holds channel number.
serialbytes[2] = target & 0x7f; // second byte holds lower 7 bits of target.
serialbytes[3] = (target >> 7) & 0x7f; // third byte holds bits 7-13 of target.
servocontroller.write(serialbytes, sizeof(serialbytes)); //write byte array serial port.
}
void loop()
{
moveservo(1, 180); //move servo on channel 0 angle of 180 degrees
moveservo(0, 180); //move servo on channel 1 angle of 180 degrees
delay(2000); //wait 2000ms
}
in loop, there way add potentiometer instead of defined 180 degree rotation?
help appreciated, thanks.
quote
in loop, there way add potentiometer instead of defined 180 degree rotation?
of course.
quote
help appreciated, thanks.
help what? reading analog pin? that's trivial. map() value servo range? that's trivial. calling function variable instead of hard-coded value? you've got kidding.
Arduino Forum > Using Arduino > Programming Questions > Arduino to Pololu Micro Maestro serial connection
arduino
Comments
Post a Comment