Wiring Forum
http://wiring.org.co/cgi-bin/yabb/YaBB.pl
Wiring Hardware >> Troubleshooting >> Wire.receive conflicting with matrix
http://wiring.org.co/cgi-bin/yabb/YaBB.pl?num=1290313366

Message started by mga on 11/21/10 at 04:22:46

Title: Wire.receive conflicting with matrix
Post by mga on 11/21/10 at 04:22:46
Hi

I am using the Wire library to get input from a capacitive sensor. I also have a 5x7 matrix (LiteOn LTP 747R) using only 12 pins and no chip controller (pins directly to the Wiring board). The sensor is powered via a 3.3V transistor. The power source is set up to come from the USB connection. I have this function readRegister:

[code c++]unsigned char readRegister(unsigned char r)
{
  unsigned char v = '1';
  Wire.beginTransmission(I2C_ADDRESS);
  Wire.send(r);  // register to read
  Wire.endTransmission();

  Wire.requestFrom(I2C_ADDRESS, 1); // read a byte
  while(Wire.available()==0) {
    // waiting
  }
  // the next line generates "noise"
  v = Wire.receive();
  return v;
}[/code]

I did the poor man's debugging commenting line by line starting with all commented (leaving the variable and the return statement uncommented) and then un-commenting one by one from top to bottom (I gave v a default value so it wouldn't "break").

Right now the display matrix is just showing some "hello world" text. It all works well while I uncomment line by line until I reach v = Wire.receive(); when the display starts behaving erratically (e.g. "h llo wor d" with flickering). It is as if the receiving function introduces some sort of noise to the rest of the circuit.

What could be wrong?

Any help will be appreciated.

- mga

Title: Re: Wire.receive conflicting with matrix
Post by barragan on 11/21/10 at 06:32:23
how does the Matrix behave when commenting the call to
// somevar = readRegister(chr); ?

Title: Re: Wire.receive conflicting with matrix
Post by mga on 11/21/10 at 06:38:43
It behaves fine. That's why I went and started going through that function line by line trying to isolate the culprit.

Title: Re: Wire.receive conflicting with matrix
Post by barragan on 11/21/10 at 07:27:59
I suspect this is taking too long:

while(Wire.available()==0) {
    // waiting
  }

test replacing this by:

  if(Wire.available()>0) {
    v = Wire.receive();
  }
  return v;

Title: Re: Wire.receive conflicting with matrix
Post by mga on 11/21/10 at 17:16:23
Thanks for the reply. It still flickers. During the line-by-line debugging I had a version with only the while(){} and no v = Wire.receive(); and it worked fine. It is just when the receive gets called that the matrix misbehaves.

Title: Re: Wire.receive conflicting with matrix
Post by mga on 11/22/10 at 07:52:23
Assuming it is not a software issue, how would a recommended wiring go? I tried adding a large capacitor (1000 microF 10V) thinking it may be loss of current by the mtrix due to the capacitive sensor but that did not work (the matrix still lights up very, very dimly almost not at all).

I had a similar issue with the matrix and motors, and adding a 47 microF capacitor worked fine so that's why I tried this.

Thanks

Title: Re: Wire.receive conflicting with matrix
Post by barragan on 11/22/10 at 15:16:13
You might consider to get extra power. The USB power is ok for small experiments, but working with LED matrix and Motors require higher current drive. Perhaps using an external power supply for those devices or for the Wiring board will help.

Title: Re: Wire.receive conflicting with matrix
Post by mga on 11/22/10 at 15:42:19
Thanks. I will try that. I will look into updating the sensor only every N ms (instead of on every loop).

Title: Re: Wire.receive conflicting with matrix
Post by barragan on 11/22/10 at 18:00:33
Yes, updating every loop is not advisable for these type of sensor, from the datasheet you could observe that it takes time to get a reading, try to lower the reading rate.

Title: Re: Wire.receive conflicting with matrix
Post by mga on 11/22/10 at 18:23:53
Thanks

Title: Re: Wire.receive conflicting with matrix
Post by mga on 11/22/10 at 22:12:06
using:


Code:
if (timehaspassed) {
  readFromI2C();
}


finally worked! with ~300ms the flickering is not very notorious although the sensing is not very responsive but I can live with that.

thanks

Wiring Forum » Powered by YaBB 2.5 AE!
YaBB Forum Software © 2000-2010. All Rights Reserved.