Hello,
I got my ND+ working with an ADXL345 accelerometer via I2C. I have needs to sample accelerations above 1 KHz for vibration analysis purpose, but I didn't get to it so far.
My current testing code makes 1000 cycles of readings saving start time and end time.
What I see is that if I set I2C to 400 KHz I get 2.6 ms per cycle, while setting I2C to 100 KHz I get 3.3 ms.
This brings me supposing that there is a 2.4 ms per cycle overhead outside of I2C communication time.
Is it possibile that Netduino take so long to manage I2C and saving incoming data to memory ( I'm using I2CDevice from NetMF 4.2 )?
I'm thinking that it's due to debugger. Even if I set the project to 'Release' configuration Output window start saying 'Found debugger!' and prints every Debug.Print.
May I have to deploy in other ways to exclude debugger and save times?
I2C and ADXL345 maxing sample rate
Started by
Ferocildo
, Jun 16 2012 06:45 PM
6 replies to this topic
#1
Posted 16 June 2012 - 06:45 PM
#2
Posted 08 August 2012 - 05:39 PM
Good question. Did you ever get it answered? Can you post your code? I'd lke to hook into an ADXL345 via I2C as well.
#3
Posted 10 August 2012 - 10:50 AM
Have you tried simply commenting out the Debug.Print statements or the majority of them. During early testing with my sensors I was running into a similar issue. Ended up having to move to adding an LCD earlier than I wanted just so I could write some values out and I removed the Debug.Print statements. While I haven't measured the time/cycle I do know it significantly increases in my case.
#4
Posted 10 August 2012 - 11:29 AM
Unfortunately, Debug.Print() calls get always compiled, unlike System.Diagnostics.Debug class methods which are decorated with Conditional attribute. You can wrap them in your own Debug class that has Conditional attributes, like shown in the following post.Even if I set the project to 'Release' configuration ... prints every Debug.Print.
#5
Posted 22 August 2012 - 05:35 PM
@Bendage
Here: https://www.loveelec...how-to-use-them
you can find anything you need to get ADXL345 working.
Anyway, to reach 1 KHz sampling rates I made some tweaks
Here: https://www.loveelec...how-to-use-them
you can find anything you need to get ADXL345 working.
Anyway, to reach 1 KHz sampling rates I made some tweaks
using System; using System.IO; using System.Net; using System.Net.Sockets; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.IO; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.NetduinoPlus; using LoveElectronics.Sensors.Accelerometers; namespace ADXL345_test { public class Program { private const int nSamples = 2048; private static byte[] bufArray = new byte[nSamples * 6]; private static byte[] buffer = new byte[6]; private static byte[] addrbuffer = new byte[] { 0x32 }; private static I2CDevice.I2CTransaction[] transaction = new I2CDevice.I2CTransaction[] { I2CDevice.CreateWriteTransaction(addrbuffer), I2CDevice.CreateReadTransaction(buffer) }; public static void Main() { OutputPort led = new OutputPort(Pins.ONBOARD_LED, false); ADXL345 accel = new ADXL345(); // Ensure that we are connected to the accel // (this will throw an exception if the accel does not respond). if (accel.EnsureConnected()) { Debug.Print("ADXL345 was found!"); } // Tell the accel we are interested in a range of +/- 2g. accel.Range = 2; // Tell the accel we want it to use full resolution. accel.FullResolution = true; // Enable the measurements on the device. accel.EnableMeasurements(); // Set the data rate to output at 3200Hz accel.SetDataRate(0x0F); while (true) { for (int i = 0; i < nSamples; i++) { // Get the newest data from the accelerometer. // Manually getting readings instead of accel.ReadAllAxis() // bufArray contains x, y and z packed on 6 bytes accel.Execute(transaction, 1000); buffer.CopyTo(bufArray, i * 6); } } } } }
#6
Posted 25 August 2012 - 08:32 PM
Thank you Ferocildo!
#7
Posted 15 April 2014 - 02:04 PM
The www.loveelectronics.co.uk site seems to be down. Can anyone share the ADXL345 library at some other site
- Esben likes this
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users