What's new
Pinball info

Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

In Progress Mishmash Homebrew - Pt II

Ashbo

Site Supporter
Joined
Apr 9, 2021
Messages
1,809
Location
Lincolnshire
Alias
Ash
So carrying the batten from this post here: https://www.pinballinfo.com/community/threads/mishmash-self-build-let’s-make-a-pinball-machine.50005/post-451003

Thanks to Alan for letting me loose on his baby. I promise not to let you down sir.

Picked up last weekend and I've had a bit of playing the game, and some furtive and ginger pokes and prods to see what she is made of.

I have to say it's a monumental effort that has got her this far and hats of to Alan for producing a working game, from scratch. It's brilliant.

So, what next? It wouldn't be a shop log without a list, so here goes ....

  1. Dig into the code, understand and document what's there (underway).
  2. Dig into the physical build and document what's there (underway).
  3. Formulate a new code that replicates what's good in modern single layer playfields....that is, easy achievable objectives that get progressively harder (underway).
  4. Plan further code developments (not started)
  5. Plan physical developments (not started)
  6. Plan electronic developments (adding additional sound options). (not started)
  7. Plan cosmetic developments (consuming thoughts, but nowhere near started)
Other things I have considered is mission pinball framework, building a pc and electronics to integrate with MPF and burrowing down that rabbit warren.....maybe later on....baby steps...

So, this weekend the plan is to add in some test functionality to reduce the need for swapping modes in code, compiling, uploading and testing. I'd like to use one of the unused switch column/row combinations to scroll through the machine states Alan has already programmed. I'd also like to do the same to turn all solenoids off or on. Basic, but as this is a new project for me, essential to ensure I start to learn how she works.

If that's easy, I may look at implementing some kind of WiFi and webpage on the esp32 to control or monitor over the air.


Useful links.....

Let's create some classes to make the code easier to handle once it gets big on me

Esp32 web server... maybe
 
Last edited:
Good luck watching!

If that's easy, I may look at implementing some kind of WiFi and webpage on the esp32 to control or monitor over the air.

Think you can also do OSC = open sound control as well. I've used OSC to send pinball messages before. Then usb/midi controllers with OSC.
 
Good luck watching!



Think you can also do OSC = open sound control as well. I've used OSC to send pinball messages before. Then usb/midi controllers with OSC.
Thanks @dave - I can't promise it will be exciting, but thanks for watching ;)
 
So, a good night's sleep later and my plans have changed...

This morning I have started creating objects and classes to help organise the code - there is nothing wrong with the code that's here, however if I am to have a chance of writing some complex rules, I need to build some foundations, and if I'm doing that it's probably best for me to re-write everything as I go.

First up, a switches class....hold on, I have never written a class in Arduino, first up, learn how to do that...see you all next year ;)

Also signed up to github to store the code as I work on it. I'll post a link when it gets interesting.
 
Did you settle on AM as a theme? Best of luck!
Yes, still working under that assumption, however it may be called "The Little Shop of Rock" with a storyline following through. Plenty of good Arctic Monkeys inspiration to draw on, and we plan too.
 
Thanks @dave - I can't promise it will be exciting, but thanks for watching ;)

Well, there is plenty of boring (unexciting) work ahead for you but we're into it so it's all exciting, right.

I haven't ever bought an Arduino and didn't know it was C++ based until today so that's just an unexciting example of what you can get from a thread like this and by the time you've finished I'll probably have bought one.
 
Well, there is plenty of boring (unexciting) work ahead for you but we're into it so it's all exciting, right.

I haven't ever bought an Arduino and didn't know it was C++ based until today so that's just an unexciting example of what you can get from a thread like this and by the time you've finished I'll probably have bought one.
Hey, I've written loads of exciting code, only problem is - none of it actually works ;)
 
Let's create some classes to make the code easier to handle once it gets big on me
There is a visual studio plugin by a place called visual micro. Lets you add breakpoints to code which makes debugging somewhat easier.
(they are not real breakpoints it injects code to fake them but they work. It does support hardware ones if you get a spangly arduino board)
Think its around £20 for it - but there is a trial. And of course theres visual studio community which is free. This means you can "just do classes" for your code and it all works.

I enjoyed the stuff I was doing with it - and have every intention of going back to it (finishing the stuff I started) but been sidetracked with life for a chunk of this year. (I was tempted to grab this when I saw Alan posting it for sale - but I have no space and too many other irons in the fire)
 
There is a visual studio plugin by a place called visual micro. Lets you add breakpoints to code which makes debugging somewhat easier.
(they are not real breakpoints it injects code to fake them but they work. It does support hardware ones if you get a spangly arduino board)
Think its around £20 for it - but there is a trial. And of course theres visual studio community which is free. This means you can "just do classes" for your code and it all works.

