Motor shield v2/TC34725 color sensor conflict?

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
leo3linbeck
 
Posts: 17
Joined: Sun Aug 10, 2014 3:51 pm

Motor shield v2/TC34725 color sensor conflict?

Post by leo3linbeck »

Greetings!

I have a AFMS v2 and 2 TC34725 breakouts wired up. When I disconnect the TC34725s, the motor shield works fine. When I connect the TC34725s, the motor shield stops working. Is there an I2C (address or other) conflict between these two/three devices? Any advice on how to get these three devices to work together?

Any help would be greatly appreciated. Cheers,

L3

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor shield v2/TC34725 color sensor conflict?

Post by adafruit_support_bill »

There shouldn't be any address conflict there. Does the problem occur as soon as you connect the device, or only if the code tries to talk to it?

User avatar
leo3linbeck
 
Posts: 17
Joined: Sun Aug 10, 2014 3:51 pm

Re: Motor shield v2/TC34725 color sensor conflict?

Post by leo3linbeck »

Thanks so much for getting back to me.

It happens during the setup sequence. If I comment out the motor shield setup code with the sensors connected to SDA and SCL, the sensors work fine. If I disconnect the sensor leads from the Arduino (Uno R3), and comment out the sensor startup code, the motors work fine.

With everything connected and all code running, I've traced the problem to the motor shield setup. Adafruit_MotorShield.begin() calls Adafruit_PWMServoDriver.begin() which calls Adafruit_PWMServoDriver.begin.reset() which calls Adafruit_PWMServoDriver.begin.write8() which then calls:

WIRE.beginTransmission(_i2caddr);
WIRE.write(addr);
WIRE.write(d);

and then it hangs when calling:

WIRE.endTransmission();

I'm not sure if that helps, but that's where the setup sequence goes off the rails.

Thanks for any help or suggestions. Cheers,

L3

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor shield v2/TC34725 color sensor conflict?

Post by adafruit_support_bill »

If I disconnect the sensor leads from the Arduino (Uno R3), and comment out the sensor startup code, the motors work fine.
What happens if the sensors are connected but the sensor startup code is commented out?

Please post the code you are using. Use the "</>" button above and paste your code between the

Code: Select all

 tags.

User avatar
leo3linbeck
 
Posts: 17
Joined: Sun Aug 10, 2014 3:51 pm

Re: Motor shield v2/TC34725 color sensor conflict?

Post by leo3linbeck »

Just ran the following test:

1. Connected the sensors.
2. Commented out sensor setup code.
3. Made the motor shield code active (i.e. uncommented it).

The motor shield setup worked fine. However, as soon as I tried to run the stepper, the code stopped working. Here's the code where it stopped working (note that I redefined FORWARD to STEP_BACKWARD and BACKWARD to STEP_FORWARD to match the "logic" of my device design):

Code: Select all

Serial.println(F("Initializing motor shield"));
AFMS.begin();
Serial.println(F("Initializing motor"));
motor->setSpeed(rpm);
Serial.println(F("Initializing solenoid"));
solenoid->setSpeed(solenoid_power);
  
Serial.println(F("Resetting X stage"));
move_steps(30000, STEP_BACKWARD, DOUBLE);

...

void move_steps(int steps, int dir, int rate) {
  Serial.print(F("Moving "));
  Serial.print(steps);
  Serial.println(F(" steps"));
  for (int i = 0; i < steps; i += 1) {
    if (dir == STEP_FORWARD && digitalRead(pinFrontLimitSwitch) == HIGH) {
      Serial.println(F("Front limit switch tripped"));
      return;
    }
    if (dir == STEP_BACKWARD && digitalRead(pinBackLimitSwitch) == HIGH) {
      Serial.println(F("Back limit switch tripped"));
      return;
    }
    motor->step(1, dir, rate);
  }
}
Looking at the serial port output, the last output I get is this:
Initializing motor shield
Initializing motor
Initializing solenoid
Resetting X st
So it doesn't finish sending the last println to the serial port before the code stops. Nothing happens to the motor (no action).

Does that help narrow it down? Thanks again for all the help!

Cheers,
L3

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor shield v2/TC34725 color sensor conflict?

Post by adafruit_support_bill »

So just having them on the i2c bus is enough to hang things up. Can you post some photos showing your soldering and connections?

User avatar
leo3linbeck
 
Posts: 17
Joined: Sun Aug 10, 2014 3:51 pm

Re: Motor shield v2/TC34725 color sensor conflict?

Post by leo3linbeck »

I will try to send some pictures if necessary. But before I do, if wiring could be the issue, lemme describe what I did:

0. I have a device (motor + solenoid + sensors) and a control unit (Arduino, motor shield, etc.).
1. I soldered four leads coming out of the two sensors (SDA-1, SCL-1, SDA-2, and SCL-2). The other end of each lead I soldered to a pin on a D Sub 25-pin female connector. This is on the device side.
2. I used a male-male 25 pin cable to connect to the female connector on the device to a female connector on the control unit. I used an ohmmeter to assure that each pin was well-connected to the associated lead. I don't have the pin layout in front of me, but let's say that they were pins 5, 6, 7, and 8 with leads from SDA-1, SCL-1, SDA-2, and SCL-2, respectively.
3. On the control unit female connector, I soldered a jumper wire between the two pins associated with each channel. In other words, I jumped pins 5 to 7 and 6 to 8, so that SDA-1 was jumped to SDA-2, and SCL-1 was jumped to SCL-2. I also soldered a lead from each set of the jumped pins to connect to the associated header pin on the Ardunio. So, in yet other words, I connected pin 5 to pin 7 and pin 7 to the SDA header pin, and pin 6 to pin 8 and pin 8 to the SCL header pin.
4. To switch between sensor units, I connected the Vin for each sensor to an analog pin (A0 and A1). The idea is to power up the sensor I want to use by applying digitalWrite(pinSensor1Vin, HIGH) and digitalWrite(pinSensor2Vin, LOW), and the switching these to use the other sensor. Same principle for the LEDs as well (which are wired to A2 and A3).

