Thank you all for the replies. First of all, here's the (first part of) the code I'm working on:
#include <Wire.h>
#define DEVICE (0x53) //ADXL345 device address
#define TO_READ (6) //num of bytes we are going to read each time (two bytes for each axis)
byte buff[TO_READ]; //6 bytes buffer for saving data read from the device
char str[512]; //string buffer to transform data before sending it to the serial port
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
//Turning on the ADXL345
writeTo(DEVICE, 0x2D, 0);
writeTo(DEVICE, 0x2D, 16);
writeTo(DEVICE, 0x2D, 8);
}
void loop()
{
int regAddress = 0x32; //first axis-acceleration-data register on the ADXL345
int x, y, z;
readFrom(DEVICE, regAddress, TO_READ, buff); //read the acceleration data from the ADXL345
//each axis reading comes in 10 bit resolution, ie 2 bytes. Least Significat Byte first!!
//thus we are converting both bytes in to one int
x = (((int)buff[1]) << 8) | buff[0];
y = (((int)buff[3])<< 8) | buff[2];
z = (((int)buff[5]) << 8) | buff[4];
//we send the x y z values as a string to the serial port
sprintf(str, "%d %d %d", x, y, z);
Serial.print(str);
Serial.print(10, BYTE);
//It appears that delay is needed in order not to clog the port
delay(50);
}
And the error message:
ADXL345_Example.cpp: In function 'void loop()':
ADXL345_Example.pde:-1: error: 'BYTE' was not declared in this scope
As of Arduino 1.0, the 'BYTE' keyword is no longer supported.
Please use Serial.write() instead.
ADXL345_Example.cpp: In function 'void writeTo(int, byte, byte)':
ADXL345_Example.pde:-1: error: 'class TwoWire' has no member named 'send'
As of Arduino 1.0, the Wire.send() function was renamed to Wire.write() for consistency with other libraries.
ADXL345_Example.pde:-1: error: 'class TwoWire' has no member named 'send'
As of Arduino 1.0, the Wire.send() function was renamed to Wire.write() for consistency with other libraries.
ADXL345_Example.cpp: In function 'void readFrom(int, byte, int, byte*)':
ADXL345_Example.pde:-1: error: 'class TwoWire' has no member named 'send'
As of Arduino 1.0, the Wire.send() function was renamed to Wire.write() for consistency with other libraries.
ADXL345_Example.pde:-1: error: 'class TwoWire' has no member named 'receive'
As of Arduino 1.0, the Wire.receive() function was renamed to Wire.read() for consistency with other libraries.
What I get out of it + your replies:
Probably, the error message does not relate to the code you're looking at.
Yes, than you! I can see now that the error relates to the Serial.print(10, BYTE) near the end of the code and not to the lower case byte at the beginning of the sketch.
no, BYTE (in caps) was a macro that was usually passed to the Serial.print commands to print an actual number rather than a character. If the compiler is warning you about byte (lowercase), ignore it. If it's error'ing you, post your code that doesn't compile. I've used byte (lowercase) many times in 1.0
thanks - this clears my doubt
It's always nice to post code, and the actual error message. Is this it?
It is not that, but thanks for the hint on posting (I hadn't seen the 'code posting' button, so didn't know how to correctly post code )
Although I'm not sure TO_READ is a good name for the number of bytes you are planning to write, but whatever.
As you can see in the code, the value of TO_READ was defined earlier, don't know if that's a valid argument though.
Thank you again!
Paolo