Switch 'Emitters On' from PC5 to PD1 in 3pi

I’m using PC5 for my R/C pulse inputs…and want to use PD1 to still control the IR Emitters in the 3pi Line Follower code. How do I rewrite the Line Follower code to swap PD5 to PD1. No issues with setting up PD1 DDR as an input etc but …concerned over wha’ts embedded in the Line Follower library functions that are called in the Line Follower code that still control PD5. Any help on changing the library functions (if that’s what’s required) is appreciated.
Dennis

Hello, Dennis.

It is not clear to me what you are trying to do with the line following sensors of your 3pi robot. Can you clarify?

It is possible for you to modify the code and be able to use the line following sensors as well as control your 3pi robot with a RC controller. The 3pi module in the AVR library contains functions that set up the line sensors to use PC5 to be an emitter control pin, which are invoked by calling pololu_3pi_init in the 3pi line follower code. You should avoid calling that function, and instead use the QTR sensor library’s function, qtr_rc_init, to set up the sensors. For now, I recommend setting the emitterPin parameter to an invalid value like 255, which means there will be no emitter control pin. This means that the IR emitters will always be on. After setting up the sensors with qtr_rc_init, you will need to use other commands from the same module to read your line sensors. These commands can be found in the “QTR Reflectance Sensors” section of the Pololu AVR Library Command Reference.

- Amanda

Thank you Amanda for the timely reply.
Yes I am trying to use the line following sensors and the RC control at the same time.

I initially substituted the following code to disable the emitter on control of PC5
"pololu_3pi_init_disable_emitter_pin(2000)"
since I HOPED to use the same sensor code found in the 3pi Line Following example.

From you suggestion it looks like I should try the following:
"qtr_rc_init(255)"
Did I understand the use of the invalid 255 code correctly above?
And now I must use the rest of the QTR module function…which will work
with the on board 3pi sensors?

Are there any other issues with using snippets of the 3pi RC code example like use of the timer or
tick functions that might cause interrupt problems if same are being used by the Line Following code?

Thank you,
Dennis

I had forgotten about the pololu_3pi_init_disable_emitter_pin command. I strongly recommend you to use that function, because it is much simpler than the other option discussed in my previous post. Calling the pololu_3pi_init_disable_emitter_pin function will initialize the 3pi robot as well as set the line sensors, so it is not necessary for you to set them again with qtr_rc_init(255). Also, by using pololu_3pi_init_disable_emitter_pin, you do not have to call other commands in the QTR sensor module and can continue to use the 3pi line following code example.

It should be fine for you to use parts of the 3pi RC code with the line following code. The 3pi line following code uses Timer 2, and the 3pi RC code uses Timer 1, so you would not encounter an issue where both codes are using the same timer.

- Amanda

Thanks
It looks like the buzzer may be using Timer 1 to play music, “welcome” and “Go”, so I will
X out that code as well just in case. Will let you know.

Hopefully the port/pin/ISR setups for 3pi RC that follow the Line Follower init code will allow
it to work now.

I also noticed that the 3pi RC calls #include interrupt.h; not used in the Line
Follower.

Is this redundant? a conflict?

Regards,
Dennis

The #include <avr/interrupt.h> directive in the 3pi RC code does not mean that it conflicts with the 3pi line following code. The interrupt.h header is needed to define the interrupt service routines (ISR) for ports PC5 and PD0 which will be called whenever the RC signal pins change from high to low or low to high. However, since the 3pi RC code uses the same timer, Timer1, as the buzzer in the line following code, I suggest that you remove or comment out those commands controlling the buzzer.

For anyone else following this thread, the RC 3pi code we have been discussing can be found in this sample project. Also, the 3pi line following code can be found under the “Example Project #1: Line Following” section in the 3pi robot user’s guide.

-Amanda