MATLAB: Can the Simulink model read data from an analog accelerometer plugged into the VEX microcontroller

accelerometeranalogdatadigitalmicrocontrollerreadsensorsimulink codervex

I have been using the Simulink Coder Support Package for VEX Microcontrollers, specifically blocks from the "sensors" library. All the sensors I've used in the past have had dedicated blocks in the library, such as the gyroscope and the ultrasonic sensor. However, I am now trying to read data from an analog accelerometer as well, but there is no accelerometer sensor block. How can I read the data from this sensor in my Simulink model?

Best Answer

The Simulink Coder Support Package for VEX does have some blocks that are sensor-specific for the most commonly used sensors - such as the ultrasonic sensor and the gyroscope blocks you have already used in your model. The support package also provides more generic blocks that let you interface with any sensor you plug into your digital or analog ports.
In this case, you have an analog accelerometer to plug into your VEX microcontroller. When plugged in, the accelerometer feeds data to 3 analog ports (one per axis). To read this data in your Simulink model, use the generic "Analog Input" block from the VEX sensors library, as shown in the screenshot below. If your accelerometer is plugged into analog ports 1, 2, and 3, this Simulink set-up would allow you to read the data from each of those ports. Note that you will need one analog input block per analog port used.