Pages: 1 [2]   Go Down
Author Topic: Problems with Wire.requestFrom (Arduiono Uno v1.0.3)  (Read 2127 times)
0 Members and 1 Guest are viewing this topic.
Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17293
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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();
}
 
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17293
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 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
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 480
Posts: 18722
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 480
Posts: 18722
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 480
Posts: 18722
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged


Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49071
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)


Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 74
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 480
Posts: 18722
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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;
}
Logged


Pages: 1 [2]   Go Up
Jump to: