Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
101d87da
Commit
101d87da
authored
Aug 10, 2014
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
stmhal: Working STM32F4DISC accelerometer, via Python script.
Thanks to David Siorpaes.
parent
4ef26c14
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
stmhal/boards/STM32F4DISC/staccel.py
+18
-4
18 additions, 4 deletions
stmhal/boards/STM32F4DISC/staccel.py
with
18 additions
and
4 deletions
stmhal/boards/STM32F4DISC/staccel.py
100644 → 100755
+
18
−
4
View file @
101d87da
...
...
@@ -2,8 +2,8 @@
Driver for accelerometer on STM32F4 Discover board.
Assumes it
'
s a LIS302DL MEMS device.
Not currently working
.
Sets accelerometer range at +-2g.
Returns list containing X,Y,Z axis acceleration values in
'
g
'
units (9.8m/s^2)
.
See:
STM32Cube_FW_F4_V1.1.0/Drivers/BSP/Components/lis302dl/lis302dl.h
...
...
@@ -22,12 +22,22 @@ READWRITE_CMD = const(0x80)
MULTIPLEBYTE_CMD
=
const
(
0x40
)
LIS302DL_WHO_AM_I_ADDR
=
const
(
0x0f
)
LIS302DL_CTRL_REG1_ADDR
=
const
(
0x20
)
LIS302DL_OUT_X
=
const
(
0x29
)
# Configuration for 100Hz sampling rate, +-2g range
LIS302DL_CONF
=
0b01000111
def
signed8
(
x
):
if
x
&
0x80
:
return
x
-
256
else
:
return
x
class
STAccel
:
def
__init__
(
self
):
self
.
cs_pin
=
Pin
(
'
PE3
'
,
Pin
.
OUT_PP
,
Pin
.
PULL_NONE
)
self
.
cs_pin
.
high
()
self
.
spi
=
SPI
(
1
,
SPI
.
MASTER
,
baudrate
=
328125
,
polarity
=
0
,
phase
=
1
,
bits
=
8
)
self
.
wr
(
LIS302DL_CTRL_REG1_ADDR
,
bytearray
([
LIS302DL_CONF
]))
def
rd
(
self
,
addr
,
nbytes
):
if
nbytes
>
1
:
...
...
@@ -52,5 +62,9 @@ class STAccel:
def
read_id
(
self
):
return
self
.
rd
(
LIS302DL_WHO_AM_I_ADDR
,
1
)
def
init
(
self
,
init_param
):
self
.
wr
(
LIS302DL_CTRL_REG1_ADDR
,
bytearray
([
init_param
]))
def
get_xyz
(
self
):
val
=
self
.
rd
(
LIS302DL_OUT_X
,
5
)
x
=
signed8
(
val
[
0
])
*
18.0
/
1000
y
=
signed8
(
val
[
2
])
*
18.0
/
1000
z
=
signed8
(
val
[
4
])
*
18.0
/
1000
return
[
x
,
y
,
z
]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment