LSM303AGR / micro:bit V1.5 Error: 'restart-i2c' not an i2c stream


#1

Hi,

I hope you are doing well. I am newbie with ulisp + lisp and micro:bit

I was testing ulisp on micro:bit V1.5 (I understand it includes Magno/Accelo = LSM303AGR)

Here is my environment:

|Description:|Ubuntu 18.04.5 LTS
|Release:|18.04|
|Codename:|bionic|

Arduino 1.8.13

uLisp ARM 3.3a

After creating the routines:

lsm303d-init
lsm303d-read-magnetic
lsm303d-whoami

According to the example provided in: http://library.ulisp.com/show?2VJM

I got the following:

607> (lsm303d-init)
$d&

607> (lsm303d-read-magnetic)

Error: ‘restart-i2c’ not an i2c stream

607> (lsm303d-whoami)

Error: ‘restart-i2c’ not an i2c stream

I am able to test basic lisp functions as per http://www.ulisp.com/show?2672

Best Regards,
And thanks a lot for this project!


#3

The error you’re getting suggests that you’ve got the wrong I2C address. I haven’t got a Version 1.5 Micro:bit to test, but I believe the I2C addresses of the sensor are different from the example in the uLisp library; from the datasheet:

The accelerometer sensor slave address is 0011001b while magnetic sensor slave address is 0011110b.

Run the uLisp I2C Scan program to find out what the I2C addresses are on the bus.


#4

Hello,

Thanks a lot for your feedback. After executing the [http://library.ulisp.com/show?2T8R](http://I2C Port Scanner Function) I got:

1038> (scn)

25
30
nil

However it is not clear which number is associated to which sensor.

So I updated the functions with 25 (assuming hex conversion to: #x19) and it appears to be working here are the results:

833> (lsm303d-init )
nil

833> (lsm303d-read-magnetic)
0 0 0
0

959> (lsm303d-whoami)
51

This last value didn’t match the expected 73 for an LSM303D.

Also when using the value 30 (#x1e) I got the following results:

833> (lsm303d-init )
nil

833> (lsm303d-read-magnetic)
0 0 0
0

833> (lsm303d-whoami)
0

Best Regards


#5

25 (#x19) is the address of the accelerometer
30 (#x1E) is the address of the magnetometer

The Who Am I value of 51 (#x33) is correct for the LSM303AGR; see page 46 of the datasheet:

LSM303AGR Datasheet

Clearly there are some significant differences between the LSM303D and LSM303AGR. I’ll try and get support for the LSM303AGR added to the Sensor Library.


#6

I’ve added some provisional routines here:

http://library.ulisp.com/show?3F3R

I’d welcome your feedback.


#7

Hi,

Thank a lot! I think it is working:

Read magnetometer x, y, and z --> defun lsm303-xyz ()

994> (lsm303-xyz)

(65369 65072 64884)

Is new data ready? --> defun lsm303-data-p ()

957> (lsm303-data-p )
t

I will try to understand the code and the way it reads data to get info from the Accelerometer. I assume that you use a combination of the Register address map perhaps it is possible to create a dice similar app: https://makecode.microbit.org/projects/dice I will try that.

Best Regards and thanks a lot for your support.


#8

I think the dice uses the accelerometer rather than the magnetometer. I’ll see if I can get that to work too.

David