Hello!
Today’s example builds on our earlier . Here we are using a three axis accelerometer as a digital level. The level reads the X, Y, and Z acceleration to determine the orientation.
Hardware used:
- CY8CKIT-042 Pioneer Kit
- 3-Axis Accelerometer
Forum Post Attachments:
At the bottom of this post we are including the following items:
- Example Project Zip File
- Zip File of Images
- Project Schematic
- Component Configurations
Components Used:
The user can download the example project at the bottom of this post. The project uses the following list of Creator Components:
- PWM
- UART
- I2C
- CyClock
- CyPin
The components are configured by right clicking on the component in your Top Design schematic view and selecting Configure. Please enable the following selections in the Configuration windows for the listed components above.
Firmware Description:
The main.c firmware is included in the example project. Please review the commented sections for more details.
In this example we are implementing a level using a three axis I2C accelerometer. The firmware reads X, Y, and Z acceleration, filters the values, and calculates orientation relative to horizontal and 45 degrees. The project then sets the color of the RGB LEDs based on how close the orientation is to ideal. The project also prints out a raw acceleration value to the UART which can be used to display on a hyperterminal software or the Bridge Control Panel.
In this example we use the interrupt output of the accelerometer to prompt communication. It also detects when the configuration of the sensor is lost, and reconfigures it. This can happen when the device is power cycled during operation.
Hardware Connections:
For this example plug the Sparkfun three axis accelerometer breakout board into the J3 header, pins 1-6. You may need to solder wires or a header to the accelerometer. In our example we connected the accelerometer to a six pin cable. This allowed us to move the accelerometer around while holding the pioneer kit in our other hand. Please be careful of the orientation of the ribbon cable, if you reverse the polarity on the accelerometer you may cause damage to the device.
Test Your Project:
Connect your hardware and program the kit. Take the accelerometer and set it on a flat surface. Notice the LED begin to change color and then glow a bright green when on a level surface.
I hope this example can help you in your design.
Best,
Matt


