Czy ktoś z Was bawił się MPU6050 ? W bascom trudno znaleźć kod taki co by zamieniał G na odchylenie kątowe w stopniach (na arduino jest cała masa ale tam mają biblioteki , podstawiasz zmienne i po sprawie).
Na razie rozpracowuję akcelerometr , właściwie chodzi ale nie do końca . Odchylając oś X pięknie oblicza do ale dochodząc do 90 stopni kąta pełnego oś Y zaczyna szaleć (pokazuje co chce przy małych odchyłach na osi Y).
Identycznie jest kiedy odchylam oś Y a X jest w miejscu i objaw ten sam przy 90 stopniach Y , X zaczyna szaleć . Kiedyś miałem moduł z adxl335 i było identycznie więc to na 100% wina w podejściu do kodu , stawiam na użycie funkcji ATN2(x,y) . Interesuje mnie też żyroskop i jak go obrobić ale najpierw możliwe poprawki z akcelerometrem.
- $regfile = "m32def.dat"
- $crystal = 20000000
- $hwstack = 32
- $swstack = 32
- $framesize = 32
- $baud =57600
- '----------------------------------------------------------------------------------------------------------------
- Config Lcd = 20 * 4
- Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E = Portc.3 , Rs = Portc.2
- Cls
- Cursor Off
- '----------------------------------------------------------------------------------------------------------------
- $lib "i2c_twi.lbx"
- Config Scl = Portc.0
- Config Sda = Portc.1
- Config Twi = 400000
- I2cinit
- '----------------------------------------------------------------------------------------------------------------
- Dim x As integer
- Dim y As Integer
- Dim z As Integer
- Dim ay(2) As Byte
- Dim az(2) As Byte
- Dim ax(2) As Byte
- dim xx as single,yy as single,zz as single ,dlax as single , dlay as single
- dim xxx as single,yyy as single
- dim textx as string*10,texty as string*10
- '--- (25) Sample Rate Divider = 1 ---
- I2cstart 'start condition
- I2cwbyte &HD0 'write adress of MPU-6050
- I2cwbyte 25 'Register 25 Sample Rate Divider (1..8 kHz)
- I2cwbyte &B00000000 'Divider set to 1 (soll)
- I2cstop 'stop condition
- '--- (26) DLPF = 42/44 Hz ---
- I2cstart 'start condition
- I2cwbyte &HD0 'write adress of MPU-6050
- I2cwbyte 26 'Register 26 DLPF_CFG (digital lowpass filter) Configuration
- I2cwbyte &B00000011 'Bits 0..2 = 011 (3) - ACC:44Hz, 4.9ms; Gyro:42Hz, 4.8ms
- I2cstop 'stop condition
- '--- (27) Gyro Full Range = +-2000°/s ---
- I2cstart 'start condition
- I2cwbyte &HD0 'write adress of MPU-6050
- I2cwbyte 27 'Register 27 Gyro Configuration
- I2cwbyte &B00011000 'Bits 3+4 = 11 - Full Scale Range: +/-2000°/ss
- I2cstop 'stop condition
- '--- (28) ACC Full Range = +-2g ---
- I2cstart 'start condition
- I2cwbyte &HD0 'write adress of MPU-6050
- I2cwbyte 28 'Register 28 ACC Configuration
- I2cwbyte &B00000000 'Bits 3+4 = 00 - Full Scale Range: +/-2g / No High Pass Filter
- I2cstop 'stop condition
- '--- (107) Power Management 1 ---
- I2cstart 'start condition
- I2cwbyte &HD0 'write adress of MPU-6050
- I2cwbyte 107 'Register 107 Power Management 1
- I2cwbyte &B00000011 'No Reset / No Sleep / No Cycle / Temp_Sens: Dis / Clock Source: Z-Gyro
- I2cstop
- Do
- gosub czytaj_xyz
- x=makeint(ax(1),ax(2))
- y=makeint(ay(1),ay(2))
- z=makeint(az(1),az(2))
- xx=x
- yy=y
- zz=z
- xx=x/16384
- yy=y/16384
- zz=z/16384
- xxx=atn2(xx,zz)
- yyy=atn2(yy,zz)
- dlax=RAD2DEG(yyy)
- dlay=RAD2DEG(xxx)
- textx = Fusing(dlax , "##.&")
- texty = Fusing(dlay , "##.&")
- locate 1,1
- lcd "x/ ";textx
- locate 2,1
- lcd "y/ ";texty
- Loop
- End
- czytaj_xyz:
- I2cstart
- I2cwbyte &HD0
- I2cwbyte 59
- I2crepstart
- I2cwbyte &HD1
- I2crbyte ax(2) , Ack
- I2crbyte ax(1) , Ack
- I2crbyte ay(2) , Ack
- I2crbyte ay(1) , Ack
- I2crbyte az(2) , Ack
- I2crbyte az(1) , Nack
- I2cstop
- return