Posts by Boomer48

Old dog still learning new tricks.

Slot Machine

I remember when I was a 17-year-old, recent high school graduate, and was traveling with my grandparents from California back to their home in Michigan.  Of course we stopped in Las Vegas and walked the Strip just to see what there was to see.  Almost all of the casinos were open at the front so I wandered into one with my grandparents.  I saw a nickel slot machine and just had to stick a coin in.  Surprise, surprise, I hit the jackpot!  Jackpots were paid out as two rolls of 50 nickels each so a casino employee came over when the lights and sound went off.  He looked at me, handed the rolls to my grandmother and quietly told her that anyone under 21 really wasn’t supposed to be in there.

I like technology but I’m not a tech junkie by any means and I also like a lot of “old school” stuff like antiques, cars, etc.  For instance, if I ever decided to buy a pinball machine I’d want one from the 60’s or 70’s before they got too glitzy.  I’m also not a gambler but I remember how cool that old time slot machine was.  Just for fun I decided to check some out on ebay and about fainted when I saw the price tags.  I could probably afford it but I’m too cheap and there’s no place in our home for it anyway.  Still, I thought that the young grandkids might enjoy a toy like that when they come to visit so I decided to see if I could build a small version.

Components

Old time slot machines had three windows and mechanical wheels with a variety of images that would spin behind the windows when a coin was inserted and the side handle was pulled.  The spinning wheels would come to a stop one at a time and some sort of payout would occur for various matching images.  They also tended to have flashing lights and noise if a jackpot occurred.  I wasn’t trying to exactly recreate an actual slot machine but at least it had to have some of the basics.  I needed a solenoid to activate the trap door for the coins when a jackpot occurred and some LED’s for flashing lights.  I also wanted some sort of sound so I found a sound recorder module in my junk box and recorded the ever popular phrase “Winner, winner, chicken dinner”.  It plays through a small speaker.

The display is one of the large digit surplus 1601 LCD’s that I have lying around.  I used square bracket characters to simulate three windows and finally decided to just use numbers instead of characters for the “tumbling” wheels.  I added a small buzzer to make a clicking sound while the digit “wheels” were turning.  I hemmed and hawed about whether or not to trigger the “spin” when a coin was inserted or to build a separate handle.  The coin slot I bought came with a coin reject button so I decided to use that to start the spin.  I mounted a micro switch so that it is activated when the coin reject button is almost fully pressed.  A piece of scrap PVC pipe was placed between the coin slot and the trap door to hold the inserted coins.

A big part of the fun was doing a little woodwork (one of my other hobbies) to build the cabinet.  I didn’t have anything that was quite right in my scrap pile so I headed to the local lumber store to look around.  One of the types they carry is poplar which, to me, sounded pretty bland.  But when I started sorting through boards I came across one that I just had to have because of its variety of color bands.  It was only later that I found out that it is an example of what is termed “Rainbow Poplar”.  Unfortunately, my photography doesn’t really do it justice.

20181213_082636

 

Hardware

Slot Machine

The schematic is shown above.  Most of the components have already been described in the previous section and are fairly obvious.  I placed four different color LED’s on the front, two on each side, and they flash back and forth when a jackpot is hit.  The schematic just shows those as two LED’s on PIC pins 11 and 12.  The sound module says it will run on 5 volts but the specs show it being happier with less than that.  Instead of a regulator I just put a couple of salvaged 1 amp diodes in series to drop the +5 volts to the module.  The inputs to the module prefer 3.3 volt levels so a resistor divider was added to the trigger input.

The solenoid runs on 12 volts and originally I had planned to just use a 7805 regulator to provide the +5 volts for the logic.  Because of the current draw of the large LCD, there was a lot of power being dissipated so I grabbed a simple DC-DC buck regulator board from my parts supply to do the job.  The small solenoid I used is not very powerful and won’t retract if too many coins are pressing down on the trap door.  That shouldn’t be a problem because I made the odds 8:1 to keep the kids interest up.  In any case, I decided to use a generic N-channel FET to activate the solenoid in order to reduce the voltage drop.

Software

