Monthly Archives: October 2018

10/26/2018 – Waiting, waiting, last call for changes

I kept thinking to myself my next post is going to be after I receive my Arduinos and I can write about my testing.  Unfortunately, when the manufacturer says I should receive them in about a week, it seems like we are nearing a month.  Sigh.  I guess I get what I pay for.  (Of course, I did get five Arduino Nano’s for $10.83.  The only thing that annoys me is that I paid $1.50 of that to get the boards faster, but that doesn’t seem to be working out for me.)

So while I’ve been waiting around for Arduinos, I had a visitor.  Yes, the famous Joe and his wife showed up at my doorstep one Saturday morning.  Joe of course lives in Chicago, and I live in Massachusetts, so it was a little unexpected.  I have been working with Joe for approximately six years at this point.  Joe has done all of the artwork and callouts on the SharpeShooter III pinball machine.  Joe also did the artwork and came up with many of the rules for the Van Halen pinball machine.  Joe owns the Dolly Parton to Van Halen machine.  Unfortunately Joe had never been able to play SharpeShooter III.

Joe and his wife happened to be traveling to Maine for week long vacation to see “more lighthouses than you can shake a stick at,” as he says.  His wife was also interested in driving to the eastern most point in the United States.  It is tough to fault anyone for that since my wife and I have driven to both the western most contiguous point that you can drive to in the United States (it is in Alaska), and the southern most point in the United states (it is at Key West) on the same trip.

My daughter shot some “incognito” photos of Joe to prove that he was able to visit OPP world headquarters.  Joe finally got to play SharpeShooter III.  He mentioned how freaky it is hearing his callouts on a machine that he has never played.

So as we were talking pinball, I showed him around the manufacturing floor at OPP, and he took a gander at the playfield blanks that I was going to be using to start the white wood for Disaster.  One quick look and he said, “Is that 3/4 inch plywood?”  I responded with, “Yes, isn’t that what it is supposed to be.”  He responded it should be 1/2″ plywood, and the more appropriate reason is that all of the pinball parts are meant to be mounted on a 1/2″ thick piece of plywood.  Sigh.  I guess it is back to Home Depot to get another sheet.

Meanwhile…an MPF user requested that a new configuration bit be added so that the initial kick for a flipper could be cancelled.  After discussing it with Jan and verifying what was needed, I added a new configuration bit for solenoid configuration.  Version 0.3.0.1 of the firmware supports this, and Jan added the necessary code for MPF to support it.  It was a fun little change that could be done in a weekend.  This makes it so the ball can be tap passed between the flippers.

So I’m throwing out a last call for OPP firmware changes before I rename the software to rev 1.0.0.0.  There have not been many request for updates to the firmware lately.  (The last two include the cancel of the initial pulse for flippers, and a delayed initial pulse to support solenoids for kickbacks.)  If anybody knows of any other features that are needed in the firmware, I’ll try to make the necessary updates.  If not, I will rerun all the regression tests to verify all the functions and rename the firmware to 1.0.0.0 and be done with it for right now.

10/11/2018 – Arduino and OPP

Well, it is going towards Fall in this neck of the woods, so I started getting a little bit bored.  There are those people who keep saying Arduino, Arduino, Arduino, and I keep saying, “I don’t care.”  A friend pointed out to me that you could purchase Arduino Nano boards for about $2 each.  That might be compelling enough for me to take a look at.  A couple weeks back, I found a seller on Aliexpress and sent my $10 for four Nano boards.  (I paid the extra for a little faster shipping).

While the boards haven’t arrived yet, I started downloading tools and getting my first code ready for the boards when they arrive.  The tools were a breeze to download and install.  I have to give them, it was exceedingly pleasant to deal with the tools.  The tools are pretty basic compared to the tools that are provided by Cypress, but that makes them easier to use versus the more powerful Cypress tools.

Before ordering the boards, I knew that I wanted to use 16 digital I/O from the Nano board.  I did a quick search on the documentation and it mentioned that the ADC pins could be configured as digital pins, so I should be fine.  I then proceeded to order the boards.  Unfortunately, when I started digging into how to write the first program, I realized that the ADC6-ADC7 (A6-A7) pins can’t be configured as digital pins.  They are dedicated analog only pins.  Bah!  I can deal with that.  It just means that those have to only be used as inputs.  It is annoying, but it can be coded around.

So for my first test, I simply want to attach two solenoid wing boards to the Nano.  Because of the insane way that the boards were laid out and the location of the ports, I had to be a little creative.  On the PSOC, the 8 pins of a port are sequential along the edge of the board.  On the Nano, the pins of ports are mixed between each other.  I guess port C is as close as it gets, but of course, as mentioned before, the top two bits are analog inputs only, so that really doesn’t help when reading an external port once and iterating through all the bits.

