Baby Orangutan PORT D1 question

Hello, i want to use encoder with baby-o. For calculate, distance with encoder. Here is my example code and its working pretty good. But when i try to use PD1 i could not count the encoder pulses. Am i missing something with PD1 ? I saw on pin mapping that pin also can use for user red led. But it is also Digital IO.

Note 1 : for the future, i will control pozition with my baby o, so i will use 2 motor and for each motor 2 encoder channel.
I am planning to use for encoder channels, PD0 - PD1 - PB5 - PB4 . These are my only free pins on baby o. I also planning to use for buzzer PB2 and and my own led PB1. So if you suggest me to change for led to PD1 or buzzer pin with PD1, i will be waiting.

Note2 : My encoder resulation is 14 pulses per 1 rotation. And my motor is 12.000 RPM. So i will use it on high speeds too.

Thank you.

int main(void){
	// a and x are global variable
	if (((PIND & 0x01) != 0) && (a==0))  
	if (((PIND & 0x01) == 0) && (a==1))
	if ((x>=0) && (x<=100))
			wait(10);   //wait is my function for delay 10 second.
	return 0;


It is possible that the LED load on PD1 is affecting the readings of your encoder. Since you are planning to use an external LED and are not opposed to swapping the two pins (PD1 and PB1), it would probably be more practical to connect your external LED to PD1 and use PB1 for one of your encoder channels.

You mentioned about using PB5 and PB4 for additional encoder channels (later on). Those pins are used for programming the Baby Orangutan, so if you connect your encoder outputs directly to them, you could cause a short circuit. Please see the warning box under the “Module Pinout and Component Identification” section in the Baby Orangutan B User’s Guide for more details. If you decide to continue to use those pins, I suggest adding current-limiting resistors (e.g. 1 kΩ) on your encoder outputs so that they do not cause a short circuit with the programmer or the AVR during programming.

By the way, you might consider using pins PC0-PC3 if they are available. Just in case you did not know, those pins can be used to read both analog and digital inputs.

- Amanda

Hello Amanda, thank you for answer.

You are right. I was using red_led, before using encoder counts on my program, and it’s true that effecting to read my encoder pulses. I swapped my pins, with PD1 and PB1, and problem solved. Now i will use my user led and red user led together. It will not be a problem for me.

About PB5 and PB4, i have read that warning message, but i have no chance to use any of PC ports. I am using them read digital sensor values. So i need to use PB4 and PB5. Except if i can use PB4 and PB5 for read QTRRC sensors, i can change PB4 and PB5 with PC0 and PC1.
Here is my encoders datasheet, this encoder is 3 channel but i will use only channel A and channel B. (I will use easy module of encoder. (not Quad)

15-102-EN-May.pdf (170.5 KB)

Can anyone help about my problem ?

You could use PB4 and PB5 to read values of your QTR-RC sensors and connect the encoders to PC0 and PC1. Since the QTR-RC sensors have a 220 Ohm resistor on their output, you do not need to add additional current-limiting resistors like you would if you use PB4 and PB5 for your encoders channels.

- Amanda