Arduino Mega And ADJD-S311 Sesnor

Hi Guys.

I am Trying to use the sensor with the Arduino mega board.

Obviously the connections are pretty straight forward:

SDA - PIN 20
SCL- PIN 21

I am trying to use the lib from Bildr bildr Sensing color with the ADJD-S311 + Arduino - bildr.
I’ve got a similar problem as described in here : http://forum.arduino.cc/index.php/topic,161976.0.html

When i tried to debug with Serial.print i found the problem in the following method:
ADJDS311::readRegister

When Trying to preform the function: while (!Wire.available()) → Wire.availiable returns 0 all the time.

Also I’ve tried to go step backward and see what happens at writing to a sensor using this simple code:

#include <Wire.h>

void setup()
{
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output
}
#define DEBUG 1
void loop()
{
  int data= 0x7;
  int test=0;
  Wire.beginTransmission(0x74);
   Serial.print("Writing addr");
  test=Wire.write(0xFFFF);
  delay(5000);
  Serial.print("Write Address\n");
  if (DEBUG) Serial.print(test,DEC);
  Serial.print("\n");
  Serial.print("Writing Data");
  test=Wire.write(0xFFCC);
  delay(10000);
  if (DEBUG) Serial.print("Write Data\n");
  Serial.print("\n");
  if (DEBUG) Serial.print(test,DEC);
  test=Wire.endTransmission();
  if (DEBUG) Serial.print("End Transmistion Status \n");
  if (DEBUG) Serial.print(test,DEC);
}

I connected a scope to SDA line.
and what i saw was that only at
test=Wire.endTransmission();

the line had an actual signal. (Picture provided)

Any you guys have an idea how to work this out?
(P.S- i’ve tried using arduino duemilanove and seems to be the same result).

Thanks.

Obviously the connections are pretty straight forward:

SDA - PIN 20
SCL- PIN 21

It might be not so straightforward to you but you have to connect GND too, even if you provide power to the chip from elsewhere.

Highocatane:
I connected a scope to SDA line.
and what i saw was that only at
test=Wire.endTransmission();

the line had an actual signal. (Picture provided)

That’s how the Wire library is implemented. You start a new transfer with beginTransmission(), then use write() to fill a buffer and endTransmission() does the actual transfer over the bus.

When Trying to preform the function: while (!Wire.available()) → Wire.availiable returns 0 all the time.

This is a bug found in many libraries and it ends in an endless loop if an I2C transfer fails for any reason. If Wire.requestFrom() fails, Wire.available() will never return anything else than 0. This is different from the (interrupt driven) Serial implementation.

Please provide a link to the library itself, I couldn’t find code on the page you linked.

Hi,
Obviously I've connected the GND to the Sensor.

The link to the lib is located in the topic , but here it is again:

http://bildr.org/2012/01/adjd-s311_arduino/

Thank you.

The link to the lib is located in the topic , but here it is again:

That's the tutorial page, not the library itself. After searching for several minutes I found the link on that page. It's almost perfectly hidden, even with the hint in the text I overlooked it several times. That's why I asked for the link to the library, which is: http://code.bildr.org/download/965.zip.

Change the readRegister() method as follows:

// read a byte of data from ADJD-S311 address
unsigned char ADJDS311::readRegister(unsigned char address){
  unsigned char data;
  
  Wire.beginTransmission(ADJD_S311_ADDRESS);
  Wire.write(address);
  Wire.endTransmission();
  
  if (Wire.requestFrom(ADJD_S311_ADDRESS, 1)) {  
    return Wire.read();
  }
  return 0;
}

Better would be an error handling but this a least doesn't have an endless loop.

Hi.

Any Idea why i always get a NACK?

This is the test code:

#include <Wire.h>

void setup()
{
  delay(1000);
  Wire.begin(); // join i2c bus (address optional for master)
  Serial.begin(9600);
}

byte x = 0;
int Test;

