Go Down

Topic: Defining address for 2 component compass (Read 742 times) previous topic - next topic

No1Daemon

Hi all

I have followed a tutorial to create a tilt compensated compass using the HMC5883L compass and the ADXL345 accelerometer.
Both are stored as variables.

Is it possible to define them as a complete unit?
ie if I was using the following in my code

Code: [Select]
#define compassAddress 0x32 >> 1

How do i go about assigning both components a single address to reference from that address.

Excuse the terminology, it may be incorrect. I did a lot of googling trying to find an answer but realised I dont even know how to ask the question :)
Hopefully it will make sense to someone

Thanks
Steve

CrossRoads

You would need an intermediate device with 1 address that would then pass the message to one device or the other.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

No1Daemon

Bummer.
I never considered that.

Could I not just se it up so when I address the compass it runs a separate loop that encompasses both devices and returns the appropriate data?

Like nesting perhaps.

If not what sort of device might we be referring to?

CrossRoads

Could be an AVR with I2C interface.  Maybe one of the ATTiny devices.

Post links for 2 the devices you want to use.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.


CrossRoads

I2C Address
8-bit read address 0x3D
8-bit write address 0x3C

With the ALT ADDRESS pin high, the 7-bit I2C address for the device is 0x1D, followed by the R/W bit.
This translates to 0x3A for a write and 0x3B for a read.
An alternate I2C address of 0x53 (followed by the R/W bit) can be chosen by grounding the ALT ADDRESS pin (Pin 12).
This translates to 0xA6 for a write and 0xA7 for a read.

So you've two different addresses, with wholly different data coming from each part.
3A/3B you get one's part info, 3C/3D you get the other.
Talk to both using normal library kind of calls.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

PeterH


I have followed a tutorial to create a tilt compensated compass using the HMC5883L compass and the ADXL345 accelerometer.
Both are stored as variables.

Is it possible to define them as a complete unit?

How do i go about assigning both components a single address to reference from that address.


I'm trying to guess why you're trying to do this, and I couldn't think of a reason. If you want to represent both devices as a single conceptual thing in your code, you could define a class to encapsulate them both. Or if classes aren't your thing you could just define a struct to contain the two addresses, and another struct to contain both sets of results, and a function to read the results from the devices.

I only provide help via the forum - please do not contact me for private consultancy.

No1Daemon

Peter

At the end of the day all it does is the HMC outputs a bearing and then the ADXL corrects it for tilt and outputs a tilt compensated bearing.
All I require is to get the tilt compensated bearing with one call basicaly.
Suspected it would be hard to see wy I needed this, especially if you are experiences with code as I am not.

Regards
Steve

CrossRoads

Have you seen this chip?
https://www.sparkfun.com/products/10888?

"LSM303DLMTR Breakout Board - Tilt Compensated Compass"

Sounds kinda like what you're after: "a tilt compensated compass using the HMC5883L compass and the ADXL345 accelerometer"
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

No1Daemon

Yes I did but but only after I have made one now out of seperate components so I will battle on.
Thanks for the replies guys.

Go Up