So, I’ve been banging my head against the wall for days with this one. I’m trying to set up pins D7 and D6 to accept the PWM signal from my Spektrum RX throttle and pitch channels respectively, but I can’t seem to receive any pulses. The RX is getting power and binding with the TX, just fine, but when I try to check for new pulses using the Orangutan libs, it always comes back false. Here is my code, hopefully someone can help me out here.
#include <pololu/orangutan.h>
#define LEFT 0
#define RIGHT 1
#define LEFT_CHANNEL 7
#define RIGHT_CHANNEL 6
#define LEFT_CHANNEL_INDEX 0
#define RIGHT_CHANNEL_INDEX 1
void set_motor_speed_pwm_us(signed long pulseWidthMicroseconds, unsigned int motor);
void set_motor_speed_pwm_ticks(unsigned pulseWidthTicks, unsigned int motor);
int main()
{
// Print battery voltage (in mV) on the LCD.
clear();
print_long(read_battery_millivolts_x2());
// Set up display for showing motor speed
lcd_goto_xy(0,2);
print("LEFT: ");
print(0);
lcd_goto_xy(0,3);
print("RIGHT: ");
print(0);
// Start accepting Pulses on
pulse_in_start((unsigned char[]) {LEFT_CHANNEL, RIGHT_CHANNEL}, 2);
struct PulseInputStruct pulseInfoLeft;
struct PulseInputStruct pulseInfoRight;
// Turn green LEDs on to indicate that setup is complete and the main loop is starting.
green_led(HIGH);
green_led2(HIGH);
while(1)
{
// Update LCD with battery voltage
lcd_goto_xy(0,0);
print_long(read_battery_millivolts_x2());
// Is there a new high pulse on the left channel?
if (new_high_pulse(LEFT_CHANNEL_INDEX))
{
// Write "Pulse!" to show the first pulse has been received for debugging
lcd_goto_xy(10,2);
print("Pulse!");
get_pulse_info(LEFT_CHANNEL_INDEX, &pulseInfoLeft); // get pulse info for the left channel
set_motor_speed_pwm_ticks(pulseInfoLeft.lastHighPulse, LEFT);
}
// is there a new pulse on the right channel?
if (new_high_pulse(RIGHT_CHANNEL_INDEX))
{
// Write "Pulse!" to show the first pulse has been received for debugging
lcd_goto_xy(10,3);
print("Pulse!");
get_pulse_info(RIGHT_CHANNEL_INDEX, &pulseInfoRight); // get pulse info for the right channel
set_motor_speed_pwm_ticks(pulseInfoRight.lastHighPulse, RIGHT);
}
}
}
// Set the motor speed from RC controller input converted to ms
void set_motor_speed_pwm_us(signed long pulseWidthMicroseconds, unsigned int motor)
{
signed int motorSpeed;
// 1500 is the neutral point of an RC servo pulse, so subtract 1500 to zero the neutral position, then divide by 2 to reduce a range of ~500 down to 250
// for the Pololu OrangutanMotor functions
motorSpeed = ((pulseWidthMicroseconds - 1500) /2);
if (motor == LEFT)
{
set_m1_speed(motorSpeed);
// Update LCD
lcd_goto_xy(0,2);
print("LEFT: ");
print_long((signed long) motorSpeed);
}
else
{
set_m2_speed(motorSpeed);
// Update LCD
lcd_goto_xy(0,3);
print("RIGHT: ");
print_long((signed long) motorSpeed);
}
}
// Set the motor speed from RC controller input in system ticks
void set_motor_speed_pwm_ticks(unsigned long pulseWidthTicks, unsigned int motor)
{
signed long pulseWidthMicroseconds;
pulseWidthMicroseconds = (signed long) pulse_to_microseconds(pulseWidthTicks);
set_motor_speed_pwm_us(pulseWidthMicroseconds, motor);
}