Read accelerometer from raspberry pi
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello there :)
I am facing problems with reading values from a Bosch BMA280 Accelerometer connected to a raspberry pi via Matlab.
What is working so far:
- Raspberry Pi Support Package is installed
- Raspi is addressable via Matlab
- BMA280 Sensor is connected to Raspberry Pi via SPI 4-wire
- I can read several register via writeRead-Function (SPI) in Matlab (for example Chip ID, X-, Y-, Z-Data)
What I want to do:
- Use the BMA280 connected to the Raspi in Simulink
My problem is, I don't know where to start. I found device drivers on the bosch homepage in c-Code. Should I try to build my own device driver in matlab? Are there any better ways?
The other problem I am facing: The bosch sensor sends the X-, Y- and Z-Data in two's complement format. The matlab function "writeRead" (Raspberry support package) returns a row vector, which looks like this:

The technical documentation tells the user to first read the LSB-Register (here 0x04, which has to be 0x84 for reading values) and afterwards read the MSB-Register (0x05 -> 0x85). I don't know why I, but when I'm not including "hex2dec('0')", matlab reads only one register. Can anyone explain that to me? This would look like (0x84 should not be "0"!):

How do I convert the row vector returned by matlab to useful values?
Thanks so far.
Kind regards,
Niko
4 Kommentare
Joachim Schlosser
am 15 Apr. 2016
Yes, if you want to write the code yourself, go MATLAB Function. If you just want to re-use existing C functions, use Legacy Code tool.
On writeread: yes, this is how the writeread function seems to be proposed by the SPI standard.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Raspberry Pi Hardware finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!