Go Down

Topic: Problems with Wire.requestFrom (Arduiono Uno v1.0.3) (Read 2668 times) previous topic - next topic

retrolefty

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

irethedo

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
*******************************************/

Code: [Select]
#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();
}

retrolefty

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

irethedo

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

Nick Gammon

Did you restart the IDE after installing the library? Did you install the library?
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Nick Gammon

I just downloaded his latest library, copied it to my libraries folder, restarted the IDE, opened the example, and compiled it, without errors.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

irethedo

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


Nick Gammon

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.

http://arduino.cc/en/Guide/Libraries
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

PaulS

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

irethedo


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


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)



irethedo


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...

Nick Gammon


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:

Code: [Select]

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;
}
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up