Using EV3 sensor with DI sensor

My son and I are trying to work write a program, in Python, that takes repeated readings (within a loop) from our DI thermal infrared sensor and also from our EV3 gyro. We’ve adapted the sensor examples from the github so that, on their own, each works within the loop that we want. However, we can’t get them both to work within the same program.

One of two things happens. If, before calling result = BrickPiUpdateValues() for the Gyro, we do not include the line BrickPiSetupSensors(), we get an error message when we try to run, pointing to this line. If we do NOT include this line, then we can run without an error message, but the Gyro returns an invariant result of 0.

The DI-dtIR code contains stuff at the beginning which we don’t quite understand. My guess is that this sets up the bus for the sensors in a way that is incompatible with what the EV3 sensors needs. Is this correct? And if so, is there a way to get these two sensors working together smoothly? I guess as a worst case we could spring for an EV3 IR sensor, since the sensor example for that looks a lot simpler! But we were hoping to use the DI one, which we’ve already got!

Any help/advice would be appreciated!

Thanks,
Jeff

Hey Jeff,

Could you post the code? That might help us a bit in troubleshooting the challenge you’re facing.

The dTIR needs a little bit of “space”; it can’t be polled as quickly as other sensors. You might try inserting a few 0.1 second pauses in the code, and see if that improves the operation.

Best, John

Hi John,

Attached is code that does not use the gyro at all. [The relevant code is Thing_Seer1. I’d previously uploaded a different version, which is there as Thing_Seer, and which I can’t seem to remove from this post.) I’d like to take a gyro reading within the function turn(direction, power), (and then have the function return that value to the larger program that called it).` The most natural thing, I think, would be to call

BrickPi.SensorType[PORT_4] = TYPE_SENSOR_EV3_GYRO_M0    
BrickPiSetupSensors()			

At the beginning of the main program, at the same place where the thermal infrared sensor is setup, and then to call

result = BrickPiUpdateValues()   
	if not result :
		gyro = BrickPi.Sensor[PORT_4]

within theturn(direction, power) function.
But that doesn’t work. Any help would be welcome.
Jeff

Here’s a version of the code that attempts to integrate the gyro. It does two things:

  1. Consistently returns a value of 0, regardless of the actual angle,
  2. Slows the rest of the program down immensely – and irregularly. It makes for long, slow pauses each time turner()is called within the program.

I’d be really grateful or any help!