The main routine just loops continuously until the button on the coin slot is pressed.  There is no requirement to insert a coin first to activate the spin cycle but I’m hoping that the kids don’t figure that out.  While the main routine is looping, it is incrementing the variable “Random”.  It will simply overflow back to zero the cycle after it hits 255.  When the “Spin” routine is called it just goes through a list of checks on the value in “Random” to determine if a winner has occurred.  As stated earlier, the odds are set at 8:1 but it can be easily changed by modifying the winning values in “Spin”.  If a matching value is not found, then the logic just shifts bits in “Random” and displays each three bits as a number.  A test is done to ensure that an accidental match of digits doesn’t occur.

The power up display shows a question mark in each of the three windows.  While the “wheels” are spinning, each window will alternate between a blank and a question mark and then finally settle on a number one at a time.  That logic is contained in the routine “Send_Digs”.  Instead of having to constantly rewrite the entire display, the routine “Send_Dig” writes to a specific LCD location.  Also, while the “wheels” are spinning, the routine “Clickit” is called to simulate the mechanical sound of the wheels.  This is accomplished by sending 2ms on / 100ms off sequences to the piezio buzzer.

When a jackpot occurs the LED’s alternate flashing from right to left, the sound module is activated, and the coin door is released.  There are no partial payouts, just all or nothing.  After the coins are collected the coin door must be manually pushed back up to latch.  That’s it for this post.  Check out my other electronics projects at: boomerrules.com

Slot Machine

GPS Clock

In my basement shop area I have a digital clock and, in the same project box, I have a receiver for Accurite weather sensors.  The weather sensor part is based on an earlier project that I modified to receive and alternately display temperature and humidity from both an indoor and an outdoor sensor.  The clock was based on an earlier project where I used a 4.194304-MHz crystal to get a nice even 2-Hz interrupt from Timer1.  The problem with the clock was that a power glitch meant that I had to reset the time.  I suppose I could have added a battery backup but that was too boring of a solution so I decided to run it on GPS time instead.

20181213_082126

GPS Units

NEO-6M

I have several GPS units (without displays) that output the standard NMEA sentences.  In a previous project I mentioned a couple of these and showed how to display a bunch of GPS information on a 4-line LCD display.  The smallest and cheapest of the units I have is the NEO-6M so that’s what I built into my clock.

It’s easy to connect the Ublox NEO-6M module to the PIC because it uses a TTL-level serial port and outputs standard NMEA-0183 sentences.  The only real difference is that the NMEA standard specifies a serial baud rate of 4800 but the Ublox unit defaults to 9600 baud.  You can run the free “u-center” program to change the baud rate but I just left it as factory default.  As I mentioned in the previous GPS project there is also a utility program called GPSInfo (put out by Globalsat) that is very handy for viewing GPS information.  You can hook up the GPS unit to a standard USB to TTL cable for checking it out or for setting it up using a PC.  Keep in mind that the GPS chip on the module actually runs at 3.3 volts (via an on-board voltage regulator) so if you want to connect to its RX port you should level shift down from 5 volts.  The TX port can connect directly to the PIC or the PC.

Time Zones

Displaying GPS time is an easy thing to do as long as you just want to display UTC (Universal Time Coordinated).  The NMEA sentences are composed of ASCII characters which can be directly output to the LCD.  The time portion is in the format of HHMMSS.FF (hours, minutes, seconds, and fractional seconds).  For our clock the fractional part is not useful so all we need to deal with is six characters.  The problem is that you then need to convert to your local time and to a 12-hour AM/PM format if you want that.  But sometimes problems are what make life interesting so that’s what the software is really all about.

As for time zones, you might think that there would simply be 24 of them with 12 of them east of the UTC location (+ zones) and 12 of them west of the UTC location (- zones).  In fact, there are a few oddball ones that are fractional hours and a couple that exceed the 12 hour “limit”.  If you happen to live in one of these areas I apologize because my software only accounts for the 24 whole hour zones.  There are also some of us who use Daylight Savings Time part of the year but that is not accounted for in the software.  I may make a later update to the software to handle it but it would require an “opt-out” capability as well as the storage in EEROM of future dates for the transition.  The software would need to be updated if those dates change at some point.  The hardware provides a switch for easy setting of the time zone so I settled for that at the moment.