I enjoyed the stuff I was doing with it - and have every intention of going back to it (finishing the stuff I started) but been sidetracked with life for a chunk of this year. (I was tempted to grab this when I saw Alan posting it for sale - but I have no space and too many other irons in the fire)
Thanks @HomerRamone . I have to say thie first thing that struck me yesterday, and then over and over again, was the lack of debugging options. Just serial output and human senses, so was really tough.

The workflow is code, compile, upload, test, repeat.

Got into a real rut yesterday afternoon when I got tired.

I will definitely check out - many thanks 🙏
 
Good luck on your coding journey.
Arduino doesn't support the full C++ standard library so don't get tripped up there. It's not a super powerful microcontroller but great for simple hardware interaction at 5v. Keep your code simple. If you want a really capable microcontroller then the Raspberry Pi Pico is excellent and cheap but you'll have to convert it's IO to 5v.
 
Significant progress this morning.

Yesterday wrote some classes for switches, coils and shift registers, however the last one was the one causing my issues. Returning to Alan's code this morning I realised I had not properly set up the shift registers in the setup() and therefor set myself up to fail.

Moving on, the big change I have implemented now is that rather than holding switches in an array, I now have to set up each switch individually as an instance of the new PinballSwitch class. Please ignore the debounce, I want it prominent for testing purposes.

1694951273693.png
There are several functions that may or may not pass the cut, but I felt may be useful initially.
1694951290264.png

I then mapped the switches to a table like you would expect in a game manual. Highlighted are some switches that seemed to have issues. It looks like I have two squares of death to investigate. :p

1694951469647.png

Once I have that, the next thing is to bring these switches to life in code.

I do that in the main Audino file by initialising them, so they are globally available.
1694951572738.png
Then in the setup() section I, well, set them up...
1694951604989.png

From there on it, I can scan them to see what's going on. I could call the checkActive function of each switch in the loop() section, but that would be clumsy, so I added these calls in its own function so I only need to see the one line in the loop.

1694951746333.png

And there you have it...it works...level one passed.

The CheckActive() code.
1694952002805.png
The fireSwitch() code.
1694952029564.png

Serial output.
1694951787651.png

Next, we need to work out whats causing the multiple switch fires. Eg, the rebounds are causing tilt bob to fire....Good old fashioned pinball problems for a bit.

1694951861348.png
 
Oh, just leaving this one here...time to go back to the real world and I'll forget about it....I need to now look at the flippers. Switch handling here needs to be very different to other switches.

Ideas:
When pressed there should be no debounce, however when no longer pressed this needs picking up and handling immediately. Once we handle that, we can look at how we handle the flipper coils.
 
Good luck on your coding journey.
Arduino doesn't support the full C++ standard library so don't get tripped up there. It's not a super powerful microcontroller but great for simple hardware interaction at 5v. Keep your code simple. If you want a really capable microcontroller then the Raspberry Pi Pico is excellent and cheap but you'll have to convert it's IO to 5v.
Many thanks for the heads up. I am concerned that the weight I'm adding to the code is likely to blow the CPU budget. Time will tell ;)
 
You might want to stick your switches in an array so you can loop over them. Would make things like your scanAllSwitches() code much compacter.

You may also want to refactor the switch matrix reading code so that it reads all switches in a column (rather than probing a single one at a time). You'd have something like a timer which strobes the columns and collects the row values into a data store. From there another piece of logic decodes it into the first-class switch objects (or more likely, raises events as appropriate when a switch is toggled).

For your flipper buttons you probably want an interrupt. As a side note, arduino is not great here because it steers you towards writing "busy looping" code, but in real embedded systems you're usually much better off having event-driven logic.
 
You can use the dual core of the esp32 - you could scan the switch matrix on one core constantly for example.

I found i didn’t need to bother it all ram ok on a single core. The switch matrix read routine i wrote would scan the whole matrix 6-7,000 a sec so well fast enough.

You’ve probably figured i’m no c or c++ coder. i was trained on non oo languages, basic, cobol, rpg, and various 4gl’s,
 
You can use the dual core of the esp32 - you could scan the switch matrix on one core constantly for example.

I found i didn’t need to bother it all ram ok on a single core. The switch matrix read routine i wrote would scan the whole matrix 6-7,000 a sec so well fast enough.

You’ve probably figured i’m no c or c++ coder. i was trained on non oo languages, basic, cobol, rpg, and various 4gl’s,
What you have done is impressive @AlanJ - don't sell yourself short - all I am doing is slowing down the loop from 122KHz to 1.3KHz - as @Fubar says, I need to make some decisions about how I go about this,