Of course, as I write this it seems like this was probably not the way to do this. If this is indeed wrong, I'd appreciate any guidance on how to wire this properly.

If this is not enough to point me in the right direction to solve this issue, I will try to send some photos.

Thanks again. Cheers,
L3

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor shield v2/TC34725 color sensor conflict?

Post by adafruit_support_bill »

The idea is to power up the sensor I want to use by applying digitalWrite(pinSensor1Vin, HIGH) and digitalWrite(pinSensor2Vin, LOW), and the switching these to use the other sensor. Same principle for the LEDs as well (which are wired to A2 and A3).
If I understand you correctly, only one of the sensors is powered at a time. But both sensors are still on the i2c bus. With the sensor un-powered, the i2c pullups become pull-downs and render the bus inoperable.

If you want to switch between 2 sensors with the same address, there is a 'soft i2c' library so you can set up a bus on another pair of pins.

User avatar
leo3linbeck
 
Posts: 17
Joined: Sun Aug 10, 2014 3:51 pm

Re: Motor shield v2/TC34725 color sensor conflict?

Post by leo3linbeck »

Ah, got it. Makes sense. One solution, I suppose, would be to set up a multiplexer that would actually only put one sensor at a time on the bus. But I will look into the soft I2C library and see if that is a good approach.

Very much appreciate the assistance. Cheers,

L3

User avatar
leo3linbeck
 
Posts: 17
Joined: Sun Aug 10, 2014 3:51 pm

Re: Motor shield v2/TC34725 color sensor conflict?

Post by leo3linbeck »

Figured out how to make this work.

1. Connected each sensor to SDA and SCL (soldered on a 2 pin block on the motor shield's extra pin holes to do this).

2. During setup, for each sensor (code below is for sensor 1, just do the same thing for sensor 2):

Code: Select all

  Serial.println("Turning on sensor 1");
  digitalWrite(pinSensor1Vin, HIGH);
  Serial.println("Turning on sensor 1 LED...");
  digitalWrite(pinSensor1LED, HIGH);
  delay(1000);
  sensor = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_101MS, TCS34725_GAIN_16X);
  if (sensor.begin()) {
    Serial.println("Sensor 1 successfully started up");
    Serial.println("Disabling assay sensor...");
    sensor.disable();
  }
  else {
    Serial.println("Sensor 1 failed to start up");
  }
  Serial.println("Turning off sensor 1 LED..."));
  digitalWrite(pinSensor1LED, LOW);
By keeping the Vin on, it keeps the sensor from crashing the bus. Disable keeps the sensor from responding to reads and writes at the address (which is the same for both sensors).

3. When it's time to take a reading, run the following code, set Vin to LOW for the sensor that needs to be ignored, and enable the sensor you want to read, take readings, and then disable the sensor and set Vin for the other sensor back to HIGH:

Code: Select all

void get_sensor_readings() {
  int colorTemp = 0;
  int lastColorTemp = 0;
  Adafruit_TCS34725 sensor;
  
  digitalWrite(pinSensor2Vin, LOW);
  analogWrite(pinSensor1LED, 1000);
  sensor = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_101MS, TCS34725_GAIN_16X);
  delay(500);
  sensor.enable();
  delay(500);
  Serial.println("Reading sensor 1: ");
  for (int i = 0; i < 20; i += 1) {
    colorTemp = get_one_sensor_reading(sensor);
    if (i > 3 && colorTemp == lastColorTemp) {
      break;
    }
    lastColorTemp = colorTemp;
    delay(500);
  }
  analogWrite(pinSensor1LED, 0);
  sensor.disable();
  digitalWrite(pinSensor2Vin, HIGH);
  Serial.println("Sensor 1 reading complete");
}

int get_one_sensor_reading(Adafruit_TCS34725 sensor) {
  uint16_t r, g, b, c;
  
  sensor.getRawData(&r, &g, &b, &c);
  int colorTemp = sensor.calculateColorTemperature(r, g, b);
  int lux = sensor.calculateLux(r, g, b);
  Serial.print("  Red: ");
  Serial.print(r);
  Serial.print("  Green: ");
  Serial.print(g);
  Serial.print("  Blue: ");
  Serial.print(b);
  Serial.print("  Clear: ");
  Serial.println(c);
  Serial.print("  Color temperature : ");
  Serial.print(colorTemp);
  Serial.print("  Lux: ");
  Serial.println(lux);
  Serial.println(" ");
  
  return colorTemp;
}
I'm not sure the delays are all necessary - I added them as a precaution where I think the device needs time to power up or enable.

Anyway, this works, and doesn't crash the I2C bus. At least so far... ;-)

Thx again for the help. Best,

L3

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”