Writing to Devantech digital compass over I2C
I am trying to interface with a Devantech digital compass found here -
Devantech Compass
I am using a i2c-usb converter to plug it into my laptop -
USB-I2C Communications Module
First of all, I do not know much about electrical engineering. I have a good idea of the bare basics, but after that I get lost.
I am trying to follow this tutorial -
https://xgoat.com/wp/2007/11/11/usin...pace-in-linux/
The problem is that I cannot write to the device.
The code right now is -
Code:
#define ADDRESS 0x55
int fd = open("/dev/i2c-0", O_RDWR);
if (fd < 0) {
printf("\n<0, %m", errno);
return -1;
}
if( ioctl( fd, I2C_SLAVE, ADDRESS ) < 0 ) {
fprintf( stderr, "Failed to set slave address: %m\n" );
return 2;
}
if( i2c_smbus_write_byte( fd, 0xAA ) < 0 )
fprintf( stderr, "Failed to write 0xAA to I2C device: %m\n" );
Whenever I run the code, it just returns
"Failed to write 0xAA to I2C device: No such device or address"
I just have the compass connected to the usb converter, which is connected to my pc using Debian.
I had the address at 0xC0 at first, but that would not work. I used that because in the compass manual it says the module address is 0xC0. I changed it 0x55 because on the converter website, there is a box with commands and I thought 0x55 fit best. I'm not sure if that is correct or not, but it got me past the first step of setting the address. If I'm doing that wrong, please let me know.
I didn't choose 0xAA for any specific reason - I am just trying to write anything.
I don't understand why there is no device found. Is it something to do with the address being set wrong? If anyone has any ideas, I would be very grateful.