I think perhaps the word “tutorial” is a rather grand title for what follows, but it’s my first attempt, either at making something like this, or at sharing my exploits.
So I bought a couple of 3-axis accelerometers for cheap cheap and had them wired up to the Arduino, trying to get them working, when it occurred: wouldn’t it be nice if there weren’t a pile of wires trailing everywhere, if it was easy to plug and unplug, and if it could even communicate wirelessly with a PC? Luckily I’m not the first person to think this, and someone cleverly invented the concept of a shield. As far as I can gather no-one sells an accelerometer shield, and anyway, where’s the fun in buying one?
I was happy for the accelerometer to be soldered to the board, having it sit in a female header would have made the board too high to stack. I did want the BT module to be removable though so that’s where the right-angled header would come in. The first step was to have a think about where best to put everything, including having the various pins in convenient places to wire to each other without it turning into a dog’s breakfast (well at least not too much of one). This done I plugged the MMA7361 into the board and heated up the iron.
|MMA7631 Pins||Arduino Pins|
|X (X-axis output)||A0 (analog input)|
|Y (Y-axis output)||A1 (analog input)|
|Z (Z-axis output)||A2 (analog input)|
|SL (sleep select)||Pin 2 (digital output, keep this HIGH to keep it awake)|
|0G (zero-gravity detect)||Not connected (used to test if e.g. a HDD has been dropped)|
|5V (power)||5V (chip is 3.3V but the breakout board has a regulator and is happy with 5V)|
|3.3V||AREF (used as a reference to make analog reads more accurate, can be left disconnected) NB: if using thus you must declare analogReference(EXTERNAL); before doing a digitalRead() or the Arduino can be damaged|
|GND (ground)||GND (ground)|
|GS (g-select)||Pin 3 (digital output, set LOW for 1.5g scale or HIGH for 6g. Defaults to 1.5 g)|
|ST (self test)||Not connected|
At this stage I soldered on the right-angled header for the Bluetooth module as I wanted to get a clear idea where the wires would end up.
|Bluetooth Module Pins||Arduino Pins|
|VCC (power)||5V (or 3.3V, power)|
|GND (ground)||GND (ground)|
|TXD (transmit)||Pin 0 (Rx, receive)|
|RXD (receive)||Pin 1 (Tx, transmit)|
Now just a case of wiring it all up. Easy on the poor soldering harassment please, I’m kind of new to this stuff. I’m sure there must have been a cleverer way to route all the wires but TBH I didn’t want to spend all afternoon thinking about it.
I chose to put the stackable headers in last and this was a good move, made it much easier to work on the wiring. The easiest way to make sure everything lines up when soldering stuff like this is to stick the pins in some holes, or vice versa, so I plugged another shield into the top of the headers whilst I did so. The Panavise makes it very easy to do this sort of thing and I’ll post a very brief review shortly.
And that was pretty much it. Plugged it in and amazingly it worked. I’ve managed to get a reading of g out of it and I want to write the calibration routine, I’ll post the code when its done.
What do you think? Any questions or suggestions, leave a comment below.