Tilt #1

I want to add a tilt feature. Not because it's needed, but because I like to practice my mojo with a limit. I've got a bunch of tilt mechanisms, but they all need refurbishing, and I've had enough of that for a while; so I says to myself...
Why not build an electronic tilt mechanism?
As usual, this was a stupid idea - not only was it not easy, it was not fun, and it's not even done.
To start with I needed an accelerometer. I selected the ADXL345 chip, on a board often labelled GY-291 (mine isn't).
Here's a picture of it with a JST 8 pin connector attached instead of the usual headers.

❗ So the first part of the cautionary tale is voltage. Some vendors will advertise 5 volt operation, but that's a little tricky as they often mean 5 volt supply, not 5 volt inputs. Some units have voltage-shifting devices fitted to them so they can work on 3.3 or 5 volts, but most don't. Mine will run from 5 but needs 3.3 inputs (which is pretty common) so I shall use a 3V3 microcontroller to save all that level-changing nonsense.
Moving on, we sort out Chip Select and I2C mode, so we can talk to the chip - not so hard, except it never seemed to work.

I hooked the accelerometer up to this beast, loaded some popular code, and got errors galore™️ and an occasional something-that-looked-promising. As it happens, the something-that-looked-promisings were just more errors.
I loaded some I2C diagnostic software, and the ESP32 could find the ADXL345 right enough, it just couldn't talk to it. Many hours of fiddling did not help. I went to bed.
The next day I had a look in my microcontroller box and found that while I had plenty of microcontrollers, I didn't want to solder them up because I'd not be able to reuse them easily. I decided to test a Raspberry Pi 2040 chip on a RP2040-Zero board, even though the software I was using was not tested on it. Why? They are cheap, and small, and fast, and have enough I/O for the job.

❗ So what pins does it use for I2C communication? The doco shows that the chip could use any of 23 pins to do the job. Much searching found a comment in a forum. https://forum.arduino.cc/t/issues-with-i2c-communication-on-waveshare-rp2040-zero/1235882 so I thought I'd give that a go rather than trawling through the library.
A quick wave of the soldering iron and...

Connections
JST8 | Colour | ADXL345 | Description of signal/use | RP2040 | 2040 | Location |
---|---|---|---|---|---|---|
JST | JST | Board | ADXL345 | Board | Chip | (USB up) |
1 | Black | GND | Ground | GND | GND | 2 from top LHS |
2 | Red | VCC | Supply Voltage 3-5V | 3V3 | 3V3 | 3 from top LHS |
3 | White | CS | Chip Select | 3V3 | 3V3 | 3 from top LHS |
4 | Yellow | INT1 | Interrupt 1 Output | nc | ||
5 | Orange | INT2 | Interrupt 2 Output | nc | ||
6 | Green | SD0 | Serial Data Output (SPI 4-Wire) | - | - | |
or I2C Address Select | GND | GND | 2 from top LHS | |||
7 | Blue | SDA | Serial Data I2C | 4 | GP4 | 5 from top RHS |
or Serial Data Input (SPI 4-WIRE) | - | - | ||||
or Serial Data Input and Output (SPI 3-Wire) | - | - | ||||
8 | Violet | SCL | Serial Communications Clock | 5 | GP5 | 6 from top RHS |
⭐Tested and worked first time!
❗ Counterfeit electronics from China strikes again! That ESP32 is more like an ESP0.32; probably a marginal chip that was binned, "reclaimed" by an entrepreneur, and sold to me as working. Lot of that going on. I buy lots of microcontrolers from China, including the working RP2040-Zero.
You pays your money and you takes your chances.
What Library to use?
I found these libraries the good old search engine way:
Library | Contributor | URL |
---|---|---|
ADXL345_WE.h | Wolfgang Ewald | wolles-elektronikkiste.de/en/adxl345-the-universal-accelerometer-part-1 |
github.com/wollewald/ADXL345_WE | ||
Adafruit_ADXL345_U.h | Adafruit | github.com/adafruit/Adafruit_ADXL345 |
ADXL345.h | Seeed Studio | www.seeedstudio.com |
Luis Llamas | Luis Llamas | www.luisllamas.es/en/arduino-adxl345-accelerometer/ |
Examination
I had a gander at them all, poked around the header files, and a look at available doco, and did some actual testing:
Library | Contributor | Testing | Can Use |
---|---|---|---|
ADXL345_WE.h | Wolfgang Ewald | Works, has many examples inc. interrupt code | yes |
Adafruit_ADXL345_U.h | Adafruit | Works, very abstracted | yes |
ADXL345.h | Seeed Studio | No data returned | ⚠️no |
Luis Llamas | Luis Llamas | No data returned | ⚠️no |
⚠️ My testing is not your testing - my modules, chips, libraries all impact on my testing. If it does not work for me, it may still be perfect for you.
Pros and Cons of the two working (for me) libraries
Library | Pro | Con |
---|---|---|
Wolfgang Ewald | Many examples | |
Interrupt examples | ||
Closer to hardware | ||
Not as commonly used | ||
Adafruit | Abstracted | |
Common | ||
Abstracted | ||
Mysterious | ||
1 example |
You might note that Abstracted is a pro and a con. It's great for ease of code, but not for fault-finding.
I decided to go with Ewald Wolfgang's library, and see where that takes me.
Update
@Homepin, and @Railways gave me some great feedback, and I this is my reasoning for not just fitting a standard tilt bob.
- I have some mechanical tilt mechanisms. I don't want to clean up the mechanical tilt mechanisms. Maybe in a year or so I'll be able to face them... I'm all brasso'ed out.
- There's this thing that happens where harmonic motion increases the tilt bob's swing, so that several gentle nudges result in a tilt, I want to eliminate that "feature".
- My old Fish Tales liked to tilt multiple times because the bob-hook did a shimmy, a figure 8 instead of swinging back and forward. I want to remove that "feature" as well.
- It's self-levelling - so I don't need to adjust it if I change the angle of the machine. I don't know if that's actually a thing, but hey, it sounds good.
- It's small and does the job of the bob, the rolling ball-in-a-cage thing (I bet that's got a name), and the slams - so I don't need to fit any of them, although I don't need them, it's nice to have.
- Someone wasn't thinking and mounted something on the playfield that would bump into where the bob should go...
- Price, my <<sophisticates electronics>> is running at $6
If the cabinet had a tilt mech fitted, would I bother - no
If I had a clean and tidy tilt mech would I bother - no