So one of the solenoid wings will be on the “right” side of the Nano, and will use PC0-PC7.  This means PC4-PC7 (pins A4-A7) will be the inputs (I’ll use analog reads and check thresholds), and PC0-PC3 (pins A0-A3) will be configured as digital outputs for the four solenoids.  The second solenoid wing will be on the “left” side of the Nano, and will use PB1-PB4 as digital inputs (pins 13-16), and PD5-PD7, PB0 (pins 9-12) as digital outputs.  Well at least the Arduino abstraction layer makes up for the fact that the hardware pins are not contiguous, and makes the pin numbering contiguous for the software.

So here is the setup for the code:

void setup() 
{
  // put your setup code here, to run once:

  // setup ADC0 to ADC3 as digital outputs and low 
  for (int pin = A0; pin <= A3; pin++)
  {
    digitalWrite(pin, LOW);
    pinMode(pin, OUTPUT);
  }
  
  // setup ADC4 to ADC7 as analog inputs
  for (int pin = A4; pin <= A7; pin++)
  {
    pinMode(pin, INPUT_PULLUP);
  }

  // setup PD5-7, PB0 (pins 9-12) as digital outputs and low 
  for (int pin = 9; pin <= 12; pin++)
  {
    digitalWrite(pin, LOW);
    pinMode(pin, OUTPUT);
  }
  
  // setup PB1 to PB4 (pins 13-16) as digital inputs 
  for (int pin = 13; pin <= 16; pin++)
  {
    digitalWrite(pin, LOW);
    pinMode(pin, OUTPUT);
  }

  // for debugging loop speed set LED pin 13 as output
  pinMode(LED_PIN, OUTPUT);
}

When setting up the outputs, I first write the value LOW before changing the pin to an output.  That should guarantee that I don’t get all the solenoids briefly firing at the beginning during initialization.  I also set up the LED so I can use it to see how fast the operation loop is.

Now for the fun stuff.  Let’s control some solenoids!  So I first set up a few states for a state machine.  The solenoid can either be idle, initial kick, PWM off, PWM on, or wait for switch off.  So for normal solenoids like pop bumpers, the solenoid will be idle, detect the switch has closed, go to the initial kick state, wait for the correct amount of time to elapse, go to the wait for switch off, wait for the switch to open, then go back to the idle state.  That is as simple as it gets.

The other type of solenoid I want to initially support is a flipper with a PWM for the hold.  (I really have to get myself some dual wound flippers).  For a flipper, the solenoid will be idle, detect the switch has closed, go to the initial kick state, wait for the correct amount of time to elapse, go to the PWM off state, wait for the correct amount of time to elapse, go to the PWM on state, wait for the correct amount of time to elapse, go to the PWM off state, while in either of the PWM states, look for the switch to go open and if so go back to the idle state.

PWM can be configured as followed:

PWM = 0, no PWM so act like a pop bumper, kickout hole, kicker, etc.

PWM = 1, duty cycle 12.5% on, 87.5% off

PWM = 2, duty cycle 25% on, 75% off

PWM = 3, duty cycle 37.5% on, 62.5% off

PWM = 4, duty cycle 50% on, 50% off

PWM = 5, duty cycle 62.5% on, 37.5% off

PWM = 6, duty cycle 75% on, 25% off

PWM = 7, duty cycle 100% on, 0% off, used for dual wound flippers

To make reading input pins and writing output pins easier, I made two little lookup tables at the beginning of the code.  That way, I just need to keep track of which solenoid I’m currently processing and can use a simple loop.

const int INP_PIN_MAP[MAX_NUM_SOL] = { A4, A5, A6, A7, 9, 10, 11, 12 };
const int OUT_PIN_MAP[MAX_NUM_SOL] = { A0, A1, A2, A3, 6, 7, 8, 9 };

Since half of the inputs are analog inputs and half are digital inputs, also need to have some constants for thresholds, and when to do an analogRead vs digitalRead.

That’s about all the code does at this point.  I’m looking forward to getting my Nano boards to test it out and do some measurements on how fast the loop is.  To be a real controller, it will need a bunch of serial commands for scoring, kicking solenoids, configuration, etc, but that can wait until I get the first loop started.

The see all of the code, you can look at it in the repository/Arduino/NanoOPP.  Note:  The code has not been tested whatsoever, so this code is simply for your viewing pleasure.