Hardware

GPS Connection

The hardware connections are shown in the diagram above.  The connection to the GPS is simply from the GPS transmit output to the PIC serial port receive input.  As mentioned earlier, the switch on PIC pin 4 is for setting the time zone.  The LCD connection is the standard 4-bit setup that has been used in a number of previous projects but the LCD itself is different.  Usually I have used the standard 1602 LCD (16 characters by 2 lines) but I chose to use a surplus 1601 display that has large characters so my old eyes can read it more easily.   The 1601 operates the same as the 1602 except it doesn’t have the second line.  In fact, my test board uses a 1602 and didn’t require any software changes.

 

Software

The GPS outputs standard NMEA-0183 sentences which are ASCII strings that contain a variety of information.  For this application I chose the GGA sentence simply because that is what I used in my previous GPS project.  Fields of information in NMEA sentences are separated by commas so after the GGA sentence header is detected the software would normally count commas and call the appropriate routine for each desired field of information.  Only the time information is needed here and that is in the first field so no comma counting is needed.

The six time digits are buffered and then processed after all of them are received.  The GPS may output some incomplete messages early on so the buffering routine verifies that each character is an ASCII numerical value.  If a bad character is received, the message is discarded.  This may also happen on rare occasions during normal operation, particularly if the serial port communication drops a bit.  I’ve only seen this once and all that happened is that the time paused for a second and then jumped two seconds instead of one.

In order to convert the UTC to local time, the UTC offset (time zone) must be applied.  Because the UTC time from the GPS is in ASCII format, the software converts the ASCII characters to decimal, adds the tens of hours to the units, and then adds the UTC offset.  The UTC offset is stored as a positive BCD value with a sign bit so it is first converted to an integer value and a two’s complement is done if the sign bit is set.  Once the local time hour value is calculated a lookup table is used to convert it to BCD and then a routine converts the BCD to ASCII for display.  The lookup table needs to handle the 24 hour UTC format as well as +/- 12 time zones.  In order to do this, the UTC times from 0000 to 2300 occupy the middle 24 entries in the table with 12 entries before and 12 entries after to account for the time zones.  I chose to use a 12-hour format so I also added a lookup table for the AM/PM part of the display.

The time zone is retrieved from EEROM during initialization and briefly displayed.  If it has not been set at least once then the setting routines are called.  The setting routines can also be called at any time by pressing the switch.  The setting routines will initialize the display to “UTC OFFSET +77”.  If a negative time zone is required, a short press of the switch will change the value to “-00”.  If a positive time zone is required, then press and hold the switch until the value changes to “+00”.  Once the value is at zero, each short press will increment it up to a maximum of 12.  After reaching the desired time zone, press and hold the switch until the display reads “OFFSET SAVED”.  The software uses a 100ms timeout for switch debounce and counts 10 timeouts (1 second) as the command to transition to the next setting step or to exit.  If you make a mistake during entry, just exit and then press the switch again to reset it.

The NEO-6M doesn’t require a good position fix in order to output the correct time so it should output messages as soon as it gets one satellite.  Until then the display will read “NO DATA”.  That’s it for this post.  Check out my other electronics projects at: boomerrules.com

GPS_Clock

HIIT Timer

Where I live, the cold months seem to go on forever so I have to find some way to exercise that keeps me indoors.  I could afford to go to a gym but it takes too much time, I’d have to show off my old body in public, and I wouldn’t be able to watch re-runs of Charlie’s Angels on a big screen TV.  Fortunately, our condo has a partially finished basement which gives us room for a treadmill, a manually operated stationary bike, and that big screen TV.  I’ve had a pretty set routine for awhile but I recently read in an AARP bulletin that it’s ok for “seniors” to engage in some forms of High Intensity Interval Training (HIIT).  After doing some research I found that one of those techniques could be perfectly adapted for use with my stationary bike.  I tried it, survived, and decided that I would try it again but decided that it was a hassle counting seconds for my high/low intervals.  Not to worry because I have a shoe box full of micro-controller chips and a lot of free time on my hands.

HIIT

