I have a project that needs a compass. It uses I2C to communicate how do I do this? setup the module for continues output mode by writing (0x3C) 0x00 to the MODE register (0x02).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I2C is relatively easy. Are you planning to use Hardware I2C or Software I2C? or both?
Do you know the speed of the I2C bus? A URL to product may help me also.
Anobium
Last edit: Anobium 2015-07-30
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you. We have a driver for this device. Please update to the latest driver here, DOWNLOAD HERE. Please place this file in your GCB 'include' folder.
I also just published a demonstration file to the code respository, DOWNLOAD HERE. The demonstration shows a simple read of the threee axis on a serial terminal - you can change this to any display type of course. I wrote this last year for someone and this covers the primitives of initialsation and read only. If you can improve the driver and the demonstration please let us have the file back others to use.
If you have any issues with these files do not hesitate to ask - as I never got any formal feedback on the driver last year if ok, or not.
Since last year we have added all the maths functions you will be needing like TAN, SIN etc. Look at the Help File for examples etc.
Let us know how you get on.
Anobium
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi all, tried out the driver ran into some problems. First had to remove the locate command. Second had to change HI2c to I2C and add the I2cStart commad to get it to work. Problem is allways return FF for the high or low bit. What am I doing wrong
OK here goes. I am truly flying a little blind and I do have your device.
But, I need you to download the driver again, see here. Place in your include directory.
Then, try this code attached.
I have made a few changes.
You need to check a few things.
1. Why the ocstune? I am just wondering.
2. Check the address of the device. It is can be different. If so, change in the program - I had added the #define for you.
3. The example I provided used hardware I2C and you are using software I2C - you were not setting up properly. You will lots of information in the help file.
4. I did remove all the CALLs. They, are not requried.
5. I removed the I2CStart. This is not required.
I think the main issues were - i2c was probably not setup correctly but more importantly I think the init of the compass was happening before the init of i2c.... this was incorrect in the .h file - I could not test.... all theory. :-)
If you cannot determine the address from the datasheet or the device I recommend you use the I2CDiscoveryRoutines to determine this device address. This will also validate your configuration and the pullup resistors are all ok.
Look in the \GCB@Syn\GreatCowBasic\Demos\I2C Solutions\I2C Discovery folder for the a software discovery demo. Take a copy and move to another folder. Then, edit and get this work via your LCD. When we have validated the I2C address then we can move back to the sensor.
Make sense?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I would get i2c discovery working. This will validate the connectivity.
Do you have the correct pull-up resistors? Lines crossed? Discovery will help determine connectivity.
I know the i2cdiscovery works - I can validate this here. Once you can see the device using the discovery code then we can be confident that we have comms.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
High modified discover see attach get these errors
ompiled.asm:387:Error [113] Symbol not previously defined (TRISC).
compiled.asm:395:Error [113] Symbol not previously defined (TRISC).
compiled.asm:398:Error [113] Symbol not previously defined (TRISC).
compiled.asm:403:Error [113] Symbol not previously defined (TRISC).
compiled.asm:408:Error [113] Symbol not previously defined (TRISC).
compiled.asm:419:Error [113] Symbol not previously defined (TRISC).
compiled.asm:421:Error [113] Symbol not previously defined (TRISC).
compiled.asm:441:Error [113] Symbol not previously defined (TRISC).
compiled.asm:444:Error [113] Symbol not previously defined (TRISC).
compiled.asm:454:Error [113] Symbol not previously defined (TRISC).
compiled.asm:455:Error [113] Symbol not previously defined (TRISC).
compiled.asm:457:Error [113] Symbol not previously defined (TRISC).
compiled.asm:460:Error [113] Symbol not previously defined (TRISC).
compiled.asm:467:Error [113] Symbol not previously defined (TRISC).
compiled.asm:469:Error [113] Symbol not previously defined (TRISC).
compiled.asm:472:Error [113] Symbol not previously defined (TRISC).
compiled.asm:474:Error [113] Symbol not previously defined (TRISC).
compiled.asm:481:Error [113] Symbol not previously defined (TRISC).
compiled.asm:482:Error [113] Symbol not previously defined (TRISC).
Edit the source please. Edit out the extra HSerPrintCRLF on line 63.
Is the LCD showing 'Software I2C Device Search'? If not, we need that working first.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The driver was provided by a conributor. I validated the code prior to inclusion in the release.
Can you describe you circuit? A diagram would be best. Show resistors and any key device dependent passive devices.
I still recommend getting the discover code working as this will ensure you connectivity circuit is correct. The discovery code scans the bus and find any device on the bus - if it does not find the device then the issue may be elsewhere.
Can you let me know what version of GCB you are using? We have resolved a lot of issues with the I2C protocol.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You must upgrade. I2C that old will not work as expected.
You are correct this module is equipped with 4.7 kΩ pull-up resistors on the SDA line and a 2.2K resistor on the SCL line. There is no need for any external hardware to operate.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have a project that needs a compass. It uses I2C to communicate how do I do this? setup the module for continues output mode by writing (0x3C) 0x00 to the MODE register (0x02).
Attach the datasheet, I can then advise.
I2C is relatively easy. Are you planning to use Hardware I2C or Software I2C? or both?
Do you know the speed of the I2C bus? A URL to product may help me also.
Anobium
Last edit: Anobium 2015-07-30
Anobium, Here are all I have found. Planning s/w I2C. Thanks, Ed.
For got this
Thank you. We have a driver for this device. Please update to the latest driver here, DOWNLOAD HERE. Please place this file in your GCB 'include' folder.
I also just published a demonstration file to the code respository, DOWNLOAD HERE. The demonstration shows a simple read of the threee axis on a serial terminal - you can change this to any display type of course. I wrote this last year for someone and this covers the primitives of initialsation and read only. If you can improve the driver and the demonstration please let us have the file back others to use.
If you have any issues with these files do not hesitate to ask - as I never got any formal feedback on the driver last year if ok, or not.
Since last year we have added all the maths functions you will be needing like TAN, SIN etc. Look at the Help File for examples etc.
Let us know how you get on.
Anobium
Anobium, you guys are very smart. I will give you feedback in a few months when I work on it. Thanks, Ed.
Hi all, tried out the driver ran into some problems. First had to remove the locate command. Second had to change HI2c to I2C and add the I2cStart commad to get it to work. Problem is allways return FF for the high or low bit. What am I doing wrong
OK here goes. I am truly flying a little blind and I do have your device.
But, I need you to download the driver again, see here. Place in your include directory.
Then, try this code attached.
I have made a few changes.
You need to check a few things.
1. Why the ocstune? I am just wondering.
2. Check the address of the device. It is can be different. If so, change in the program - I had added the #define for you.
3. The example I provided used hardware I2C and you are using software I2C - you were not setting up properly. You will lots of information in the help file.
4. I did remove all the CALLs. They, are not requried.
5. I removed the I2CStart. This is not required.
I think the main issues were - i2c was probably not setup correctly but more importantly I think the init of the compass was happening before the init of i2c.... this was incorrect in the .h file - I could not test.... all theory. :-)
Let us know the results.
Ocstune to trim frequency to be exact. How do I check the device address?
With the changes it now reads 00, what next? Thanks, Ed.
If you cannot determine the address from the datasheet or the device I recommend you use the I2CDiscoveryRoutines to determine this device address. This will also validate your configuration and the pullup resistors are all ok.
Look in the \GCB@Syn\GreatCowBasic\Demos\I2C Solutions\I2C Discovery folder for the a software discovery demo. Take a copy and move to another folder. Then, edit and get this work via your LCD. When we have validated the I2C address then we can move back to the sensor.
Make sense?
Datasheet says 0x3d is read 0x3c is write. Used 0x3d still gets 00. Wj\hat next? Thanks, Ed.
I would get i2c discovery working. This will validate the connectivity.
Do you have the correct pull-up resistors? Lines crossed? Discovery will help determine connectivity.
I know the i2cdiscovery works - I can validate this here. Once you can see the device using the discovery code then we can be confident that we have comms.
I tried low byte it is FF high is 00.
OK. What others tool do you have? How did you determine the FF?
High modified discover see attach get these errors
ompiled.asm:387:Error [113] Symbol not previously defined (TRISC).
compiled.asm:395:Error [113] Symbol not previously defined (TRISC).
compiled.asm:398:Error [113] Symbol not previously defined (TRISC).
compiled.asm:403:Error [113] Symbol not previously defined (TRISC).
compiled.asm:408:Error [113] Symbol not previously defined (TRISC).
compiled.asm:419:Error [113] Symbol not previously defined (TRISC).
compiled.asm:421:Error [113] Symbol not previously defined (TRISC).
compiled.asm:441:Error [113] Symbol not previously defined (TRISC).
compiled.asm:444:Error [113] Symbol not previously defined (TRISC).
compiled.asm:454:Error [113] Symbol not previously defined (TRISC).
compiled.asm:455:Error [113] Symbol not previously defined (TRISC).
compiled.asm:457:Error [113] Symbol not previously defined (TRISC).
compiled.asm:460:Error [113] Symbol not previously defined (TRISC).
compiled.asm:467:Error [113] Symbol not previously defined (TRISC).
compiled.asm:469:Error [113] Symbol not previously defined (TRISC).
compiled.asm:472:Error [113] Symbol not previously defined (TRISC).
compiled.asm:474:Error [113] Symbol not previously defined (TRISC).
compiled.asm:481:Error [113] Symbol not previously defined (TRISC).
compiled.asm:482:Error [113] Symbol not previously defined (TRISC).
Did you change the ports? I thought you were using portb.
You are right now OK but nothing but Jibberish on LCD can not determine any address Any Ideas?
Edit the source please. Edit out the extra HSerPrintCRLF on line 63.
Is the LCD showing 'Software I2C Device Search'? If not, we need that working first.
Ok I get message s/w search. Having probelms with the LCD. getting late will resume tomorrow AM
Hi I give up. I do not uderstand why we should doubt the datasheet address. Has anyone got your code to work with a real device or am I the first one
The driver was provided by a conributor. I validated the code prior to inclusion in the release.
Can you describe you circuit? A diagram would be best. Show resistors and any key device dependent passive devices.
I still recommend getting the discover code working as this will ensure you connectivity circuit is correct. The discovery code scans the bus and find any device on the bus - if it does not find the device then the issue may be elsewhere.
Can you let me know what version of GCB you are using? We have resolved a lot of issues with the I2C protocol.
Verion Great Cow BASIC (0.9 22/9/2013) No passive parts just 16F88 chip and compass module wired as per datasheet.
You must upgrade. I2C that old will not work as expected.
You are correct this module is equipped with 4.7 kΩ pull-up resistors on the SDA line and a 2.2K resistor on the SCL line. There is no need for any external hardware to operate.
where do I find it?
Why do I need to update I2C.h when it has its own include <hmc5883l.h></hmc5883l.h>
Last edit: Edward LaBudde 2015-09-04