Home \ Help \ Search \ Login RSS

Welcome, Guest. Please Login

This forum is now READ-ONLY! Please visit http://forum.wiring.co/ for the new forum.

Wiring ForumWiring HardwareTroubleshooting › Wire.receive conflicting with matrix

Page Index Toggle Pages: 1
Wire.receive conflicting with matrix (Read 8191 times)
11/21/10 at 04:22:46

mga   Offline
YaBB Newbies

Posts: 41
*
 
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;
} 



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
 
IP Logged
 
Reply #1 - 11/21/10 at 06:32:23

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
how does the Matrix behave when commenting the call to
// somevar = readRegister(chr); ?
 
IP Logged
 
Reply #2 - 11/21/10 at 06:38:43

mga   Offline
YaBB Newbies

Posts: 41
*
 
It behaves fine. That's why I went and started going through that function line by line trying to isolate the culprit.
 
IP Logged
 
Reply #3 - 11/21/10 at 07:27:59

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
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;
 
IP Logged
 
Reply #4 - 11/21/10 at 17:16:23

mga   Offline
YaBB Newbies

Posts: 41
*
 
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.
 
IP Logged
 
Reply #5 - 11/22/10 at 07:52:23

mga   Offline
YaBB Newbies

Posts: 41
*
 
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
 
IP Logged
 
Reply #6 - 11/22/10 at 15:16:13

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
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.
 
IP Logged
 
Reply #7 - 11/22/10 at 15:42:19

mga   Offline
YaBB Newbies

Posts: 41
*
 
Thanks. I will try that. I will look into updating the sensor only every N ms (instead of on every loop).
 
IP Logged
 
Reply #8 - 11/22/10 at 18:00:33

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
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.
 
IP Logged
 
Reply #9 - 11/22/10 at 18:23:53

mga   Offline
YaBB Newbies

Posts: 41
*
 
Thanks
 
IP Logged
 
Reply #10 - 11/22/10 at 22:12:06

mga   Offline
YaBB Newbies

Posts: 41
*
 
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
 
IP Logged
 
Page Index Toggle Pages: 1