For the uninitiated, HIIT basically involves a warm up time followed by sequences of high intensity activity followed by low intensity activity.  In my case, the recommendation I found has 5 minutes of casual bike pedaling followed by 20 seconds of fast pedaling followed by 90 seconds of casual pedaling.  The only thing that varies with the high/low intensity sequences is how many you do.  For me the range is generally 4-6 sequences and then a few minutes of cool down.  The other thing I found was that HIIT should only be done 2-3 times a week, interspersed with other types of activity.  I figured that I could do the HIIT and then the next day do my regular treadmill routine.  That works for me but I’m no expert so don’t take this as advice.

Hardware

HIIT Timer

The schematic for the timer is pretty boring because it just involves several LED’s connected to the PIC outputs.  I built it into a small plastic project box that I fastened to my bike frame with Velcro.  I run it on two alkaline AAA batteries with an on/off switch.  The LED’s are different colors with green being the one for the low intensity intervals (including the warm up time) and red being the one for the high intensity intervals.  The other six LED’s keep a count of the number of intervals completed.  Given that the maximum number recommended was 6, that’s what I used.  It also was a convenient number because it made the software simple when turning on subsequent LED’s (no need for a counter).  I couldn’t decide if I should use yellow or blue LED’s so I alternated them.

20181213_082007

20181213_083505

Software

The software is also pretty boring as it basically just runs a one second timer and counts seconds for each phase of the exercise from warm up through the intervals.  There are defines for the length of the intervals so that is easy to change if you need different values.  Timing isn’t critical so I chose to use the 250-kHz internal oscillator to help conserve power.

To get the one second interval I used Timer1 and preset it so it would overflow after the desired count.  The desired count for one second is the oscillator frequency divided by 4 (62,500).  The overflow generates an interrupt and all of the logic is contained in the interrupt handler.  The specific routines are assigned based on which portion of the sequence we are in – warm up, high intensity, or low intensity.  The only “fancy” part is that I wanted a warning of when the next high intensity interval was coming.  To do that I simply determined if there was less than 10 seconds left for the low intensity interval and then turned the green LED on/off every other second.  The sequence count LED’s are all assigned to PORT C so a simple shift of a “1” bit will light the next one while keeping the previous ones lit.  The high/low intervals don’t stop after all of the LED’s are lit so if you want more sequences you can easily add code to reset the LED’s and start lighting them again.  That’s it for this simple project.  Check out my other projects at: boomerrules.com

HIIT_Timer

Servo Control Stuff

In the past few months I have been playing around with some cheap servos.  I started by making a four-leg walking “thingie” out of oversized Popsicle sticks.  The hardest part was keeping it balanced when one of the legs was lifted for movement.  That exercise prompted me to build a 3-DOF (degrees of freedom) tester so that I could test servo movement in general and also verify pulse width settings for the desired positions of each 3-DOF leg.  More recently I decided to buy a cheap 4-DOF robot arm kit that did not include control electronics.  This article is sort of a mishmash of what I’ve learned so far about servo control and includes schematics and PIC software for the 3-DOF tester and the 4-DOF robot arm controller.

Cheap Servos

The cheap servos available from online suppliers have a rotation range of 180 degrees.  They consist of a small motor, some gears, and a control circuit that requires a PWM (pulse width modulation) input.  In general, the PWM frequency is set to 50-Hz for servos and the servo position is varied by sending a pulse width of about 500 microseconds to about 2.5 milliseconds (1.5 milliseconds centers the servo).  The first information I found online indicated a range of 1ms to 2ms but that only moved the servos 45 degrees either side of center.

Servos1

PWM

One of my earlier projects (posted on my website) talked in detail about PWM so I won’t repeat that information here.  Check out the Model Train Controller for those details.  In my previous projects I used the PWM capability built into one of the PIC microcontrollers but that is insufficient when you have more than one servo to control.  There are a variety of ways to handle multiple servos and that includes external modules that do the PWM for you.  When I built the four-leg walker I used three servos per leg so I needed to control 12 altogether.  Fortunately, there is a module that accepts I2C serial command inputs to generate up to 16 separate PWM outputs.    Just search for “PCA9685” on ebay.  There are also some simple PWM modules that have either an LED or LCD and can output 2 or 3 separate PWM signals.  Mostly they are for manual control via the onboard buttons but they can also be controlled using a 9600 baud RS-232 type of interface.  I don’t recommend these for servo control because multiple PWM outputs can be generated in software for a PIC.  I used the PIC 16F688 chip for both the 3-DOF servo tester and the 4-DOF robot arm controller.

