From c2fa25c5be039445018985fbc89e6a90ce3508ef Mon Sep 17 00:00:00 2001 From: Allex Oliveira Date: Tue, 6 Aug 2019 18:22:54 +0200 Subject: [PATCH 1/4] Driver to sensor MPU6050 accelerometer/gyroscope --- .../instance/devices.st | 3 ++- .../.filetree | 5 +++++ .../PotMPU6050Device.class/README.md | 19 +++++++++++++++++++ .../class/defaultI2CAddress.st | 3 +++ .../instance/calculateDistanceA.B..st | 3 +++ .../instance/calculateRotationX.Y.Z..st | 8 ++++++++ .../instance/connect.st | 4 ++++ .../instance/readAccelerometer.st | 7 +++++++ .../instance/readAccelerometerSkaliert.st | 8 ++++++++ .../instance/readGyroscope.st | 7 +++++++ .../instance/readGyroscopeSkaliert.st | 8 ++++++++ .../instance/readRegisters..st | 7 +++++++ .../instance/readRegisters2C..st | 7 +++++++ .../instance/readRotationXY.st | 8 ++++++++ .../PotMPU6050Device.class/properties.json | 11 +++++++++++ .../monticello.meta/categories.st | 1 + .../monticello.meta/initializers.st | 0 .../monticello.meta/package | 1 + .../properties.json | 1 + 19 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 src/PharoThings-Devices-MPU6050.package/.filetree create mode 100644 src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/README.md create mode 100644 src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/class/defaultI2CAddress.st create mode 100644 src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/calculateDistanceA.B..st create mode 100644 src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/calculateRotationX.Y.Z..st create mode 100644 src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/connect.st create mode 100644 src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readAccelerometer.st create mode 100644 src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readAccelerometerSkaliert.st create mode 100644 src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readGyroscope.st create mode 100644 src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readGyroscopeSkaliert.st create mode 100644 src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRegisters..st create mode 100644 src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRegisters2C..st create mode 100644 src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRotationXY.st create mode 100644 src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/properties.json create mode 100644 src/PharoThings-Devices-MPU6050.package/monticello.meta/categories.st create mode 100644 src/PharoThings-Devices-MPU6050.package/monticello.meta/initializers.st create mode 100644 src/PharoThings-Devices-MPU6050.package/monticello.meta/package create mode 100644 src/PharoThings-Devices-MPU6050.package/properties.json diff --git a/src/BaselineOfPharoThings.package/BaselineOfPharoThings.class/instance/devices.st b/src/BaselineOfPharoThings.package/BaselineOfPharoThings.class/instance/devices.st index 3c1634e..73facd8 100644 --- a/src/BaselineOfPharoThings.package/BaselineOfPharoThings.class/instance/devices.st +++ b/src/BaselineOfPharoThings.package/BaselineOfPharoThings.class/instance/devices.st @@ -9,5 +9,6 @@ devices #'PharoThings-Devices-ADXL345' -> #(#'PharoThings-Devices-I2C'). #'PharoThings-Devices-MCP9808' -> #(#'PharoThings-Devices-I2C'). #'PharoThings-Devices-BME280' -> #(#'PharoThings-Devices-I2C'). - #'PharoThings-Devices-HD44780' -> #(#'PharoThings-Devices-I2C') + #'PharoThings-Devices-HD44780' -> #(#'PharoThings-Devices-I2C'). + #'PharoThings-Devices-MPU6050' -> #(#'PharoThings-Devices-I2C') } \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/.filetree b/src/PharoThings-Devices-MPU6050.package/.filetree new file mode 100644 index 0000000..57a6797 --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/.filetree @@ -0,0 +1,5 @@ +{ + "separateMethodMetaAndSource" : false, + "noMethodMetaData" : true, + "useCypressPropertiesFile" : true +} \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/README.md b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/README.md new file mode 100644 index 0000000..21f4ca7 --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/README.md @@ -0,0 +1,19 @@ +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)" \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/class/defaultI2CAddress.st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/class/defaultI2CAddress.st new file mode 100644 index 0000000..7e7c828 --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/class/defaultI2CAddress.st @@ -0,0 +1,3 @@ +instance creation +defaultI2CAddress + ^16r68 \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/calculateDistanceA.B..st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/calculateDistanceA.B..st new file mode 100644 index 0000000..c982957 --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/calculateDistanceA.B..st @@ -0,0 +1,3 @@ +controlling +calculateDistanceA: anAccelerometerSkaliertA B: anAccelerometerSkaliertB + ^ ((anAccelerometerSkaliertA*anAccelerometerSkaliertA)+(anAccelerometerSkaliertB*anAccelerometerSkaliertB)) sqrt \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/calculateRotationX.Y.Z..st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/calculateRotationX.Y.Z..st new file mode 100644 index 0000000..31113eb --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/calculateRotationX.Y.Z..st @@ -0,0 +1,8 @@ +controlling +calculateRotationX: anAccelerometerSkaliertX Y: anAccelerometerSkaliertY Z: anAccelerometerSkaliertZ + | radiansX radiansY rotationX rotationY | + radiansX := anAccelerometerSkaliertY arcTan: (self calculateDistanceA: anAccelerometerSkaliertX B: anAccelerometerSkaliertZ). + radiansY := anAccelerometerSkaliertX arcTan: (self calculateDistanceA: anAccelerometerSkaliertY B: anAccelerometerSkaliertZ). + rotationX := radiansX radiansToDegrees. + rotationY := radiansY radiansToDegrees * -1. + ^ { rotationX . rotationY } \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/connect.st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/connect.st new file mode 100644 index 0000000..f4e2551 --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/connect.st @@ -0,0 +1,4 @@ +controlling +connect + super connect + diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readAccelerometer.st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readAccelerometer.st new file mode 100644 index 0000000..c6a110f --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readAccelerometer.st @@ -0,0 +1,7 @@ +controlling +readAccelerometer + | accX accY accZ | + accX := self readRegisters2C: 16r3b. + accY := self readRegisters2C: 16r3d. + accZ := self readRegisters2C: 16r3f. + ^ { accX . accY . accZ } \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readAccelerometerSkaliert.st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readAccelerometerSkaliert.st new file mode 100644 index 0000000..bcfb3db --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readAccelerometerSkaliert.st @@ -0,0 +1,8 @@ +controlling +readAccelerometerSkaliert + | 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 } \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readGyroscope.st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readGyroscope.st new file mode 100644 index 0000000..904c66f --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readGyroscope.st @@ -0,0 +1,7 @@ +controlling +readGyroscope + | gyroX gyroY gyroZ | + gyroX := self readRegisters2C: 16r43. + gyroY := self readRegisters2C: 16r45. + gyroZ := self readRegisters2C: 16r47. + ^ { gyroX . gyroY . gyroZ } \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readGyroscopeSkaliert.st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readGyroscopeSkaliert.st new file mode 100644 index 0000000..e4cd8a7 --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readGyroscopeSkaliert.st @@ -0,0 +1,8 @@ +controlling +readGyroscopeSkaliert + | 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 } \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRegisters..st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRegisters..st new file mode 100644 index 0000000..4cf95e0 --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRegisters..st @@ -0,0 +1,7 @@ +controlling +readRegisters: anHex + | h l value | + h := i2cConnection read8BitsAt: anHex. + l := i2cConnection read8BitsAt: anHex + 1. + value := (h bitShift: 8) + l. + ^ value \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRegisters2C..st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRegisters2C..st new file mode 100644 index 0000000..6415e7f --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRegisters2C..st @@ -0,0 +1,7 @@ +controlling +readRegisters2C: anHex + | value | + value := self readRegisters: anHex. + value >= 16r8000 + ifTrue: [ ^ ((65535 - value) + 1) * -1] + ifFalse: [^ value ] \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRotationXY.st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRotationXY.st new file mode 100644 index 0000000..55b0904 --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRotationXY.st @@ -0,0 +1,8 @@ +controlling +readRotationXY + | accelerometerSkaliert rotation rotationX rotationY | + accelerometerSkaliert := self readAccelerometerSkaliert. + rotation := self calculateRotationX: (accelerometerSkaliert at: 1) Y: (accelerometerSkaliert at: 2) Z: (accelerometerSkaliert at: 3). + rotationX := rotation at: 1. + rotationY := rotation at: 2. + ^ { rotationX . rotationY } \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/properties.json b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/properties.json new file mode 100644 index 0000000..cec8529 --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/properties.json @@ -0,0 +1,11 @@ +{ + "commentStamp" : "AllexOliveira 8/6/2019 17:51", + "super" : "PotI2CDevice", + "category" : "PharoThings-Devices-MPU6050", + "classinstvars" : [ ], + "pools" : [ ], + "classvars" : [ ], + "instvars" : [ ], + "name" : "PotMPU6050Device", + "type" : "normal" +} \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/monticello.meta/categories.st b/src/PharoThings-Devices-MPU6050.package/monticello.meta/categories.st new file mode 100644 index 0000000..66e7f4c --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/monticello.meta/categories.st @@ -0,0 +1 @@ +SystemOrganization addCategory: #'PharoThings-Devices-MPU6050'! diff --git a/src/PharoThings-Devices-MPU6050.package/monticello.meta/initializers.st b/src/PharoThings-Devices-MPU6050.package/monticello.meta/initializers.st new file mode 100644 index 0000000..e69de29 diff --git a/src/PharoThings-Devices-MPU6050.package/monticello.meta/package b/src/PharoThings-Devices-MPU6050.package/monticello.meta/package new file mode 100644 index 0000000..b84f9fd --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/monticello.meta/package @@ -0,0 +1 @@ +(name 'PharoThings-Devices-MPU6050') \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/properties.json b/src/PharoThings-Devices-MPU6050.package/properties.json new file mode 100644 index 0000000..6f31cf5 --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/properties.json @@ -0,0 +1 @@ +{ } \ No newline at end of file From 5636973ce23900dfe6dfe93b02e5f86fc22b04c0 Mon Sep 17 00:00:00 2001 From: Allex Oliveira Date: Wed, 7 Aug 2019 11:04:15 +0200 Subject: [PATCH 2/4] Changed the word 'skaliert' to 'scaled' --- .../instance/calculateDistanceA.B..st | 4 ++-- .../instance/calculateRotationX.Y.Z..st | 6 +++--- ...dAccelerometerSkaliert.st => readAccelerometerScaled.st} | 2 +- .../{readGyroscopeSkaliert.st => readGyroscopeScaled.st} | 2 +- .../PotMPU6050Device.class/instance/readRotationXY.st | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) rename src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/{readAccelerometerSkaliert.st => readAccelerometerScaled.st} (90%) rename src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/{readGyroscopeSkaliert.st => readGyroscopeScaled.st} (91%) diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/calculateDistanceA.B..st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/calculateDistanceA.B..st index c982957..8a1ba48 100644 --- a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/calculateDistanceA.B..st +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/calculateDistanceA.B..st @@ -1,3 +1,3 @@ controlling -calculateDistanceA: anAccelerometerSkaliertA B: anAccelerometerSkaliertB - ^ ((anAccelerometerSkaliertA*anAccelerometerSkaliertA)+(anAccelerometerSkaliertB*anAccelerometerSkaliertB)) sqrt \ No newline at end of file +calculateDistanceA: anAccelerometerScaledA B: anAccelerometerScaledB + ^ ((anAccelerometerScaledA*anAccelerometerScaledA)+(anAccelerometerScaledB*anAccelerometerScaledB)) sqrt \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/calculateRotationX.Y.Z..st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/calculateRotationX.Y.Z..st index 31113eb..28edfdd 100644 --- a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/calculateRotationX.Y.Z..st +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/calculateRotationX.Y.Z..st @@ -1,8 +1,8 @@ controlling -calculateRotationX: anAccelerometerSkaliertX Y: anAccelerometerSkaliertY Z: anAccelerometerSkaliertZ +calculateRotationX: anAccelerometerScaledX Y: anAccelerometerScaledY Z: anAccelerometerScaledZ | radiansX radiansY rotationX rotationY | - radiansX := anAccelerometerSkaliertY arcTan: (self calculateDistanceA: anAccelerometerSkaliertX B: anAccelerometerSkaliertZ). - radiansY := anAccelerometerSkaliertX arcTan: (self calculateDistanceA: anAccelerometerSkaliertY B: anAccelerometerSkaliertZ). + 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 } \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readAccelerometerSkaliert.st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readAccelerometerScaled.st similarity index 90% rename from src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readAccelerometerSkaliert.st rename to src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readAccelerometerScaled.st index bcfb3db..6b15381 100644 --- a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readAccelerometerSkaliert.st +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readAccelerometerScaled.st @@ -1,5 +1,5 @@ controlling -readAccelerometerSkaliert +readAccelerometerScaled | acc accX accY accZ | acc := self readAccelerometer. accX := ((acc at: 1)/16384) asFloat round: 6. diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readGyroscopeSkaliert.st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readGyroscopeScaled.st similarity index 91% rename from src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readGyroscopeSkaliert.st rename to src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readGyroscopeScaled.st index e4cd8a7..ec8b617 100644 --- a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readGyroscopeSkaliert.st +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readGyroscopeScaled.st @@ -1,5 +1,5 @@ controlling -readGyroscopeSkaliert +readGyroscopeScaled | gyro gyroX gyroY gyroZ | gyro := self readGyroscope. gyroX := (gyro at: 1)/131 asFloat round: 6. diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRotationXY.st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRotationXY.st index 55b0904..35b8ea4 100644 --- a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRotationXY.st +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRotationXY.st @@ -1,8 +1,8 @@ controlling readRotationXY - | accelerometerSkaliert rotation rotationX rotationY | - accelerometerSkaliert := self readAccelerometerSkaliert. - rotation := self calculateRotationX: (accelerometerSkaliert at: 1) Y: (accelerometerSkaliert at: 2) Z: (accelerometerSkaliert at: 3). + | 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 } \ No newline at end of file From db4d399bdffe0a6334892d339e83f9eb8ae2edce Mon Sep 17 00:00:00 2001 From: Allex Oliveira Date: Wed, 7 Aug 2019 12:09:22 +0200 Subject: [PATCH 3/4] initializing with wakeUpSensor method --- .../PotMPU6050Device.class/instance/connect.st | 3 ++- .../PotMPU6050Device.class/instance/wakeUpSensor.st | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/wakeUpSensor.st diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/connect.st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/connect.st index f4e2551..7da32b0 100644 --- a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/connect.st +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/connect.st @@ -1,4 +1,5 @@ controlling connect - super connect + super connect. + self wakeUpSensor diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/wakeUpSensor.st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/wakeUpSensor.st new file mode 100644 index 0000000..73cc413 --- /dev/null +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/wakeUpSensor.st @@ -0,0 +1,3 @@ +controlling +wakeUpSensor + i2cConnection write8BitsAt: 16r6b data: 0 \ No newline at end of file From b64f8058fc9daf6d85e15d39a17182fe6509ba8f Mon Sep 17 00:00:00 2001 From: Allex Oliveira Date: Thu, 8 Aug 2019 10:58:40 +0200 Subject: [PATCH 4/4] waking up the sensor while reading the registers --- .../PotMPU6050Device.class/README.md | 7 ++++++- .../PotMPU6050Device.class/instance/readRegisters..st | 4 ++++ .../PotMPU6050Device.class/properties.json | 6 ++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/README.md b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/README.md index 21f4ca7..d354b58 100644 --- a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/README.md +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/README.md @@ -16,4 +16,9 @@ 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)" \ No newline at end of file +readRotationXY. "#(-3.224775339993247 -2.4755961852044157)" + +sensor := (RpiBoard3B current) installDevice: PotMPU6050Device new. +sensor readRollPitchYaw +sensor printRollPitchYaw. +sensor finishRollPitchYaw. \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRegisters..st b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRegisters..st index 4cf95e0..cac92b7 100644 --- a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRegisters..st +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/instance/readRegisters..st @@ -3,5 +3,9 @@ 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 \ No newline at end of file diff --git a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/properties.json b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/properties.json index cec8529..f7f8722 100644 --- a/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/properties.json +++ b/src/PharoThings-Devices-MPU6050.package/PotMPU6050Device.class/properties.json @@ -1,11 +1,13 @@ { - "commentStamp" : "AllexOliveira 8/6/2019 17:51", + "commentStamp" : "AllexOliveira 8/7/2019 18:28", "super" : "PotI2CDevice", "category" : "PharoThings-Devices-MPU6050", "classinstvars" : [ ], "pools" : [ ], "classvars" : [ ], - "instvars" : [ ], + "instvars" : [ + "readProcess" + ], "name" : "PotMPU6050Device", "type" : "normal" } \ No newline at end of file