Jump to content

Component: Accelerometer 3-Axis (MMA8452Q) (Movement Orientation): Difference between revisions

From Flowcode Help
No edit summary
No edit summary
Line 17: Line 17:
==Component Source Code==
==Component Source Code==


Please click here to download the component source project: [https://www.flowcode.co.uk/wiki/componentsource/FC_Comp_Source_Accelerometer_MMA8452Q.fcfx FC_Comp_Source_Accelerometer_MMA8452Q.fcfx]
Please click here to download the component source project: [https://www.flowcode.co.uk/wiki/componentsource/FC_Comp_Source_temp/Accelerometer_MMA8452Q.fcfx FC_Comp_Source_temp/Accelerometer_MMA8452Q.fcfx]


Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/FC_Comp_Source_Accelerometer_MMA8452Q.fcfx FC_Comp_Source_Accelerometer_MMA8452Q.fcfx]
Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/FC_Comp_Source_temp/Accelerometer_MMA8452Q.fcfx FC_Comp_Source_temp/Accelerometer_MMA8452Q.fcfx]


==Detailed description==
==Detailed description==
Line 80: Line 80:


''<span style="color:red;">No additional examples</span>''
''<span style="color:red;">No additional examples</span>''




Line 87: Line 89:
==Macro reference==
==Macro reference==


===Read_Register===
===CollectXYZData===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Read_Register'''
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''CollectXYZData'''
|-
|-
| colspan="2" | Reads a value from a register on the accelerometer.&nbsp;
| colspan="2" | Collect the data from the local accelerometer buffers. The Axis parameter specifies the Axis to be read. 0 / 'x' / 'X' - X axis 1 / 'y' / 'Y' - Y axis 2 / 'z' / 'Z' - Z axis&nbsp;
|-
|-
|-
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | Reg
| width="90%" | Axis
|-
|-
| colspan="2" | Register address to read from&nbsp;
| colspan="2" | &nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-s16-icon.png]] - INT
| width="90%" style="border-top: 2px solid #000;" | ''Return''
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
|}




===SimReset1G===
===Initialise===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SimReset1G'''
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Initialise'''
|-
|-
| colspan="2" | Resets the simulation to 0.0 on X and Y and 1.0 on Z as if the accelerometer was sitting completely horizontal.&nbsp;
| colspan="2" | Sets up up the communication bus and initialises the accelerometer module. Returns 0 for success and > 0 for fail.&nbsp;
|-
|-
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" style="border-top: 2px solid #000;" | ''Return''
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
|}




===Write_Register===
===Read_N_Registers===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Write_Register'''
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Read_N_Registers'''
|-
| colspan="2" | Reads a set of data values from sequential registers on the accelerometer&nbsp;
|-
|-
|-
| colspan="2" | Writes a data value to a specific register on the accelerometer&nbsp;
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | Start_Reg
|-
|-
| colspan="2" | First address to read data from&nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | Reg
| width="90%" | Num_Regs
|-
|-
| colspan="2" | Register Address to Write to&nbsp;
| colspan="2" | Number of registers to read&nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | Data
| width="90%" | data
|-
|-
| colspan="2" | Value to write to the register&nbsp;
| colspan="2" | Data variable to populate with the register values&nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
Line 144: Line 151:




===CollectXYZData===
===Read_Register===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''CollectXYZData'''
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Read_Register'''
|-
|-
| colspan="2" | Collect the data from the local accelerometer buffers. The Axis parameter specifies the Axis to be read. 0 / 'x' / 'X' - X axis 1 / 'y' / 'Y' - Y axis 2 / 'z' / 'Z' - Z axis&nbsp;
| colspan="2" | Reads a value from a register on the accelerometer.&nbsp;
|-
|-
|-
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | Axis
| width="90%" | Reg
|-
| colspan="2" | &nbsp;
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-s16-icon.png]] - INT
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
 
 
===UpdateXYZData===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''UpdateXYZData'''
|-
| colspan="2" | Reads from the accelerometer and updates the local XYZ variables. Returns 1 for new data and 0 for no new data&nbsp;
|-
|-
| colspan="2" | Register address to read from&nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
Line 177: Line 170:




===Read_N_Registers===
===SimReset1G===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Read_N_Registers'''
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''SimReset1G'''
|-
|-
| colspan="2" | Reads a set of data values from sequential registers on the accelerometer&nbsp;
| colspan="2" | Resets the simulation to 0.0 on X and Y and 1.0 on Z as if the accelerometer was sitting completely horizontal.&nbsp;
|-
|-
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | Start_Reg
|-
| colspan="2" | First address to read data from&nbsp;
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | Num_Regs
|-
| colspan="2" | Number of registers to read&nbsp;
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | data
|-
| colspan="2" | Data variable to populate with the register values&nbsp;
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
Line 235: Line 213:




===Initialise===
===UpdateXYZData===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Initialise'''
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''UpdateXYZData'''
|-
|-
| colspan="2" | Sets up up the communication bus and initialises the accelerometer module. Returns 0 for success and > 0 for fail.&nbsp;
| colspan="2" | Reads from the accelerometer and updates the local XYZ variables. Returns 1 for new data and 0 for no new data&nbsp;
|-
|-
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
===Write_Register===
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Write_Register'''
|-
| colspan="2" | Writes a data value to a specific register on the accelerometer&nbsp;
|-
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | Reg
|-
| colspan="2" | Register Address to Write to&nbsp;
|-
| width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE
| width="90%" | Data
|-
| colspan="2" | Value to write to the register&nbsp;
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-void-icon.png]] - VOID
| width="90%" style="border-top: 2px solid #000;" | ''Return''
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
|}

