I am trying to modify libraries that are in Arduino for this IMU sensor: MinIMU-9 v3 Gyro, Accelerometer, and Compass (L3GD20H and LSM303D Carrier)
Here are the library links for LSM 303D and L3GD20H
I like how this sensor is really small and would like to use this in a setup with the photon.
I am a newbie for photon and new to writing these kinds of libraries. Can someone suggest if changing the Arduino libraries and include files is possible, and how to get started?
It uses the i2c interface, but if possible I would also change it to use other input ports as I plan to attach around 4 of these IMU sensors to a single photon( 8 input pins needed).
Else if this is a very time taking library modification job, is there other tiny IMU sensors(less than 2cm square) with libraries already integrated with photon?
Any experts, willing to take up this conversion job? It isnt really my area of expertise, I am just trying to use photon for data collection…
I2C is a bus protocol that allows for multiple devices connected only using two pins.
The only requirement there is that each device is individually addressable - some sensors allow for different addresses for exactly that reason to have multiple of the same sort on one bus.
For porting libraries there are some threads to get you started
Porting from Arduino to Particle.io (Simplified-Hopefully)
[solved] Porting from Arduino to Particle
If you get stuck, just shout out
I wish I had got the Pololu one at about $11, it is cheaper and I like Pololu. I got the 9 Axis Accelerometer from RobotShop about $40 http://www.robotshop.com/ca/en/hovis-gyro-accelerometer-sensor.html I have to set it up for my class so I will try to port it next, I will try to share the info here since the porting may be similar for the two devices.
A quick look at yours the L3G.h file at . https://github.com/pololu/l3g-arduino/blob/master/L3G/L3G.h
#include <Arduino.h> // for byte data type
#include <Particle.h> // for byte data type
You will have to remove
#include <Wire.h> from the main .ino as well.
As for the Photon PIN connections, I always sweat over these, perhaps @ScruffR can make some suggestions. Also a good idea to find out if you need resistors on the communication wires (Most likely not as yours is a 3V device I think).
If you have issues with data types perhaps send @peekay123 a note to have a look at it.
The wiring of multiple of these boards to the bus could be a bit tricky for two reasons.
First the board only supports two different sets of IDs via SA0 and second each board has its own set of pull-up resistors which will in parallel drop the pull-up resistance to 2k5 (with four boards - still within specs tho’).
A possible way around both is to supply the boards via digital pins on Vdd (e.g. one permanent via 3V3 and SA0 pulled low, and three others via their own mutually exclusive digital pin and SA0 open).
Allow a few microseconds after power up of the sensor before reading the data.
@rocksetta, for I2C this is not a question of voltage but rather if the sensor comes with resistors or not, since I2C always need pull-up resistors on SCL/SDA and no in-line resistors
Thanks for the links and help. I managed to port the library for the gyroscope, L3GD20H. I made the changes suggested by rocksetta. Then also included math.h. It compiled successfully and I managed to flash the photon. I can now get the gyrsocope x,y,z readings (using CLI: particle serial monitor). However even when not moving, the readings arent close to zero ( gyroscope not moving should so readings of 0 in all xyz values?). I am getting something like consistently when not in movement.
G X: -173 Y: -1140 Z:112
When moving 1 or more of the xyz values would jump to 1000+ and change.
Could it be some datatype problems? Any insights?