design

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.

ADXL345
ADXL345

❗ 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.

Dud ESP32
ESP32

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.

RP2040-Zero
RP2040-Zero

❗ 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...

ADXL345-RP2040-Zero
ADXL345-RP2040-Zero

Connections

JST8ColourADXL345Description of signal/useRP20402040Location
JSTJSTBoardADXL345BoardChip(USB up)
       
1BlackGNDGroundGNDGND2 from top LHS
2RedVCCSupply Voltage 3-5V3V33V33 from top LHS
3WhiteCSChip Select3V33V33 from top LHS
4YellowINT1Interrupt 1 Outputnc  
5OrangeINT2Interrupt 2 Outputnc  
6GreenSD0Serial Data Output (SPI 4-Wire)-- 
   or I2C Address SelectGNDGND2 from top LHS
7BlueSDASerial Data I2C4GP45 from top RHS
   or Serial Data Input (SPI 4-WIRE)-- 
   or Serial Data Input and Output (SPI 3-Wire)-- 
8VioletSCLSerial Communications Clock5GP56 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:

LibraryContributorURL
ADXL345_WE.hWolfgang Ewaldwolles-elektronikkiste.de/en/adxl345-the-universal-accelerometer-part-1
  github.com/wollewald/ADXL345_WE
Adafruit_ADXL345_U.hAdafruitgithub.com/adafruit/Adafruit_ADXL345
ADXL345.hSeeed Studiowww.seeedstudio.com
Luis LlamasLuis Llamaswww.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:

LibraryContributorTestingCan Use
ADXL345_WE.hWolfgang EwaldWorks, has many examples inc. interrupt codeyes
Adafruit_ADXL345_U.hAdafruitWorks, very abstractedyes
ADXL345.hSeeed StudioNo data returned⚠️no
Luis LlamasLuis LlamasNo 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

LibraryProCon
Wolfgang EwaldMany examples 
 Interrupt examples 
 Closer to hardware 
  Not as commonly used
   
AdafruitAbstracted 
 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