Problems with Wire.requestFrom (Arduiono Uno v1.0.3)

I'm getting confused now. Can you please run the I2C scanner and post what it returns?

There are no links to datasheets for these items as these devices are custom and company
confidential information.

Can someone send me a link to the Wire commands in v1.0.3?

If I could ask the same question in an easier way, it might go like this:

The problem seems to be when I try to write to I2C address 44h with the following code
which shuts the power off to the device that i am attempting to communicate or get a
status if whether it is connected or not and the data returned from Wire.endTransmission()
(and all the code from that point to the end of my loop closing bracket) is ignored...

Is there some sort of error handling going on behind the scenes that is causing a break
statement (of sorts) in my loop?

I need more information on the v 1.0.3 Wire library I think.

Please see comments in the code below

// ------------ turn off ext power ------------------
Wire.beginTransmission(0x22); // write to I2c Address 44h to set power condition
// Wire.beginTransmission(0x44); // (Use address in line above) because this one DOES NOT WORK
Wire.write(0xFA); // write command to turn off power
// ***** power does turn off here with the command in the line above as expected ***********
timeout = Wire.endTransmission(); // Check status of data sent- did it get there?
delay(4500);
Serial.print(" Power IS OFF- timeout= "); // This time out is not being displayed in Serial monitor .. Why is that?
Serial.print(timeout); // and all the code through the end of my loop end bracket is also ignored

Hmmm - you are turning the device's power off? No wonder it doesn't respond. :slight_smile:

There is another version of the Wire library that handles lack of response better. There is a link to it on my I2C page.

Thanks Nic-

I just saw your scanner and here is my output

I2C scanner. Scanning ...
Found address: 33 (0x21)
Found address: 34 (0x22)
Found address: 35 (0x23)
Done.
Found 3 device(s).

I will take a llok at your I2C page

thanks

Nick-

Please send a link to the Wire library on your site

thanks

It's not mine, but here is the link:

Thanks for the link.

I am attempting to switch my code over to use this I2c.h library but I keep getting an error with the following:

I2c.begin(); gives me this error: 'I2c' was not declared in this scope

in my code I have included the file included:
#include <I2C.h> and in both the v1.0.3 IDE and v1.0.1 IDE
I have also tried adding I2c.h & I2c.cpp but still I get this error.

This was done after I placed I2C folders (which contain I2c.h & I2c.cpp) into \my documents\Aduino-1.0.1\libraries
and \my documents\Aduino-1.0.3\libraries folders.

I see an import library option in the sketch pull down menu but the I2c library does not exist in the list nad there does not appear to be a way to browse for it either...

Any ideas what i am missing or doing wrong?

thanks

Just a guess but:

I2C.h and I2c.begin(); seem to be using mixed case characters and C/C++ is case sensitive?

Try I2C.begin();
Lefty

Thanks...
I tried changing the case the I2c.begin() to I2C.begin() and the error for the same line of code
changes to request for member 'begin' in 'I2C', which is of non-class 'int'

What gives?

I copied the sample code that was on the library link page and it does the same thing:
/*******************************************
Sample sketch that configures an HMC5883L 3 axis
magnetometer to continuous mode and reads back
the three axis of data.
Code compiles to a size of 1500 bytes
Equivalent Wire Library code compiles to 2032 bytes
*******************************************/

#include <I2C.h>

#define HMC5883L  0x1E 

int x = 0;
int y = 0;
int z = 0;


void setup()
{
  I2c.begin();
  I2c.write(HMC5883L,0x02,0x00); //configure device for continuous mode
}

void loop()
{
  I2c.read(HMC5883L,0x03,6); //read 6 bytes (x,y,z) from the device
  x = I2c.receive() << 8;
  x |= I2c.receive();
  y = I2c.receive() << 8;
  y |= I2c.receive();
  z = I2c.receive() << 8;
  z |= I2c.receive(); 
}

I can't really help you. All my sketches that use I2C stuff use the #include <Wire.h> I2C library that comes standard with the Arduino distribution.

Lefty

I would still be using Wire.h also if it wasn't locking up my sketch...

Did you restart the IDE after installing the library? Did you install the library?

I just downloaded his latest library, copied it to my libraries folder, restarted the IDE, opened the example, and compiled it, without errors.

Where did you store the files and did you need to do anything else to link the I2C.h file?

I keep getting this 'I2c' was not declared in this scope error
on the I2c.begin() line of code

Inside I2C_Rev5.zip is a folder, "I2C".

Copy that to the "libraries" folder which is under where your sketches folder is (the whole folder, not just its contents).

Restart the IDE.

Then it should work.

And, you've been told that it is I2C, not I2c. Don't come back until you fix that.

Thanks Nick!

I thought that I did restart the IDE but I had another instance of it running in the background.

I closed all instances of the IDE and then stated up one instance of it and then I was able to import the library.

I like your scan utility and would like to incorporate that into checking for the device
before reading it but not sure how to convert it over to the I2C.h library functions for the following:

Wire.beginTransmission (i);
if (Wire.endTransmission () == 0)

PaulS:
And, you've been told that it is I2C, not I2c. Don't come back until you fix that.

Fix I2c Again???
Wasn't the problem... I2c is correct and as I posted prior to your reply, that is the way that is was in the sample code that came with the library.

I later found out (thanks to Nick's post) that the sample code did not work for me because I hadn't restarted the IDE and loaded the library...

but thanks all the same...

irethedo:
I like your scan utility and would like to incorporate that into checking for the device
before reading it but not sure how to convert it over to the I2C.h library functions for the following:

Looking at the source, the library has a scan function. Look at how that does it:

void I2C::scan()
{
  uint16_t tempTime = timeOutDelay;
  timeOut(80);
  uint8_t totalDevicesFound = 0;
  Serial.println("Scanning for devices...please wait");
  Serial.println();
  for(uint8_t s = 0; s <= 0x7F; s++)
  {
    returnStatus = 0;
    returnStatus = start();
    if(!returnStatus)
    { 
      returnStatus = sendAddress(SLA_W(s));
    }
    if(returnStatus)
    {
      if(returnStatus == 1)
      {
        Serial.println("There is a problem with the bus, could not complete scan");
        timeOutDelay = tempTime;
        return;
      }
    }
    else
    {
      Serial.print("Found device at address - ");
      Serial.print(" 0x");
      Serial.println(s,HEX);
      totalDevicesFound++;
    }
    stop();
  }
  if(!totalDevicesFound){Serial.println("No devices found");}
  timeOutDelay = tempTime;
}