void loop()
{
  
  Wire.beginTransmission(0x74); // transmit to device #4
  Test=Wire.write(0x06);
  Serial.print("Write adrress\n");
  Serial.print(Test,HEX);
  Serial.print("\n");
  delay(3000);
  Test=Wire.endTransmission();
  Serial.print("Wire Tranmission Status:");
  Serial.print(Test, HEX);
  Serial.print("\n");
  delay(3000);
 Test=Wire.requestFrom(0x74, 1);
 Serial.print("Requested FROM\n");
 Serial.print(Test,HEX);
 Serial.print("\n");
 delay(3000);
  
}

Any Idea why i always get a NACK?

Cabling, pull-ups, could be anything. Post a picture of your complete setup so that the whole wiring is visible.

I've managed to get it to work but part time, I'll explain:

When i power the MC on the sensor most of the time doesn't respond and the MC recognizes NACK.
Sometime when I short the sleep pin to 3.3V pin and then release it the devices starts responding, but not always.
Also if I connect the sleep leg to the GND, the sensor stops responding.

The most weird thing that wakes up the sensor most of the time is when I toggle the LED PIN, on and off (3.3 V -0V).
I really can’t understand this behavior , Is there something wrong with the sensor (and the board it’s on)?

Also when I got it to work and finally measured the color he is sensing the reading where unreasonable, meaning that when I projected red light he sensed the green the blue, maybe another indicator that the sensor is malfunctioning.

I guess there is a reason they stopped its manufacturing.

I repeat: Post a picture of your complete setup so that the whole wiring is visible.

For example: did you remove the internal pull-ups (RN1B, RN1C) the Mega unfortunately has? The UNO doesn't have such pull-ups, that's why connecting it directly to the UNO has no negative effect, while the Mega may even destroy the sensor if it really is supplied by 5V (the pull-ups on the board and the pull-ups on the Mega would give about 3.9V which is slightly above the maximum the chip tolerates. How did you power the Mega during the tests? USB is usually a bit lower than 5V which would move it to an acceptable value.
BTW: you should connect none of the pins (except 3V3) to 3.3V because the chip operates at 2.8V.

Hi

Here is are the picture of the circuit

Pinout:

SCL(21) → (orange) → SCL on sensor
SDA(20)->(RED) → SDA SENSOR
3.3V → (Green) → 3.3 Sensor
GND → Black → GND
GND → Yello → GND
Pin7 (PWM) → White → LED sensor - using analog out to configure 3.3[v] to led. ( Can disable it, same problem happens)

Can you please elaborate about the pullups you’ve mentioned?

i checked couple of time and the SCL and SDA putout 3.3 V, didn’t notice what you are claiming.

normaly i power the mega with the USB , and also tried external 12V supply, same result for both

2

Can you please elaborate about the pullups you’ve mentioned?

The Mega2560 and the Mega1280 have onboard I2C pullups (to 5V) installed (on the Mega2560 it’s a resistor array with 6 or 8 pins, while the Mega1280 has 3 separate resistors, placed on both directly besides the power LED). Because the sensor board has onboard pullups to 2.8V and both resistors are 10k, this should be a voltage divider resulting in about 3.9V, which theoretically is too much for the sensor (according to the datasheet). Maybe the breakout board is incompatible with the Mega series of Arduinos.

BTW: Your Arduino seems to be a clone of a Mega1280. Is that correct?

Now that you mention it it does looks like a clone.

I received it from our stock in the university , and didn't even think they might give a clone.
Is there any significant difference between the original and the clone?

Regarding the voltages , as soon as ill get access to a scope ill measure the voltage.
Your claim is that the voltage is too high and therefor the sensor is going crazy?

Is there any significant difference between the original and the clone?

That depends on who built the clone and if it was built with the original board layout or if there were changes. From the photo it looks like an almost exact clone so I would expect it to react like an original Mega (ATmega1280). I never used a Mega, my only experience in the Mega world is with a Mega2560.

Your claim is that the voltage is too high and therefor the sensor is going crazy?

I would expect it to be almost 4V but I don’t know how the sensor reacts on that. You might have damaged it already, maybe it just doesn’t work as long as the voltage is too high, I simply don’t know.