My Google searches are full of Arduino + async or multithread or eventHandler. There are loads of libraries out there, but as many have said before - this isn't like programming for a server or desktop OS, this is more challenging - I love it though :D

Had a bit of a dabble this afternoon and getting some great results (for me ;))

I've done some work on the PinballCoil class and this has meant some additional development on the PinballSwitch class too.

Flippers are handled very differently now, which (without connecting any coils up yet) looks to be giving a great result.

PinballSwitch has the highlighted sections added
1694972061440.png
isFlipper removes any debounce processing. Nice and responsive.

A first glipse at the PinballCoil class
1694972126276.png

The main loop calls the manage() function for each coil to do any work thats needed.
1694972209509.png
I'm a way away from doing shift register work with the class, however when I finally do test, I'll be doing it with solenoids disconnected. Thanks to Alan's choice of MOFSET boards, there are LEDs on when firing, I can use them as visual confirmation before risking the higher voltage, higher cost components.

Finally a bit of a peek at some of the main code elements...

Individual switch debugging possible...
1694972485995.png
Coils being imagined into life
1694972513986.png

Setup() code using extra definitions in the switch class.
1694972548796.png
Hooking the coils up to the physical hardware
1694972587709.png
Main loop
1694972606485.png
Peek at the switch handling as it progresses
1694972641273.png

Finally coil management calls
1694972666866.png
 
Last edited:
Oh, just leaving this one here...time to go back to the real world and I'll forget about it....I need to now look at the flippers. Switch handling here needs to be very different to other switches.

Ideas:
When pressed there should be no debounce, however when no longer pressed this needs picking up and handling immediately. Once we handle that, we can look at how we handle the flipper coils.
Unless rewired, bally flippers are non 'fliptronic' affair at this era, so high power through the cabinet switch and a relay to enable disable both flipper coils. So no switch control needed.
 
Unless rewired, bally flippers are non 'fliptronic' affair at this era, so high power through the cabinet switch and a relay to enable disable both flipper coils. So no switch control needed.
I remember this from my Special Force - that was cool, it worked really really well. I don't think that its present on this playfield though.
 
I remember this from my Special Force - that was cool, it worked really really well. I don't think that its present on this playfield though.
You could reimplement this old design or if using low power switches i would consider what other pinball frameworks do (inc my own) and create 'hardware switches' These are switches tied to a specific coil. ie create a hardware switch class and assign a coil and switch to it etc When the switch activates it automatically fires the coil assigned for the length designated. Works for slings and pops to. Obviously for flippers it will just be on if using a regular eos, or if double winding parallel coil main coil pulse then hold coil on. switch off cancels anything active etc
 
Thanks for everyone's comments, it's really appreciated.

So adding to the list for investigation, else I'll forget...

  • Hardware switches for coils
  • Put back the matrix scan as was, update a data source with states then process changes to class instances from that, leaving scanning free to scan (when multi-threading introduced).
  • Introduce a timer to run the switch scanning at a defined interval, stop it racing away with resources that will be needed for leds, sound and display.
  • Investigate other boards with more power. Esp32, Raspberry Pi Pico etc.
 
Last edited:
You can use the dual core of the esp32 - you could scan the switch matrix on one core constantly for example.

I found i didn’t need to bother it all ram ok on a single core. The switch matrix read routine i wrote would scan the whole matrix 6-7,000 a sec so well fast enough.

You’ve probably figured i’m no c or c++ coder. i was trained on non oo languages, basic, cobol, rpg, and various 4gl’s,
Going to give this a test and see what it's capable of....thanks for the heads up.

Screenshot_20230917-203620-531.png

 
i learnt a lot from random nerds. the dual core stuff can get a bit tricky. worth trying a simple example first.
Having spent all weekend coding, searching and reading, it's sods law that I have to stop now I have found the most interesting article, back to work tomorrow :(
 
i learnt a lot from random nerds. the dual core stuff can get a bit tricky. worth trying a simple example first.
Been out of the loop for a few days, had a play tonight and core 0 is there and works nicely. I do need to put in a delay(1) else some of the embedded systems on the chip get starved of CPU time and force a reset. I guess you can have all of the core 0. Qué Cera, it's more of an extra core than I thought I had.

I also need to be mindful I don't have simultaneous things going in two loops battling each other. My thought here is shift register. I don't want to be sending bits and locking on one thread and then doing the same from another. With this in mind, I need to reserve one CPU core for I/O operations and one core for all others, should be ok.
 
Back
Top Bottom