Thanks Tyler for your response, unfortunately it did not help.
The data registers (acc) are still zero.
I also tried this to read the deviceId:
success = ps.twi_.writeRead(0x1E, false, new byte[]{ 0x3C, 0x0A}, 2, acc,3);
//trying to read deviceId from register 10
and get 3 zeros. I would expect some nonzero value.
If I initialize acc byte array with something else before calling writeRead the
IOIO writeRead reads zeros.
Could it be that the sensor is damaged ?
If I unplug the power 3.3v from the sensor, I get zeros. The same thing if I
remove the pull-au resistors.
But if I unplug SDA or SCL, writeRead returns false (otherwise true).
How could I verify that sensor works ? Can I "factory reset" it ?
torstai 15. lokakuuta 2015 20.41.26 UTC+3 Tyler kirjoitti:
>
> Hello,
>
>
> Tryout the code changes below.
>
>
> ...
> ps.twi_.writeRead(0x1E, false, new byte[]{0x3C,0x02,0x01}, 2, acc, 6); //
> Remove this line (it's set by default)
> ps.twi_.writeRead(0x1E, false, new byte[]{0x3C,0x03}, 2, acc, 6); // Use
> this line
> ps.twi_.writeRead(0x1E, false, new byte[]{0x3D,0x06}, 2, acc, 6); // Delete
> this line
> ...
>
>
> As I understand the IOIO's implementation of I2C, one writeRead() is
> sufficient to perform a read, and a write operation to a single slave device
> on the I2C bus. By sending the above, you are requesting to read from
> register 0x03. Simply specifying a byte[] and a length is sufficient for
> writeRead() to automatically wait for a response from the slave and put the
> reply into the byte[] (acc).
>
>
> Your first writeRead() is unnesessary because single read mode is set by
> default on the HMC5883L.
>
> Your second writeRead() is about right. Modify as above.
>
> Your third writeRead() attempt looks close, but based on what I read, that
> tells the slave that you would like to *write* to register 0x06.
>
>
> Hopefully that all makes sense,
>
> Tyler
>
>
> On Thursday, October 15, 2015 at 4:52:38 AM UTC-7, [email protected]
> wrote:
>>
>> Hi !
>> I am trying to use HMC5883L magnetometer sensor like in thread:
>>
>> https://groups.google.com/forum/#!msg/ioio-users/V6riKrVsZnQ/JcEHz_u_an4J
>>
>> I have connected SDA and SCL to IOIO pins 4,5 and power to IOIO 3.3V. I
>> also have two 10kOhm pull-up resistors connected between IOIO 3.3v and
>> SDA,SCL pins, double checked that wiring is ok.
>>
>> Then in my IOIO setup TWI0 is opened, like this:
>>
>> ps.twi_ = ioio_.openTwiMaster(0, TwiMaster.Rate.RATE_400KHz, false);
>>
>> in my IOIO loop:
>>
>> Boolean success;
>> byte [] acc = new byte [6];
>> success = ps.twi_.writeRead(0x1E, false, new byte[]{0x3C,0x02,0x01}, 2,
>> acc,0); // single measurement mode
>> success = ps.twi_.writeRead(0x1E, false, new byte[]{0x3C,0x03}, 2, acc, 0);
>> //register pointer to 03
>> success = ps.twi_.writeRead(0x1E, false, new byte[]{0x3D,0x06}, 2, acc, 6);
>> // read 6 registers
>>
>> if (success) {
>> int dataX = (acc[0]) + ((acc[1]) << 8);
>> int dataY = (acc[2]) + ((acc[3]) << 8);
>> int dataZ = (acc[4]) + ((acc[5]) << 8);
>> DisplayInfo(260, null, null, "X:" + String.valueOf(dataX) + " Y:" +
>> String.valueOf(dataY) + " Z:" + String.valueOf(dataZ));
>> }
>>
>> This info taken from the datasheet:
>> http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/Magneto/HMC5883L-FDS.pdf
>> The problem is that data registers acc always have 6 zeros (0). So no data
>> is never read.
>> What I am doing wrong here, have tried to find a working example using IOIO,
>> but all seems to be with Arduino.
>> I have tried to use continous measure and single read mode, with no success.
>> writeRead always returns success=true, but no data.
>> Can anybody help me, thanks !
>> Is there anywhere documentation, what the parameters in writeRead really
>> mean ? Especially the lengths, is the first number of bytes to write, and
>> the last length:
>> number of bytes will be read
>>
>>
>>
>>
--
You received this message because you are subscribed to the Google Groups
"ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/d/optout.