Software Generated PWM

As I indicated earlier, a typical PWM frequency for servos is 50-Hz and the servos are positioned by sending a pulse during each frequency period.  The 50-Hz interval is set in the PIC software using Timer0.  When it times out, an interrupt is generated and a flag is set to let the main routine know that it is time to send pulses to the servos.  Given that 50-Hz is a 20ms period it is easy to fit control pulses for several servos within each time frame.  For simplicity, the pulses for each servo are sent out sequentially.  That means that the PIC only has to use a single timer to generate the desired pulse widths.  For instance, Timer1 is loaded with the desired pulse time for servo1, the control output for servo1 is set high, the software waits for the timeout, and then the control output for servo1 is set low.  The sequence is repeated for each of the remaining servos.  The maximum pulse width for each servo is 2.5ms so four servos only use about half of each 20ms period.  The servos don’t care where the pulse occurs within the time frame.

3-DOF Servo Tester

20180531_163208

The servo tester uses potentiometers to allow variance of the servo pulse widths.  There is also a switch for forcing all servos to the center position.  An LCD is included so that the actual pulse width values can be observed without having to connect to an oscilloscope.  Each potentiometer forms a simple voltage divider between +5 volts and ground and is connected to a PIC pin that is set for use as an ADC (analog-to-digital conversion) input.  Based on the voltage read, a calculation is performed to convert the voltage to a servo pulse width.  Basically, the formula is: (V * 7.5) + 600.  I found that 600 was the “real” minimum pulse width for my servos as opposed to the stated value of 500.  Remember that “V” in the formula is actually the truncated 8-bit ADC value (0-255) of the input voltage from the potentiometer.  On its own, the PIC doesn’t do multiplies or divides so the simple method for getting 7.5 was to left shift the ADC value three times (multiply by 8) and then subtract the right shift of the ADC value (0.5).

The LCD interface uses just 3 PIC pins but requires the addition of a 74HC164 shift register.  The details of the hardware are discussed in the “3-wire, 8-bit LCD Interface” project on my website.  The LCD shown in the picture is an oversized, single line one that I picked up as surplus but the software will work with the standard 1602 LCD.

Servo Tester 3DOF

Servo tester 3DOF

4-DOF Robot Arm Controller

20180531_163721

20180531_163700-e1527886885312.jpg

The kit for the robot arm shown in the picture can be bought for $25-$30 online.  I opted for one with servos that have metal gears so it was at the high end of that range.  I attached the flat robot arm base to a large project box which contains the control circuitry.  The hardware/software was base lined off of the 3-DOF servo tester.  A fourth potentiometer was added to the hardware, limit checks were added to the software, and the routines for the LCD were stripped out.  I used the 3-DOF servo tester to get a feel for the maximum ranges I wanted for each servo.  The range checks are not essential but I thought they might be a good idea given that I let my young grandkids play with it.  I’ve debated adding simple Bluetooth control for the robot arm so I specifically left the PIC serial ports pins available.  Otherwise, the hardware/software could be modified for 5-DOF.  You might think that you could go to 6-DOF with 12 I/O lines but RA3 is an input only and digital only pin.

Robot Arm1

RobotArmCtrl1

Check out my other projects at: http://www.boomerrules.com

 

Turkeys

Since we’re so close to Thanksgiving, today I want to talk to you about turkeys.  Wild turkeys, that is, not the kind of turkeys we eat at Thanksgiving.  Did you know that the Pilgrims actually brought some turkeys with them on the boat?  Anyway, my interest in turkeys is just part of my interest in wildlife.  I’ve always been a city boy and I still get excited when I see things like deer and turkeys roaming around in the wild.  Snakes excite me too but not in a good way.

 

