Sonar Sensor Problem

I have a problem with programming an ultrasonic sensor that is completely baffling me, I hope someone knows whats going wrong.
Essentially I’m using it for a simple while statement for reversing, I have done this a couple times before, but this time I found the ultrasonic sensor wasn’t showing up in the debugger window, I tried a few different obvious things (checking ports and config code and such) yet it still didn’t work. So I created the simplest code I could think of to try to diagnose the problem, and I found I could get it to recognise the sensor if I didn’t include any other sensors in the setup. Here is the code I tried:
This works:

#pragma config(Sensor, dgtl4,  sonarSensor,    sensorSONAR_inch)
#pragma config(Motor,  port8,           Right1,        tmotorVex393HighSpeed_MC29, openLoop, reversed)
#pragma config(Motor,  port9,           Right2,        tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor,  port2,           Left1,         tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor,  port3,           Left2,         tmotorVex393HighSpeed_MC29, openLoop)

task main()
{
	wait1Msec(2000);			

	while(SensorValue(sonarSensor) > 5  || SensorValue(sonarSensor) == -1)	
	{                                                                       
		motor[Left1]  = -63;
		motor[Left2]  = -63;
		motor[Right1] = 63;
		motor[Right2] = 63;
	}

}

This doesn’t:

#pragma config(Sensor, in1,    FrontL1,        sensorLineFollower)
#pragma config(Sensor, in2,    FrontR1,        sensorLineFollower)
#pragma config(Sensor, in3,    FrontM1,        sensorLineFollower)
#pragma config(Sensor, in4,    Back1,          sensorLineFollower)
#pragma config(Sensor, in7,    ClawSensor,     sensorPotentiometer)
#pragma config(Sensor, in8,    LiftSensor,     sensorPotentiometer)
#pragma config(Sensor, dgtl4,  sonarSensor,    sensorSONAR_cm)
#pragma config(Sensor, dgtl9,  LeftRotation,   sensorQuadEncoder)
#pragma config(Sensor, dgtl11, RightRotation,  sensorQuadEncoder)
#pragma config(Motor,  port2,           Left1,         tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor,  port3,           Left2,         tmotorVex393HighSpeed_MC29, openLoop)
#pragma config(Motor,  port4,           Leftlift,      tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port5,           Rightlift,     tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port7,           Claw,          tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port8,           Right1,        tmotorVex393HighSpeed_MC29, openLoop, reversed)
#pragma config(Motor,  port9,           Right2,        tmotorVex393HighSpeed_MC29, openLoop)


task main()
{
	wait1Msec(2000);					
	while(SensorValue(sonarSensor) > 5  || SensorValue(sonarSensor) == -1)	
	{                                                                         
			motor[Left1]  = -63;
			motor[Left2]  = -63;
			motor[Right1] = 63;
			motor[Right2] = 63;
	}

}

I really can’t tell why there should be any difference.
Also now its only displaying the 2 quad encoders in the debugger. :stuck_out_tongue:

Thanks.

Just move the Sonar sensor to ports 1 and 2. There is a hardware issue(simplifying the truth) that means you cant use an encoder/ ultrasonic sensor in both ports 4 and 10.

Thank you! It works just fine now.