View previous topic :: View next topic |
Author |
Message |
six1
Joined: 27 Feb 2009 Posts: 553
|
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Fri Feb 15, 2013 3:55 pm Post subject: |
|
|
you have to make a word of the 2 data
use makeint or use overlay
did not have time to test but like this
Config Single = Scientific , Digits = 1
Dim Angle2 As Single
Angle = Makeint(value(3) , Value(2)) 'angle
Angle2 = Angle / 10
Print Angle2 _________________ / Kim |
|
Back to top |
|
|
mhk1367
Joined: 20 Jan 2013 Posts: 34
|
Posted: Sun Feb 17, 2013 10:10 am Post subject: |
|
|
thanks this code do well but it's degree change for example for 135' change between 123 to 147
how i can get it's real degree with no change or very very small change?
Code: | $regfile = "m16def.dat"
$crystal = 8000000
$baud = 9600 ' 'USE TX RX pins PORTD.0 PORTD.1
$hwstack = 32
$swstack = 32
$framesize = 40
'connect GY-26 to SDA SCL pins PULLUPS 4K7
Config Scl = Portc.0
Config Sda = Portc.1
Config I2cdelay = 20
Config Single = Scientific , Digits = 1
Dim Angle As Word
Dim Angle2 As Word
Dim Value(8) As Byte , A As Byte
Do
I2cstart 'generate start
I2cwbyte &HE0 'chip adsress
I2cwbyte &H00 'address of EEPROM
I2cwbyte &H31
I2cstart 'repeated start
I2cwbyte &HE1 'read address (read)
I2crbyte Value(1) , Ack 'read byte
I2crbyte Value(2) , Ack 'read byte
I2crbyte Value(3) , Ack 'read byte
I2crbyte Value(4) , Ack 'read byte
I2crbyte Value(5) , Ack 'read byte
I2crbyte Value(6) , Ack 'read byte
I2crbyte Value(7) , Ack 'read byte
I2crbyte Value(8) , Nack 'read byte
I2cstop
Waitms 20
Angle = Makeint(value(3) , Value(2)) 'angle
Angle2 = Angle / 10
Print Angle2
Wait 1
Loop |
|
|
Back to top |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Sun Feb 17, 2013 3:07 pm Post subject: |
|
|
You need to calibrate it
Quote: | 4. Calibrating methods and functions
When magnetic field changes angle information counted by compass will be inaccurate. This time it is
necessary to calibrate the compass to remove the influence.
Methods:
Send “0xC0” command, and then rotate the compass two circles slowly, equably and flatly, fast not
allowed. One cycle needs more than one minute. Then send “0xC1” command to finish calibration.
|
I2C
send &H00
send &HC0
read 8 byte
rotate it slowly and when done a full circle
send &H00
send OHC1
read 8 byte
the serial code can be used to just make Input a string and use TX/RX chip hardware serial port
but then you must use the serial command _________________ / Kim |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|