Digital I/O + X2

Hi!

I’m using Orangutan X2 Microcontroller for my sumo-robot project. For the last days I’ve been trying to set up a bump sensor. Using this sensor I would be able to know,
when my robot is hitten by other participant.
I have followed this scheme, to setup a proper sensor.
After soldering the sensor to the Digital socket on the microcontroller, I checked the sensor with a multimeter, and everything was as it should be -
when the switch is pressed the voltage goes down to 0.3V.
So I assume, that the sensor itself is doing fine. So my problem should be at the code.
Here’s a test code I wrote for the sensor, to check whether it’s working. The robot acts as the sensor would be driven low all the time. The worst thing is that it doesn’t react to the switch, whether it’s pressed or not, it doesn’t change a thing.
My question is, is there something wrong with the code? Did I miss some important lines within the code?

#include "SPI.h"

int main()
{
delay_ms(3000);
SPIInit();
while (1)
{


DDRC  &= ~(1 << PORTC2);   // make pin PC2 an input
   PORTC |=  (1 << PORTC2);   // enable pull-up on pin PC2 (this means pin PC2
                     //  will read as high unless externally driven low)
					 if (!(PINC & (1 << PORTC2)))	// if pin PC2 input reads as high


	{
	setMotor1( 50 );
	setMotor2( 50 );
	}

else
{
	setMotor1( 50 );
	setMotor2( -50 );
	}

}
return 0;
}

Hello.

Why are you using pin PC2 for your sensor? On the X2, port C is used for the LCD data lines, and they double as the three user pushbuttons and five user LEDs. The reason why PC2 is always reading low is because it is being pulled low by the user LED on the line. If you try using one of the user I/O pins (port A or port D), you should have better results.

- Ben

Thank you Ben! I solved the problem by removing the line that manually sets Port D2 “high” and it worked.