I am trying to implement the kit accelerometer, and I started by basing it off of the HiTechncCompass class from last years code. (I can’t find the newest version, but I doubt that class has changed). The problem I am having is when I try to initialize the I2C in my robot constructor, the constructor does not finish and the robot stops responding. The console output from the serial port also does not give me any errors either. Here is the class I started, with simple functions just to see what I can get out of it:
I am working on the same project with my team ::ouch:: and play to modify the compass code to get me started. I am hoping the I2C code is good so I can concentrate on the accelerometer.
At first glance of the data sheet for the adxl345 it appears we will need to add more code that just the read of one register. Data is in 3 different registers at addresses 0x32 to 0x37 in a two’s complement format so I would guess that returning a float from the read is the wrong choice. The compass may return a float but not the accelerometer. (this is what if get from the data sheet anyway).
We will probably have to trigger a sampling of some sort before the read.
I am not sure how the chip select is getting set or what the address is on the acclerometer. I’ll start by assuming the chip is always selected and the address is zero (0).
As far as your code goes the only address I recognized is the power control register, not sure where you got the other ones. there not on my data sheet.
I’ll keep you posted on what I find this weekend. And look forward to what others have to say.
I had a little more time to dig into the data sheet and can see where you got address 3a and 3b from. It is the result of adding the r/w bit to the 7 bit address. From looking at the I2C code I wonder if it twittles that read write bit for you. I wonder if the address they are really looking for there is 0x1D.
If you want to work this out off line my email address is [email protected]
One last thing…Don’t try to turn on the measurement bit in the constructor.
There may be other objects associated with the I2C stuff that hasn’t been constructed yet. Create an init method where you do the write and call it after you are sure all the construcing is done, like the first part of your main loop.
Yeah the address given in the Sensor Guide says 0x3A, and I figure its all in 8bit for the WPI Function, so the 0x1D wouldn’t work with that but 0x3A would?? I really don’t know I2C or WPI’s implementation of it, so I don’t really know. I’m going to keep playing with it tonight.
I also just found the register map, didn’t see it in the datasheet when I worked on it last, don’ know how I missed it.
The biggest issue I am having now is whenever I call the read or write function the robot freezes up, and my console output shows nothing. This is both when I try to perform a read or a write…
I am still new to this environment that FIRST has set up for us so please excuse my ingnorance…Where do I find the labview example for I2C. Right now I am set up to write C++ code using the WPI library and the windriver tools…I have no experience with labview…not even sure I have it installed…
Naturally you need LabVIEW installed. Just run it from the start menu and in the getting started window that pops up on the bottom right there is a short list of examples… click on more examples and look for ADXL345 I2C Accelerometer.
I did find an issue with the initial release of the I2C for this year. The bug was introduced since last year. See details here: http://firstforge.wpi.edu/sf/go/artf1144
This bug would prevent the accelerometer from working.
Yippeee!! everything is finally working…We re imaged the Crio, made sure ‘ALL’ the updates were applied to the driver station and the development laptop, compiled then downloaded the BuiltinDefaultCode.out file.
Then we added Joe’s accelerometer code and fixed the I2C.cpp file. and all still worked.
We had some problems with the IterativeDemo but I we’ll revisit that later. The BuiltinDefaultcode is what we will base our robot code on.
Thanks to all especially Joe Hersh for all the info and his patience…They don’t pay you enough…Every one should send Joe a starbucks gift card so he can buy enough coffee to keep him awake when he sending those responses at 3 AM…:ahh:
We attached an oscilloscope to the bus and noticed that the data returned from the slave accelerometer is 0 for all three transactions (x, y, z); could it be attributed to some sort of a power saving feature which is not disabled?
Download the source code, change the logical OR to a bitwise OR, build the library, run the Scripts/updateBuiltInLibrary.cmd file to install the compiled library, rebuild your project.