From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
01-29-2014 02:52 PM
Hello folks,
I was wondering if perhaps I could get some assistance in regards in communicating with the sparkfun ADXL345 accelerometer through the myRIO. So far, my attempts to communicate with the accelerometer has not gone very well, and I'm getting an error message saying that I'm receiving a NACK from the accerlometer. I have tried it only through the I2C as that seems to be the most simple setup according to the accelerometer's datasheet. I believe my main issue is how to handle the slave address and then point to the proper register locations. Below, is a link to the accelerometer datasheet (Page 10 shows the I2C setup and a figure showing how data is sent from the control device and theaccelerometer).
https://www.sparkfun.com/datasheets/Sensors/Accelerometer/ADXL345.pdf
I've only tried writing to the accelerometer as some registers need an initialized value.
01-30-2014 01:35 PM - edited 01-30-2014 01:39 PM
Hey DragoTheWise,
Here is a quick shot at the code to read from the ADXL345.
I don't have the sensor to test with so let us know if that works or if you have additional questions.
-Sam K
Join / Follow the LabVIEW Hacker Group on google+
02-02-2014 08:07 PM
Hey Sammy,
Thanks for the help; however, I was still unable to read data from the device. With the setup you gave me, I was getting a NACK from the accelerometer. I tried toying with the setup on both software and with the hardware, but I didn't get anything different. Any other suggestions?
Thanks,
~Drago
02-03-2014 09:10 AM
Hey Drago,
What value pull up resistors are you using?
It also looks like you'll have to bring the device out of standby mode by writing 0b00001000 to register 0x2D.
Let us know if that works (Sorry, I can't test it since I don't have the device)
-Sam K
Join / Follow the LabVIEW Hacker Group on google+
02-03-2014 07:16 PM
Hey Sammy,
I'm currently using 2.2k ohmn resistors. I did play around with the values some just to see if anything different would happen. It seems like anything below 1k causes issues. Now, concerning the code. I first checked the first code you gave me once again and somehow it works to an extent (maybe a wire was out of place before). It'll run and not spit out any errors; however, I consistently get 0's for the data. So it seems like it is able to fully communicate with the device, but can't collect the data properly which is what the latest code was to fix. Now, for the recent one, I tried it out and I end up getting a different error : -363002. It says that the channel that was specified is incorrect. This happens on the part of the code trying to write to the 0x2D register to go into "Measure" mode. I'm not sure why that is an incorrect channel as that is the correct slaveaddress of the device and the register. I looked through the accelerometer data sheet again, and I don't see an issue with the current setup. Perhaps we are overlooking something? Thank you again for the time and effort for helping me.
~Drago
02-04-2014 08:59 AM
Hey Drago,
If you open the express VIs you'll notice that the channel drop down is empty. That is because I opened and saved it outside of the myRIO context without thinking about it. Just open each express VI and choose the appropriate I2C channel and run it again.
-Sam K
Join / Follow the LabVIEW Hacker Group on google+
02-05-2014 01:48 PM - edited 02-05-2014 01:49 PM
Hey Sammy!
Thanks for pointing that out. On my side, it showed the correct channel, but I suppose it didn't generate the code quite right. So after I switched to B and then back to A, everything started to work perfectly. Thank you for all your help!
~Drago
02-05-2014 02:59 PM
Happy to help. The data sheet has everything you need to know, but it can be a challenge to read them some times.
If you have any questions about how / why any of the code works the way it does let me know.
Thanks!
-Sam K
Join / Follow the LabVIEW Hacker Group on google+
03-16-2014 10:13 AM
hi Sam,
The accel read VI is working but data is insignificant. there is't any nagative data. how can i convert to +g and -g data type?
Thank you..
Harun TURAN
03-17-2014 09:32 AM
The sensor returns data in 2's Compliment as noted in the data sheet. Check out the wikipedia page if you're not famliar with 2's Compliment.
I have a VI in the LabVIEW Hacker toolbox that converts from 2's Compliment to decimal (for U16s only, but thats what you need in this case).
You can grab it from the LVH GitHub repository (direct download here)
Let us know if that works.
-Sam K
Join / Follow the LabVIEW Hacker Group on google+