Unlike domesticated turkeys, wild turkeys are smart.  They are also very sociable.  They hang around in groups.  They play together.  And the older ones teach the younger ones everything they need to know about being a turkey.

 

When I lived in Iowa, I would drive by a small corn field on the way to church and every Fall there would be at least one bunch of turkeys grazing on corn that had fallen to the ground during the harvest.  In West Texas, though, the turkeys don’t have the luxury of corn fields.  I guess I don’t really know what they normally eat, but I do know that they like acorns.  I’ve seen a group of turkeys gathered around a tree eating acorns.  And when the supply of acorns runs low, one of the turkeys flies up into the tree and starts thrashing around to knock down more acorns.  See, I said they were pretty smart.  After awhile, the turkey will jump down from the tree to eat some acorns and another turkey will take its place in the tree.  It’s all part of living in community as turkeys.

 

So what do turkeys have to teach us about being a Christian?  Well, when Jesus founded the church, he basically told us to be like turkeys.  He didn’t say it exactly that way but he did expect us to be in community with one another.  He expected us to worship together.  He expected us to play together.  He expected us to teach each other how to be a Christian.  He expected us to take turns doing the work of “shaking the tree” so that everyone can get a share of the acorns.  And he expected us to be sociable enough that others would want to join our group.

 

Benjamin Franklin once wrote a letter to his daughter in which he compared the Bald Eagle and the turkey.  Basically, he said that the Bald Eagle looked good on the outside, but that it only cared about itself and was both a coward and a thief.  On the other hand, Ben praised the turkey for all of the things that I mentioned.  It’s like that for us as Christians too.  It doesn’t matter if you look more like a turkey than an eagle, it’s what’s inside that counts.  That’s what God sees in us and that’s what other people will experience through our actions.

Grandma

There are lots of stories about people who overcame some bad things in life but the one that I know best is the story of my grandmother.  When grandma was born in 1905 her father was in charge of running a logging camp.  Her mother took care of all of the cooking for the camp as well as taking care of her own family.  Grandma loved school but, when she was still in High School, her father died.  Her mother had to take over the day to day business of the logging camp management and that meant that grandma, as the oldest child, had to quit school and take over the cooking and looking after her younger brothers and sisters.  Grandma eventually found her way back to school and, when in her 80’s, grandma dressed in a cap and gown and proudly marched up to get her diploma.  Every one of her kids and most of her grandkids were there to cheer her on.

 

Grandma got married and had children.  She lost her youngest daughter as a baby and then, when grandma was 94, she lost her oldest daughter who was my mother.  In between, grandma and grandpa made a modest living until grandpa died when grandma was 61.  In order to pay the bills grandma worked fulltime as a housekeeper at the local hospital.  Eventually she worked her way up to be a nurses aide but not before she lead a difficult fight to get the housecleaning workers organized into a union.  Grandma was in her 70’s when she retired from fulltime work at the hospital but she continued doing volunteer work there for another 20 years because she just liked helping people.

 

Grandma got a little slower with age but she was still very active and mentally sharp into her late 90’s.  She collected family stories and pictures and put them into a family history.  When I would visit her she would tell me wonderful stories about how life was lived long ago and the interesting characters who were my ancestors.  Unfortunately, all of that came to a sudden end when grandma had a stroke at age 98.  The stroke caused grandma to lose her ability to walk and to talk and even to swallow.  After being so active and helpful she ended up bedridden, with a feeding tube, and only able to make sounds that couldn’t be understood as words.  But grandma was still there inside of that broken body and people say that her face lit up with joy when her many friends threw her a 100th birthday party.  Grandma had another stroke a few months later and was finally released from her earthly prison.

 

I read somewhere recently that life can only promise us pain so it’s up to us to create the joy.  When I think about that I’m reminded of grandma.  She endured what life threw at her and still managed to thrive and to be someone that made people feel good.  The Bible also tells us that we are certain to have suffering in our lives.  And, unfortunately, good people sometimes suffer more than bad people because life is not fair.  But the Bible also tells us that we can take joy and comfort in a life lived in Jesus.  And we can take joy and comfort in knowing that there is a better world after this one.  I know that grandma believed that.  And I think that’s what got her through the last year and a half of her life.