So i have a basic accelerometer that I'm reading, and its values are supposed to turn an LED on if they are over a specified threshold. However, when the arduino exceeds that threshold and the digitalwrite command fires, the program hangs. I'm using a nano clone (chinese driver is installed) and the sparkfun LIS3DH accelerometer breakout. I've successfully read values using I2C communication, but once I try to run LED's with those values everything breaks down.
Thoughts?
Try adding your own LED, with current limiting resistor, and use a different pin.
Try adding more Serial.print() statements, to get a better idea where the program "hangs".
spycatcher2k:
Google what pins are used for SPI on the Arduino, and a solution shall present itself.
The accelerometer is an I2C device. Where does SPI enter the picture?
That there was a misuse of an SPI pin was my first thought, and why I suggested using a different pin, and the device OP is using can be used in SPI or I2C mode, but the code he/she is using looks like it is in I2C mode (since the no-argument constructor defaults to I2C mode).
PaulS:
Explain how it is possible for that to happen.
A set threshold is compared against by the arduino (ie 1.23 float value). Actions happen when the input from the accelerometer exeeds it (1.5 float value)
[/quote]
PaulS:
The accelerometer is an I2C device. Where does SPI enter the picture?
That there was a misuse of an SPI pin was my first thought, and why I suggested using a different pin, and the device OP is using can be used in SPI or I2C mode, but the code he/she is using looks like it is in I2C mode (since the no-argument constructor defaults to I2C mode).
I'm using I2C mode, the #include "SPI.h" is just from the tutorial code header that I didn't bother changing.
PaulS:
Try adding your own LED, with current limiting resistor, and use a different pin.
Try adding more Serial.print() statements, to get a better idea where the program "hangs".
Same thing happens when using the onboard LED, I can keep testing other pins, but I'd like to know why this isn't working as it stands.
A set threshold is compared against by the arduino (ie 1.23 float value). Actions happen when the input from the accelerometer exeeds it (1.5 float value)
But that is not the same thing as "the arduino exceeds that threshold".
The sensor reading has. or has not, exceeded a threshold.
Same thing happens when using the onboard LED, I can keep testing other pins, but I'd like to know why this isn't working as it stands.
So we are left to guess which pins you tried. I'll guess that you tried 12, 11, and 10, and they caused problems, too.
Try some non-SPI pin, just for giggles.
And get rid of the #include statement for SPI.h, since you do not need it.
Switched to digital pin 2 and that solved the problem. I'd still like to know why the other pins don't work, my research hasn't yielded any reason why they shouldn't...
afrye:
Switched to digital pin 2 and that solved the problem. I'd still like to know why the other pins don't work, my research hasn't yielded any reason why they shouldn't...
Could you try all of the digital pins, and compile a list of the ones that cause, and the ones that do not cause, interference? Perhaps those lists will give us a clue.