Reading Multiple Sensors Simultaneously

Thread Starter

Johnny1010

Joined Jul 13, 2014
96
Hi everyone,

I have 2 sensors connected to my arduino one is the invensense mpu6050 and the other is a force sensor. I am using the i2cdev library by jeff rowberg for the mpu6050. Now I am sequentially reading the values of mpu and those of the force sensor. Whenever I tap the force sensor very fast the values are skipped because I think at that moment the controller is busy reading values from the mpu. I measured the time taken by the function for reading the mpu is around 10ms. When I stop reading the mpu no matter how fast I tap the sensor there is no value left off.

What I want is the value of the mpu and the bend sensor at a given time instance.

Can anybody suggest a possible solution for this?
 

AlbertHall

Joined Jun 4, 2014
12,345
The only way to read multiple sources simultaneously with one micro is if one of the sensors can be triggered and then while it is making its measurement the micro reads the other one then fetches the result of the triggered measurement. I haven't used the MPU6050 but a quick skim tells me that it has a FIFO in which it can store readings to be retrieved later by the micro. Maybe that can solve the problem.
 

dannyf

Joined Sep 13, 2015
2,197
The answer depends on your definition of "simultaneously".

If you meant to use it literally here, you will need two mcus and you will need to see if the chips can be sampled on command and then read back later.

If you meant to say that you want to read the chips sufficiently fast so as to almost simultaneously to a human, that's a different ask and certainly can be done easily.
 

atferrari

Joined Jan 6, 2004
4,764
The answer depends on your definition of "simultaneously".

If you meant to use it literally here, you will need two mcus and you will need to see if the chips can be sampled on command and then read back later.

If you meant to say that you want to read the chips sufficiently fast so as to almost simultaneously to a human, that's a different ask and certainly can be done easily.
No idea if those arduinos could do what some PICS in the 18F family: simultaneous ADC followed by successive writing of the target registers with the results.
 

DickCappels

Joined Aug 21, 2008
10,153
Arduinos use Atmel ATMEGA controllers with execution rates of 1 instruction every one or two clocks, depending upon the instruction. Run it at 16 MHz and that's 1 instruction ever 63 nanoseconds for most instructions (Jumps and Branches can take three, if I recall correctly). Of course with the Arduino software and the C compiler underneath it, the code might not be nearly as tight as you could get by using an assembler directly.

It might just be a matter of re-arranging your code. If there is the need to wait for a measurement, use interrupts so you can be doing other things rather than waiting around for data. An easy way to do that is to use a timer to periodically interrupt whatever is going on and jump to the next task -check out preemptive multitasking.
 

atferrari

Joined Jan 6, 2004
4,764
Arduinos use Atmel ATMEGA controllers with execution rates of 1 instruction every one or two clocks, depending upon the instruction. Run it at 16 MHz and that's 1 instruction ever 63 nanoseconds for most instructions (Jumps and Branches can take three, if I recall correctly). Of course with the Arduino software and the C compiler underneath it, the code might not be nearly as tight as you could get by using an assembler directly.

It might just be a matter of re-arranging your code. If there is the need to wait for a measurement, use interrupts so you can be doing other things rather than waiting around for data. An easy way to do that is to use a timer to periodically interrupt whatever is going on and jump to the next task -check out preemptive multitasking.
So, the most "simultaneous" readings that way, how long would take, Dick? No experience with Atmel.
 

dannyf

Joined Sep 13, 2015
2,197
No idea if those arduinos could do what some PICS in the 18F family: simultaneous ADC followed by successive writing of the target registers with the results.
That would require two independent adc modules, or at least two sample-and-hold units.

No PIC18s have that. No AVRs (8-bit) have that as well. Some PIC24/dsPIC do.
 

dannyf

Joined Sep 13, 2015
2,197
The OP's probably, however, is slightly different. He's reading / writing to mpu6050 (via i2c) is too slow - 10ms.

The solution is actually much simpler than being discussed.
 

atferrari

Joined Jan 6, 2004
4,764
That would require two independent adc modules, or at least two sample-and-hold units.

No PIC18s have that. No AVRs (8-bit) have that as well. Some PIC24/dsPIC do.
The last PIC I was using before moving to this house, takes simultaneous readings. I should look which one is. To read (and process the readings, of course) it is you that goes sequentially with your code.
 

ErnieM

Joined Apr 24, 2011
8,377
You will still miss events no matter how fast one reading is if you access the reading thru I2C. It takes a not insignificant time to get the data from the perf to the processor.

You may want to add a peak detector between the sensor and the A2D to preserve that high tap value. Once you read the value your processor can reset the peak level... Though you may still loose an event there. Only go this way if the intensity of the tap needs be captured.

An even simpler way is to amplify the senors up to a digital level and use an interrupt to capture the tapping event. You loose amplitude info but get all the events.

A combination of the two methods may be necessary.
 

Thread Starter

Johnny1010

Joined Jul 13, 2014
96
Guys MPU6050 has an inbuilt DMP which implements some sort of algorithm for the data fusion and this is what takes most of the time and I can't sample from the DMP more than 100 Hz. So, basically this 100 Hz is stopping me from sampling the other sensor at a higher rate.
If I sample the raw accelerometer and gyro values leaving the dmp out I could sample at 1000 Hz. Now, if I apply a complementary filter myself what do you guys think would that be faster?
 

Picbuster

Joined Dec 2, 2013
1,047
Hi everyone,

I have 2 sensors connected to my arduino one is the invensense mpu6050 and the other is a force sensor. I am using the i2cdev library by jeff rowberg for the mpu6050. Now I am sequentially reading the values of mpu and those of the force sensor. Whenever I tap the force sensor very fast the values are skipped because I think at that moment the controller is busy reading values from the mpu. I measured the time taken by the function for reading the mpu is around 10ms. When I stop reading the mpu no matter how fast I tap the sensor there is no value left off.

What I want is the value of the mpu and the bend sensor at a given time instance.

Can anybody suggest a possible solution for this?
The mpu6050 is the slowest ( in reaction time) use SPI bus and the trigger output to do two things;
1:read force sensor use an interrupt to speed up.
2:read mpu6050 via spi @ highest possible rate. (value is in output registry and clocked out when addressed)
You introduce a time delay, depending on program and cpu speed, between 1 and 2.
picbuster
 
Top