magnetometer HMC5883L with BBB

I am attempting to use a HMC5883L magnetometer. This is my first time using a BBB (or any single board computer) wondering if anyone has had success with this chips? I understood it was supposed to connect to 0x1E but it connected to 0x0D: i2cdetect -y -r 2
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: – – – – – 0d – –
10: – – – – – – – – – – – – – – – –
20: – – – – – – – – – – – – – – – –
30: – – – – – – – – – – – – – – – –
40: – – – – – – – – – – – – – – – –
50: – – – – – – – – – – – – – – – –
60: – – – – – – – – – – – – – – – –
70: – – – – – – – –
I could not get a signal so I tried finding out more: I tried the following: import smbus2

bus = smbus2.SMBus(2)
address = 0x0D # Replace with your device’s address

for reg in range(0x00, 0xFF):
try:
data = bus.read_byte_data(address, reg)
print(f"Reg: {reg:02x}, Data: {data:02x}“)
except Exception as e:
print(f"Reg: {reg:02x}, Error: {e}”)

and I got the following:
Reg: 00, Data: 00
Reg: 01, Data: 01
Reg: 02, Data: 00
Reg: 03, Data: 1f
Reg: 04, Error: [Errno 121] Remote I/O error
Reg: 05, Data: 00
Reg: 06, Data: 00
Reg: 07, Data: 00
Reg: 08, Data: 00
Reg: 09, Data: 00
Reg: 0a, Data: 00
Reg: 0b, Data: 1f
Reg: 0c, Data: 01
Reg: 0d, Data: ff
Reg: 0e, Data: 00
Reg: 0f, Data: 00
Reg: 10, Data: 00
Reg: 11, Data: 00
Reg: 12, Error: [Errno 121] Remote I/O error
Reg: 13, Data: 00
Reg: 14, Data: 00
Reg: 15, Data: 00
Reg: 16, Error: [Errno 121] Remote I/O error
Reg: 17, Error: [Errno 121] Remote I/O error
Reg: 18, Data: 00
Reg: 19, Data: 00
Reg: 1a, Data: 00
Reg: 1b, Data: 00
Reg: 1c, Error: [Errno 110] Connection timed out
Reg: 1d, Data: 00
Reg: 1e, Data: 00
Reg: 1f, Error: [Errno 11] Resource temporarily unavailable
Reg: 20, Error: [Errno 110] Connection timed out
Reg: 21, Error: [Errno 110] Connection timed out
Reg: 22, Error: [Errno 110] Connection timed out
Reg: 23, Error: [Errno 110] Connection timed out
Reg: 24, Error: [Errno 110] Connection timed out
Reg: 25, Error: [Errno 110] Connection timed out
Reg: 26, Error: [Errno 110] Connection timed out
Reg: 27, Error: [Errno 110] Connection timed out
Reg: 28, Error: [Errno 121] Remote I/O error
Reg: 29, Error: [Errno 121] Remote I/O error
Reg: 2a, Error: [Errno 121] Remote I/O error
Reg: 2b, Error: [Errno 121] Remote I/O error
Reg: 2c, Error: [Errno 121] Remote I/O error
Reg: 2d, Error: [Errno 121] Remote I/O error
Reg: 2e, Error: [Errno 121] Remote I/O error
Reg: 2f, Error: [Errno 121] Remote I/O error
Reg: 30, Error: [Errno 121] Remote I/O error
Reg: 31, Error: [Errno 121] Remote I/O error
Reg: 32, Error: [Errno 121] Remote I/O error
Reg: 33, Error: [Errno 121] Remote I/O error
Reg: 34, Error: [Errno 121] Remote I/O error
Reg: 35, Error: [Errno 110] Connection timed out
Reg: 36, Error: [Errno 121] Remote I/O error
Reg: 37, Error: [Errno 121] Remote I/O error
Reg: 38, Error: [Errno 121] Remote I/O error
Reg: 39, Error: [Errno 121] Remote I/O error
Reg: 3a, Error: [Errno 121] Remote I/O error
Reg: 3b, Error: [Errno 11] Resource temporarily unavailable
Reg: 3c, Error: [Errno 121] Remote I/O error
Reg: 3d, Error: [Errno 121] Remote I/O error
Reg: 3e, Error: [Errno 121] Remote I/O error
Reg: 3f, Error: [Errno 121] Remote I/O error
Reg: 40, Error: [Errno 121] Remote I/O error
Reg: 41, Error: [Errno 121] Remote I/O error
Reg: 42, Error: [Errno 11] Resource temporarily unavailable
Reg: 43, Error: [Errno 121] Remote I/O error
Reg: 44, Error: [Errno 121] Remote I/O error
Reg: 45, Error: [Errno 121] Remote I/O error
Reg: 46, Error: [Errno 121] Remote I/O error
Reg: 47, Error: [Errno 121] Remote I/O error
Reg: 48, Error: [Errno 121] Remote I/O error
Reg: 49, Error: [Errno 121] Remote I/O error
Reg: 4a, Error: [Errno 121] Remote I/O error
Reg: 4b, Error: [Errno 121] Remote I/O error
Reg: 4c, Error: [Errno 121] Remote I/O error
Reg: 4d, Error: [Errno 121] Remote I/O error
Reg: 4e, Error: [Errno 121] Remote I/O error
Reg: 4f, Error: [Errno 121] Remote I/O error
Reg: 50, Error: [Errno 121] Remote I/O error
Reg: 51, Error: [Errno 121] Remote I/O error
Reg: 52, Error: [Errno 110] Connection timed out
Reg: 53, Error: [Errno 121] Remote I/O error
Reg: 54, Error: [Errno 11] Resource temporarily unavailable
Reg: 55, Error: [Errno 121] Remote I/O error
Reg: 56, Error: [Errno 121] Remote I/O error
Reg: 57, Error: [Errno 11] Resource temporarily unavailable
Reg: 58, Error: [Errno 121] Remote I/O error
Reg: 59, Error: [Errno 121] Remote I/O error
Reg: 5a, Error: [Errno 121] Remote I/O error
Reg: 5b, Error: [Errno 121] Remote I/O error
Reg: 5c, Error: [Errno 121] Remote I/O error
Reg: 5d, Error: [Errno 11] Resource temporarily unavailable
Reg: 5e, Error: [Errno 121] Remote I/O error
Reg: 5f, Error: [Errno 11] Resource temporarily unavailable
Reg: 60, Error: [Errno 121] Remote I/O error
Reg: 61, Error: [Errno 121] Remote I/O error
Reg: 62, Error: [Errno 121] Remote I/O error
Reg: 63, Error: [Errno 121] Remote I/O error
Reg: 64, Error: [Errno 121] Remote I/O error
Reg: 65, Error: [Errno 110] Connection timed out
Reg: 66, Error: [Errno 121] Remote I/O error
Reg: 67, Error: [Errno 121] Remote I/O error
Reg: 68, Error: [Errno 121] Remote I/O error
Reg: 69, Error: [Errno 11] Resource temporarily unavailable
Reg: 6a, Error: [Errno 121] Remote I/O error
Reg: 6b, Error: [Errno 121] Remote I/O error
Reg: 6c, Error: [Errno 121] Remote I/O error
Reg: 6d, Error: [Errno 121] Remote I/O error
Reg: 6e, Error: [Errno 121] Remote I/O error
Reg: 6f, Error: [Errno 121] Remote I/O error
Reg: 70, Error: [Errno 121] Remote I/O error
Reg: 71, Error: [Errno 121] Remote I/O error
Reg: 72, Error: [Errno 121] Remote I/O error
Reg: 73, Error: [Errno 121] Remote I/O error
Reg: 74, Error: [Errno 11] Resource temporarily unavailable
Reg: 75, Error: [Errno 121] Remote I/O error
Reg: 76, Error: [Errno 121] Remote I/O error
Reg: 77, Error: [Errno 121] Remote I/O error
Reg: 78, Error: [Errno 121] Remote I/O error
Reg: 79, Error: [Errno 121] Remote I/O error
Reg: 7a, Error: [Errno 121] Remote I/O error
Reg: 7b, Error: [Errno 121] Remote I/O error
Reg: 7c, Error: [Errno 121] Remote I/O error
Reg: 7d, Error: [Errno 121] Remote I/O error
Reg: 7e, Error: [Errno 11] Resource temporarily unavailable
Reg: 7f, Error: [Errno 121] Remote I/O error
Reg: 80, Error: [Errno 121] Remote I/O error
Reg: 81, Error: [Errno 121] Remote I/O error
Reg: 82, Error: [Errno 121] Remote I/O error
Reg: 83, Error: [Errno 110] Connection timed out
Reg: 84, Error: [Errno 121] Remote I/O error
Reg: 85, Error: [Errno 121] Remote I/O error
Reg: 86, Error: [Errno 121] Remote I/O error
Reg: 87, Error: [Errno 121] Remote I/O error
Reg: 88, Error: [Errno 121] Remote I/O error
Reg: 89, Error: [Errno 121] Remote I/O error
Reg: 8a, Error: [Errno 121] Remote I/O error
Reg: 8b, Error: [Errno 121] Remote I/O error
Reg: 8c, Error: [Errno 121] Remote I/O error
Reg: 8d, Error: [Errno 121] Remote I/O error
Reg: 8e, Error: [Errno 121] Remote I/O error
Reg: 8f, Error: [Errno 121] Remote I/O error
Reg: 90, Error: [Errno 121] Remote I/O error
Reg: 91, Error: [Errno 121] Remote I/O error
Reg: 92, Error: [Errno 121] Remote I/O error
Reg: 93, Error: [Errno 121] Remote I/O error
Reg: 94, Error: [Errno 121] Remote I/O error
Reg: 95, Error: [Errno 121] Remote I/O error
Reg: 96, Error: [Errno 121] Remote I/O error
Reg: 97, Error: [Errno 121] Remote I/O error
Reg: 98, Error: [Errno 110] Connection timed out
Reg: 99, Error: [Errno 11] Resource temporarily unavailable
Reg: 9a, Error: [Errno 121] Remote I/O error
Reg: 9b, Error: [Errno 121] Remote I/O error
Reg: 9c, Error: [Errno 121] Remote I/O error
Reg: 9d, Error: [Errno 121] Remote I/O error
Reg: 9e, Error: [Errno 121] Remote I/O error
Reg: 9f, Error: [Errno 121] Remote I/O error
Reg: a0, Error: [Errno 121] Remote I/O error
Reg: a1, Error: [Errno 121] Remote I/O error
Reg: a2, Error: [Errno 121] Remote I/O error
Reg: a3, Error: [Errno 11] Resource temporarily unavailable
Reg: a4, Error: [Errno 121] Remote I/O error
Reg: a5, Error: [Errno 121] Remote I/O error
Reg: a6, Error: [Errno 121] Remote I/O error
Reg: a7, Error: [Errno 121] Remote I/O error
Reg: a8, Error: [Errno 121] Remote I/O error
Reg: a9, Error: [Errno 121] Remote I/O error
Reg: aa, Error: [Errno 121] Remote I/O error
Reg: ab, Error: [Errno 121] Remote I/O error
Reg: ac, Error: [Errno 121] Remote I/O error
Reg: ad, Error: [Errno 11] Resource temporarily unavailable
Reg: ae, Error: [Errno 121] Remote I/O error
Reg: af, Error: [Errno 121] Remote I/O error
Reg: b0, Error: [Errno 121] Remote I/O error
Reg: b1, Error: [Errno 121] Remote I/O error
Reg: b2, Error: [Errno 121] Remote I/O error
Reg: b3, Error: [Errno 121] Remote I/O error
Reg: b4, Error: [Errno 121] Remote I/O error
Reg: b5, Error: [Errno 121] Remote I/O error
Reg: b6, Error: [Errno 121] Remote I/O error
Reg: b7, Error: [Errno 11] Resource temporarily unavailable
Reg: b8, Error: [Errno 121] Remote I/O error
Reg: b9, Error: [Errno 121] Remote I/O error
Reg: ba, Error: [Errno 121] Remote I/O error
Reg: bb, Error: [Errno 121] Remote I/O error
Reg: bc, Error: [Errno 121] Remote I/O error
Reg: bd, Error: [Errno 110] Connection timed out
Reg: be, Error: [Errno 121] Remote I/O error
Reg: bf, Error: [Errno 121] Remote I/O error
Reg: c0, Error: [Errno 121] Remote I/O error
Reg: c1, Error: [Errno 121] Remote I/O error
Reg: c2, Error: [Errno 121] Remote I/O error
Reg: c3, Error: [Errno 121] Remote I/O error
Reg: c4, Error: [Errno 121] Remote I/O error
Reg: c5, Error: [Errno 121] Remote I/O error
Reg: c6, Error: [Errno 11] Resource temporarily unavailable
Reg: c7, Error: [Errno 121] Remote I/O error
Reg: c8, Data: ff
Reg: c9, Error: [Errno 121] Remote I/O error
Reg: ca, Error: [Errno 121] Remote I/O error
Reg: cb, Error: [Errno 121] Remote I/O error
Reg: cc, Error: [Errno 121] Remote I/O error
Reg: cd, Error: [Errno 121] Remote I/O error
Reg: ce, Error: [Errno 121] Remote I/O error
Reg: cf, Error: [Errno 121] Remote I/O error
Reg: d0, Error: [Errno 121] Remote I/O error
Reg: d1, Error: [Errno 121] Remote I/O error
Reg: d2, Error: [Errno 121] Remote I/O error
Reg: d3, Error: [Errno 121] Remote I/O error
Reg: d4, Error: [Errno 11] Resource temporarily unavailable
Reg: d5, Error: [Errno 11] Resource temporarily unavailable
Reg: d6, Error: [Errno 121] Remote I/O error
Reg: d7, Error: [Errno 121] Remote I/O error
Reg: d8, Error: [Errno 121] Remote I/O error
Reg: d9, Error: [Errno 121] Remote I/O error
Reg: da, Error: [Errno 121] Remote I/O error
Reg: db, Error: [Errno 121] Remote I/O error
Reg: dc, Error: [Errno 121] Remote I/O error
Reg: dd, Error: [Errno 121] Remote I/O error
Reg: de, Error: [Errno 121] Remote I/O error
Reg: df, Error: [Errno 121] Remote I/O error
Reg: e0, Error: [Errno 121] Remote I/O error
Reg: e1, Error: [Errno 11] Resource temporarily unavailable
Reg: e2, Error: [Errno 121] Remote I/O error
Reg: e3, Error: [Errno 121] Remote I/O error
Reg: e4, Error: [Errno 121] Remote I/O error
Reg: e5, Error: [Errno 121] Remote I/O error
Reg: e6, Error: [Errno 121] Remote I/O error
Reg: e7, Error: [Errno 121] Remote I/O error
Reg: e8, Error: [Errno 121] Remote I/O error
Reg: e9, Error: [Errno 121] Remote I/O error
Reg: ea, Error: [Errno 121] Remote I/O error
Reg: eb, Error: [Errno 121] Remote I/O error
Reg: ec, Error: [Errno 121] Remote I/O error
Reg: ed, Error: [Errno 121] Remote I/O error
Reg: ee, Error: [Errno 121] Remote I/O error
Reg: ef, Error: [Errno 121] Remote I/O error
Reg: f0, Error: [Errno 121] Remote I/O error
Reg: f1, Error: [Errno 121] Remote I/O error
Reg: f2, Error: [Errno 121] Remote I/O error
Reg: f3, Error: [Errno 121] Remote I/O error
Reg: f4, Error: [Errno 121] Remote I/O error
Reg: f5, Error: [Errno 11] Resource temporarily unavailable
Reg: f6, Error: [Errno 121] Remote I/O error
Reg: f7, Error: [Errno 121] Remote I/O error
Reg: f8, Error: [Errno 121] Remote I/O error
Reg: f9, Error: [Errno 121] Remote I/O error
Reg: fa, Error: [Errno 11] Resource temporarily unavailable
Reg: fb, Error: [Errno 121] Remote I/O error
Reg: fc, Error: [Errno 121] Remote I/O error
Reg: fd, Error: [Errno 121] Remote I/O error
Reg: fe, Error: [Errno 11] Resource temporarily unavailable

Aplogies, I don’t have the knowledge to understand if something is wrong with my BBB or the chip or if, perhaps, I have a clone chip that needs to be configured differently.
Thanks

1 Like

Hello,

Depending on your i2c address, /dev/bone/i2c/*, it may help to know which bus you are using and what file location is the actual location.

I have noticed some things change in time. File locations have changed depending on your image and kernel. Are you building your own image or are you using a beagleboard.org image?

Please give the output of the below commands so I or others can help a bit more…

uname -a

and…

cat /etc/dogtag

Seth

Yes looking at the datasheet the address is 0x1E. It can’t be changed, so something at 0x0D is not your HMC5883L.

What is the HMC5883L board you are using ?
How is it connected to the BBB ?

Most BBB capes have an eeprom on them to identify the cape. It is possible that is what you are seeing at 0x0D. If you are using a cape and it has an eeprom, assuming the HMC5883L is also using the same I2C bus, then it should be there.

Not really sure how i2cdetect works, but I have seen it fail to detect some I2C devices. Reading the MAN pages even says that both its detection methods are not recommended !

Have you tried writing a simple program to just read the CRA register from 0x1E?

Thanks - these are the outputs for the commands.

debian@BeagleBone:~$ uname -a
Linux BeagleBone 5.10.168-ti-r71 #1bullseye SMP PREEMPT Fri Sep 1 04:05:07 UTC 2023 armv7l GNU/Linux
debian@BeagleBone:~$ cat /etc/dogtag
BeagleBoard.org Debian Bullseye IoT Image 2023-09-02

[code]import smbus
import time

The HMC5883L has a fixed I2C address

HMC5883L_ADDRESS = 0x1E

Register address

CRA_REG = 0x00

Initialize the I2C bus

bus = smbus.SMBus(2)

Read data from the Configuration Register A

def read_cra():
try:
# Read one byte from the specified register
value = bus.read_byte_data(HMC5883L_ADDRESS, CRA_REG)
return value
except Exception as e:
print(f"Error reading from I2C device: {e}")
return None

Main program logic

if name == “main”:
# Read CRA register
cra_value = read_cra()
if cra_value is not None:
print(f"Configuration Register A: 0x{cra_value:02X}")
else:
print(“Failed to read from device.”)
[/code]
my results are:
[list]
[] Error reading from I2C device: [Errno 121] Remote I/O error
[
] Failed to read from device.
[/list]

OK, so what hardware are you using ? and how is it connected to the BBB ?

Have you got a serial console cable ? If so what is the output from u-boot ? Is it loading an I2C overlay ?

Are you running your test program as root ? Not sure what group the I2C devices are in.

@CJD
depending where you got this module from, it may not be the part you think,
i bought some off of amazxxxx and got a qmc5883 part and not the HMC5883 that they advertised on their site.
the qmc5883 part has a 0x0D I2C address,
I have not found a driver for the qmc5883 version, but there is some C-code out there for testing the part.
googy for qmc5883_i2c.c
this link may be the C-code i was thinking of

there is also some python code here, it’s being run on a Raspberry, but i think it can be ported to BBB.

https://www.raspberrypi.org/forums/viewtopic.php?t=224769

Hello @CJD ,

@benedict.hewson seems to know more than I. I say go w/ his recommendations.

Seth

P.S. There are many ideas circulating right now around the newer boards but some of your files may be located where I stated earlier. I think?

Thank you for these questions.
I have a BB Black Rev C3 and I mounted to it a CZH-LABS Screw Terminal Block Breakout Board Module for BeagleBone Black.
I have connected the P9_19 to SCL the P9_20 to the SDA the P9_15 to the DRDY and the power and ground to a 3.3 V external power supply. The chip is in a BreadBoard and I used wires to connect the BB Black to the chip.
I have the ethernet cable plugged into my router for internet access.
I do not have a serial console cable but if it is needed I believe I could get one.
I plugged a usb cable into the micro usb port and I communicate via terminal and ssh. I use nano for python code execution or terminal commands. If I did not answer the questions please let me know. I appreciate the help.

Ok, have you added pull-up resistors to the I2C lines ?

Hi @benedict.hewson I did not add pull-up resistors I thought they were added to the magnetometer circuit board. I also found via troubleshooting that I got QMC chips not HMC.

Thanks, yes it is QMC chip even though the writing is HMC. I got a signal from it using Arduino but the signal never reacted to magnetic fields. After further analysis I tried an Arduino code compatible with QMC and it works. I still don’t know how to get it working with BB Black. I might need to alter my original expectations and change hardware.

1 Like

if it works on the arduino, should just work in BB as well. I2C is I2C. Now you know it is the QMC chip, you will need to have a look at the datasheet. You can also inspect the Arduino code and see what it is doing for comparison

1 Like

here is my BBB test code,
just compile this on the BBB

/*
 ============================================================================
 Name        : qmc5883_i2c.c
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
#include <unistd.h>

/* just hard code for now, */

#define I2C_ADDR	0x0D
#define I2C_BUS		"/dev/i2c-2"



int i2c_open(uint8_t bus) {

  int handle;

  if((handle = open(I2C_BUS, O_RDWR)) < 0) return handle;
  //if(!check_i2c_functionality(handle)) return -1;
  return handle;
}

int i2c_close(int handle) {
  return close(handle);
}

int main(void) {

	int i2c_handle = i2c_open(2);
	char dataBuffer[0x0F];
	printf("%s, %X\n", I2C_BUS, 0x0D);
	if (ioctl(i2c_handle, I2C_SLAVE, I2C_ADDR) < 0){
			printf("I2C_SLAVE address %i failed ...", I2C_ADDR);
			return(2);
	}

	/* part is in standby after POR */
    char buf[1] = { 0x09 };
    if(write(i2c_handle, buf, 1) !=1){
    	printf("Failed to Reset Address in readFullSensorState()");
    }

    buf[0] =  0x01 ;	// set to continous
    if(write(i2c_handle, buf, 1) !=1){
    	printf("Failed to Reset Address in readFullSensorState()");
    }

    int j= 0;
	for (j =0;j< 100;j++)
	{
		char buf[1] = { 0x00 };
		if(write(i2c_handle, buf, 1) !=1){
		printf("Failed to Reset Address in readFullSensorState()");
		}

		// read X data 10 times, should be simular each time
		int bytesRead = read(i2c_handle, dataBuffer, 6);
		if (bytesRead == -1){
			printf("Failure to read Byte Stream in readFullSensorState()");
		}
		else
		{
			//printf("X LSB: 0x%x\n", dataBuffer[0]);
			//printf("X MSB: 0x%x\n", dataBuffer[1]);
	#if (0)
			printf("X: 0x%X, %i\n", ((int)dataBuffer[1] << 8)+ (int)dataBuffer[0],((int)dataBuffer[1] << 8)+ (int)dataBuffer[0]);
			printf("Y: 0x%X, %i\n", ((int)dataBuffer[3] << 8)+ (int)dataBuffer[2],((int)dataBuffer[3] << 8)+ (int)dataBuffer[2]);
			printf("Z: 0x%X, %i\n", ((int)dataBuffer[5] << 8)+ (int)dataBuffer[4],((int)dataBuffer[5] << 8)+ (int)dataBuffer[4]);
	#endif
			printf("X: %i, ", ((int)dataBuffer[1] << 8)+ (int)dataBuffer[0]);
			printf("Y: %i, ", ((int)dataBuffer[3] << 8)+ (int)dataBuffer[2]);
			printf("Z: %i\n", ((int)dataBuffer[5] << 8)+ (int)dataBuffer[4]);
			sleep(1);
		}
	}

#if (0)
    int j= 0;
    for (j =0;j< 10;j++)
    {
        char buf[1] = { 0x00 };
        if(write(i2c_handle, buf, 1) !=1){
        	printf("Failed to Reset Address in readFullSensorState()");
        }
        // read X data 10 times, should be simular each time
        int bytesRead = read(i2c_handle, dataBuffer, 2);
		if (bytesRead == -1){
			printf("Failure to read Byte Stream in readFullSensorState()");
		}
		else
		{
			//printf("X LSB: 0x%x\n", dataBuffer[0]);
			//printf("X MSB: 0x%x\n", dataBuffer[1]);
			printf("X: 0x%X, %i\n", ((int)dataBuffer[1] << 8)+ (int)dataBuffer[0],((int)dataBuffer[1] << 8)+ (int)dataBuffer[0]);
		}
    }
    for (j =0;j< 10;j++)
    {
        char buf[1] = { 0x02 };
        if(write(i2c_handle, buf, 1) !=1){
        	printf("Failed to Reset Address in readFullSensorState()");
        }
        // read X data 10 times, should be simular each time
        int bytesRead = read(i2c_handle, dataBuffer, 2);
		if (bytesRead == -1){
			printf("Failure to read Byte Stream in readFullSensorState()");
		}
		else
		{
			//printf("Y LSB: 0x%x\n", dataBuffer[0]);
			//printf("Y MSB: 0x%x\n", dataBuffer[1]);
			printf("Y: 0x%X, %i\n", ((int)dataBuffer[1] << 8)+ (int)dataBuffer[0],((int)dataBuffer[1] << 8)+ (int)dataBuffer[0]);
		}
    }
    for (j =0;j< 10;j++)
    {
        char buf[1] = { 0x04 };
        if(write(i2c_handle, buf, 1) !=1){
        	printf("Failed to Reset Address in readFullSensorState()");
        }
        // read X data 10 times, should be simular each time
        int bytesRead = read(i2c_handle, dataBuffer, 2);
		if (bytesRead == -1){
			printf("Failure to read Byte Stream in readFullSensorState()");
		}
		else
		{
			//printf("X LSB: 0x%x\n", dataBuffer[0]);
			//printf("X MSB: 0x%x\n", dataBuffer[1]);
			printf("z: 0x%X, %i\n", ((int)dataBuffer[1] << 8)+ (int)dataBuffer[0],((int)dataBuffer[1] << 8)+ (int)dataBuffer[0]);
		}
    }
#endif
#if (0)
    buf[0] =  0x00 ;
    if(write(i2c_handle, buf, 1) !=1){
    	printf("Failed to Reset Address in readFullSensorState()");
    }

    int bytesRead = read(i2c_handle, dataBuffer, 0x0B);
    if (bytesRead == -1){
    	printf("Failure to read Byte Stream in readFullSensorState()");
    }
    else
    {
    	int i;
    	for(i = 0; i < 0x0B; i++)
    		printf("%i: 0x%x\n", i, dataBuffer[i]);
    }
#endif
	i2c_close(i2c_handle);

	return EXIT_SUCCESS;
}

Thank you. I will let you know how it works as soon I get a chance to return to this project.
I really appreciate this help.

1 Like