-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MPU6050 #35
Open
oliveiraallex
wants to merge
4
commits into
pharo-iot:dev
Choose a base branch
from
oliveiraallex:MPU6050
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
MPU6050 #35
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c2fa25c
Driver to sensor MPU6050 accelerometer/gyroscope
oliveiraallex 5636973
Changed the word 'skaliert' to 'scaled'
oliveiraallex db4d399
initializing with wakeUpSensor method
oliveiraallex b64f805
waking up the sensor while reading the registers
oliveiraallex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"separateMethodMetaAndSource" : false, | ||
"noMethodMetaData" : true, | ||
"useCypressPropertiesFile" : true | ||
} |
24 changes: 24 additions & 0 deletions
24
src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
I provide implementation of Gyroscope/Accelerator I2C sensor MPU6050. | ||
|
||
The code for initialization and sensors reading is based from example: | ||
https://tutorials-raspberrypi.com/measuring-rotation-and-acceleration-raspberry-pi/ | ||
|
||
Register map: | ||
https://www.i2cdevlib.com/devices/mpu6050#registers | ||
|
||
To use it: | ||
sensor := (RpiBoard3B current) installDevice: PotMPU6050Device new. | ||
or on inspector: | ||
sensor := board installDevice: PotMPU6050Device new. | ||
|
||
API: | ||
readGyroscope. "#(1540 -9 -211)" | ||
readGyroscopeSkaliert. "#(13.526718 -1.916031 -1.526718)" | ||
readAccelerometer. "#(748 -892 15676)" | ||
readAccelerometerSkaliert. "#(0.033691 -0.051025 0.974121)" | ||
readRotationXY. "#(-3.224775339993247 -2.4755961852044157)" | ||
|
||
sensor := (RpiBoard3B current) installDevice: PotMPU6050Device new. | ||
sensor readRollPitchYaw | ||
sensor printRollPitchYaw. | ||
sensor finishRollPitchYaw. |
3 changes: 3 additions & 0 deletions
3
src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/class/defaultI2CAddress.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
instance creation | ||
defaultI2CAddress | ||
^16r68 |
3 changes: 3 additions & 0 deletions
3
...roThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/calculateDistanceA.B..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
controlling | ||
calculateDistanceA: anAccelerometerScaledA B: anAccelerometerScaledB | ||
^ ((anAccelerometerScaledA*anAccelerometerScaledA)+(anAccelerometerScaledB*anAccelerometerScaledB)) sqrt |
8 changes: 8 additions & 0 deletions
8
...Things-Devices-MPU6050.package/PotMPU6050Device.class/instance/calculateRotationX.Y.Z..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
controlling | ||
calculateRotationX: anAccelerometerScaledX Y: anAccelerometerScaledY Z: anAccelerometerScaledZ | ||
| radiansX radiansY rotationX rotationY | | ||
radiansX := anAccelerometerScaledY arcTan: (self calculateDistanceA: anAccelerometerScaledX B: anAccelerometerScaledZ). | ||
radiansY := anAccelerometerScaledX arcTan: (self calculateDistanceA: anAccelerometerScaledY B: anAccelerometerScaledZ). | ||
rotationX := radiansX radiansToDegrees. | ||
rotationY := radiansY radiansToDegrees * -1. | ||
^ { rotationX . rotationY } |
5 changes: 5 additions & 0 deletions
5
src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/connect.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
controlling | ||
connect | ||
super connect. | ||
self wakeUpSensor | ||
|
7 changes: 7 additions & 0 deletions
7
src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readAccelerometer.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
controlling | ||
readAccelerometer | ||
| accX accY accZ | | ||
accX := self readRegisters2C: 16r3b. | ||
accY := self readRegisters2C: 16r3d. | ||
accZ := self readRegisters2C: 16r3f. | ||
^ { accX . accY . accZ } |
8 changes: 8 additions & 0 deletions
8
...Things-Devices-MPU6050.package/PotMPU6050Device.class/instance/readAccelerometerScaled.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
controlling | ||
readAccelerometerScaled | ||
| acc accX accY accZ | | ||
acc := self readAccelerometer. | ||
accX := ((acc at: 1)/16384) asFloat round: 6. | ||
accY := ((acc at: 2)/16384) asFloat round: 6. | ||
accZ := ((acc at: 3)/16384) asFloat round: 6. | ||
^ { accX . accY . accZ } |
7 changes: 7 additions & 0 deletions
7
src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readGyroscope.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
controlling | ||
readGyroscope | ||
| gyroX gyroY gyroZ | | ||
gyroX := self readRegisters2C: 16r43. | ||
gyroY := self readRegisters2C: 16r45. | ||
gyroZ := self readRegisters2C: 16r47. | ||
^ { gyroX . gyroY . gyroZ } |
8 changes: 8 additions & 0 deletions
8
...haroThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readGyroscopeScaled.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
controlling | ||
readGyroscopeScaled | ||
| gyro gyroX gyroY gyroZ | | ||
gyro := self readGyroscope. | ||
gyroX := (gyro at: 1)/131 asFloat round: 6. | ||
gyroY := (gyro at: 2)/131 asFloat round: 6. | ||
gyroZ := (gyro at: 3)/131 asFloat round: 6. | ||
^ { gyroX . gyroY . gyroZ } |
11 changes: 11 additions & 0 deletions
11
src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRegisters..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
controlling | ||
readRegisters: anHex | ||
| h l value | | ||
h := i2cConnection read8BitsAt: anHex. | ||
l := i2cConnection read8BitsAt: anHex + 1. | ||
(h == 0 & l == 0) | ||
ifTrue: [ self wakeUpSensor. 1 milliSeconds wait. | ||
h := i2cConnection read8BitsAt: anHex. | ||
l := i2cConnection read8BitsAt: anHex + 1 ]. | ||
value := (h bitShift: 8) + l. | ||
^ value |
7 changes: 7 additions & 0 deletions
7
src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRegisters2C..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
controlling | ||
readRegisters2C: anHex | ||
| value | | ||
value := self readRegisters: anHex. | ||
value >= 16r8000 | ||
ifTrue: [ ^ ((65535 - value) + 1) * -1] | ||
ifFalse: [^ value ] |
8 changes: 8 additions & 0 deletions
8
src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRotationXY.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
controlling | ||
readRotationXY | ||
| accelerometerScaled rotation rotationX rotationY | | ||
accelerometerScaled := self readAccelerometerScaled. | ||
rotation := self calculateRotationX: (accelerometerScaled at: 1) Y: (accelerometerScaled at: 2) Z: (accelerometerScaled at: 3). | ||
rotationX := rotation at: 1. | ||
rotationY := rotation at: 2. | ||
^ { rotationX . rotationY } |
3 changes: 3 additions & 0 deletions
3
src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/wakeUpSensor.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
controlling | ||
wakeUpSensor | ||
i2cConnection write8BitsAt: 16r6b data: 0 |
13 changes: 13 additions & 0 deletions
13
src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"commentStamp" : "AllexOliveira 8/7/2019 18:28", | ||
"super" : "PotI2CDevice", | ||
"category" : "PharoThings-Devices-MPU6050", | ||
"classinstvars" : [ ], | ||
"pools" : [ ], | ||
"classvars" : [ ], | ||
"instvars" : [ | ||
"readProcess" | ||
], | ||
"name" : "PotMPU6050Device", | ||
"type" : "normal" | ||
} |
1 change: 1 addition & 0 deletions
1
src/PharoThings-Devices-MPU6050.package/monticello.meta/categories.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SystemOrganization addCategory: #'PharoThings-Devices-MPU6050'! |
Empty file.
1 change: 1 addition & 0 deletions
1
src/PharoThings-Devices-MPU6050.package/monticello.meta/package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(name 'PharoThings-Devices-MPU6050') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have more meaningful names for h and l it would be much better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to improve it. I rewrote this drive from scratch, I'm just finishing some adjusts to push it again.