Revision as of 11:59, 3 February 2023

Author Matrix Ltd.
Version 2.0
Category Movement Orientation


Accelerometer 3-Axis (MMA8452Q) component

MMA8452Q Accelerometer sensor with I2C. Useful for approximating Pitch and Roll or for detecting acceleration.

Component Source Code

Please click here to download the component source project: FC_Comp_Source_temp/Accelerometer_MMA8452Q.fcfx

Please click here to view the component source code (Beta): FC_Comp_Source_temp/Accelerometer_MMA8452Q.fcfx

Detailed description

No detailed description exists yet for this component

Examples

No additional examples




Macro reference

CollectXYZData

CollectXYZData
Collect the data from the local accelerometer buffers. The Axis parameter specifies the Axis to be read. 0 / 'x' / 'X' - X axis 1 / 'y' / 'Y' - Y axis 2 / 'z' / 'Z' - Z axis 
- BYTE Axis
 
- INT Return


Initialise

Initialise
Sets up up the communication bus and initialises the accelerometer module. Returns 0 for success and > 0 for fail. 
- BYTE Return


Read_N_Registers

Read_N_Registers
Reads a set of data values from sequential registers on the accelerometer 
- BYTE Start_Reg
First address to read data from 
- BYTE Num_Regs
Number of registers to read 
- BYTE data
Data variable to populate with the register values 
- VOID Return


Read_Register

Read_Register
Reads a value from a register on the accelerometer. 
- BYTE Reg
Register address to read from 
- BYTE Return


SimReset1G

SimReset1G
Resets the simulation to 0.0 on X and Y and 1.0 on Z as if the accelerometer was sitting completely horizontal. 
- VOID Return


SimSetXYZ

SimSetXYZ
Allows the XYZ slider values to be set via the simulation 
- INT X
 
- INT Y
 
- INT Z
 
- VOID Return


UpdateXYZData

UpdateXYZData
Reads from the accelerometer and updates the local XYZ variables. Returns 1 for new data and 0 for no new data 
- BYTE Return


Write_Register

Write_Register
Writes a data value to a specific register on the accelerometer 
- BYTE Reg
Register Address to Write to 
- BYTE Data
Value to write to the register 
- VOID Return



Property reference

Properties
Bit Depth
The number of binary bits used to store the sensor's X,Y,Z readings. 
Scale
The accelerometer readings are scaled based on the maximum amount of G force the sensor can represent. 6G = Bigger gravitational force 2G = Higher resolution 
Data Rate
 
Int Option
Sets if we use the interrupt pin to check if new data is available 
Connections
Device Address
 
I2C Connections
Channel
Channel selection 
Baud Select
Baud rate option selector 
Baud Rate
Baud rate to be used 
SDA
Pin used for SDA (data signal) 
SDA Remap Pin
 
SCL
Pin used for SCL (clock signal) 
SCL Remap Pin
 
Stop Delay
On older microcontroller devices there is a potential for the I2C hardware channel to lock up if there is not a 10ms delay between an I2C stop event and the next I2C start event. Most modern microcontrollers will not have a problem so this property can be disabled to speed up the I2C communications.  
Simulation
Simulate Comms
Yes: Accelerometer data will come from the simulation component sliders. No: Accelerometer data will come from the CAL component - I2C or SPI - API etc