Pushbutton Trigger

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
User avatar
JLeith
Posts: 537
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 146 times
Been thanked: 26 times
Contact:

Pushbutton Trigger

Post by JLeith »

Hello all. Its been about 2yrs since I have been working in PIC world.

I have a simple project that I need help in seeing what I'm missing to press a button and trigger a action.

I tried to determine what is happening by putting a slide switch but no control happened ?

What I would like to see is press of the button to be activate the "PortATrigger macro only to activate when the button pressed.

I was using the LCD to display the state of the "Coin" when no coin detected Coin should be Coin=1. When the button is pressed Coin=0.

I was using A6 led to track events.

In the future is to activate a Servo in the PortATrigged macro to activate a servo. I will have to refresh my information on Port and how to have a servo to go from 0-90degree.

I changed the original program form a PIC16 28 pin to the new Pick16f1937 40pin to active a servo.

Hope someone has Ideas what is wrong with my program.

Thank you
John Leith

Flowcode included
PIC40_servo_Pachinco 6.fcfx
(39.77 KiB) Downloaded 155 times

chipfryer27
Valued Contributor
Valued Contributor
Posts: 617
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 195 times
Contact:

Re: Pushbutton Trigger

Post by chipfryer27 »

Hi

I see that you have both the Push Button and the Slide connected to Port A4, however you are not testing that port anywhere in Main.

I also see you have an interrupt on INT0 enabled to call Macro PortA4Triggered, however you don't appear to have anything connected to that pin (Port B0). Perhaps reassign your button to Port B0, and you may want to rename the Macro from PortA4Triggered to PortB0Triggered?

Regards

User avatar
JLeith
Posts: 537
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 146 times
Been thanked: 26 times
Contact:

Re: Pushbutton Trigger

Post by JLeith »

Thank you
I might have tried all settings and made a mess.

RB1 is the incoming signal for the Coin activation and the Servo is connected to B0.

John

chipfryer27
Valued Contributor
Valued Contributor
Posts: 617
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 195 times
Contact:

Re: Pushbutton Trigger

Post by chipfryer27 »

Hi

Port B0 is designated as interrupt INT0 so if you wish to use INT0 then you need to connect a switch or such like to it. It can't be used as an output.

Interrupt On Change (IOC) also uses Port B so that may be an option for you if you use masking. Do note however that change on any active IOC pin will call the assigned Macro. You will need further code to establish which pin triggered but this is only an issue if you have multiple pins active.

Regards

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Pushbutton Trigger

Post by medelec35 »

Hi John, just to comment on the version of Flowcode you are using.
Flowcode v6 is very out of date now so there is no official support for it.
In saying that, thank you chipfryer27 for your helpful posts.

With the new Flowcode v10 the 16F18877 (updated version of 16F1937) and all the components are free.
Not only that the code and user macros allowed are now unlimited with the free version
So if you don't want professional options of which include:
  • step into components
    view component code directly
    Component connection lists
    Component debugger
    Additional tools menu
    User Interface tree customisation
    In built TODO list
    Separate .c and .h generation
    Variables on simulation and In Circuit Debug scopes
    Customization of the C code of flowchart icons
Then it won't cost anything to use, so long as you use the free targets.
Check out this link
Martin

User avatar
JLeith
Posts: 537
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 146 times
Been thanked: 26 times
Contact:

Re: Pushbutton Trigger

Post by JLeith »

Thank you Chipfryer27

The summary is the Port B1 incoming signal is Logic 0 .
Step 1. With B1 is High Logic 1 (From a 10K resistor to VCC)
Step 2 Display text on the LCD
Step 3 ----- Trying to trigger B1
Step 4 -- Trigger on B1 from Logic 1 to Logic 0.
Step 5 - When B1 goes Low I would then run code to send a 120ms pulse to a Relay to control the Solenoid on Port B0

My question is how can I run the Solenoid code with out a trigger B1.
I can past a drawing if that helps.

The trigger from the outside hardware coming into B1 is only about 5ms on/off. This is what I could detect while The LCD is running text to Trigger and run the solenoid code.

My research indicates B1 is a IOC port possible to make a trigger just not sure how to detect ? Maybe fellow members of flowcode 6 have Ideas.
I tried the Intercept options but nothing worked. I did notice I can see the Port B1 change if I don't right to much text on the LCD.

Hello Martin it was nice to see your text about Flowcode 6 is not supported sad times. I would of thought Matrix would still offer help on all Flowcode not the top of the line Flowcode 10.

User avatar
JLeith
Posts: 537
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 146 times
Been thanked: 26 times
Contact:

Re: Pushbutton Trigger

Post by JLeith »

Hi Chipfryer27

Here is a quick drawing of the process.

The red section is the Mystery.

Token.jpg
Token.jpg (52.86 KiB) Viewed 189964 times

viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 43 times
Been thanked: 60 times
Contact:

Re: Pushbutton Trigger

Post by viktor_au »

Hi John.

Please have a look.
What happens after the program detects a coin?
Attachments
PIC40__Pachinco_8.fcfx
(58.52 KiB) Downloaded 168 times

User avatar
JLeith
Posts: 537
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 146 times
Been thanked: 26 times
Contact:

Re: Pushbutton Trigger

Post by JLeith »

Token route.png
Token route.png (127.91 KiB) Viewed 189947 times
Hello Viktor_au
When a Token is put in the coin shut it falls out the bottom by to Infrared detectors that send a pulse to a PNP transistor and a 5v relay sends a Grd (Logic 0) to the PIC16F1937

In the PIC16F1937 I list procedure for game players to put in a token and I was trying to get the PIC to trigger on B1 to trigger a solenoid offer the Servo in my Flowcode 40.

Hope the picture helps.

John

User avatar
JLeith
Posts: 537
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 146 times
Been thanked: 26 times
Contact:

Re: Pushbutton Trigger

Post by JLeith »

Excellent design Viktor_au

I noticed you used the DashBoard Panel. Not sure why but when I press the Button or the switch the B1 does not trigger?

Did it work on your Flowcode ?

The action hoping for is During the LCD listing information and B1 is going from Logic 1 to Logic 0 the Macro "Coin Detected" should list.

I really appreciate the time you spent. I will review the code and see how it flows.

John

viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 43 times
Been thanked: 60 times
Contact:

Re: Pushbutton Trigger

Post by viktor_au »

Hi John

Re: Button
It is not activated yet.

Re: PIC input from Coin sensor module
Does your relay has NO and NC contacts?

Question
Looks like you have the Pachinko machine.
Can I ask you what model is it?
Do you try to repair it or completely change the electronics?

Viktor

User avatar
JLeith
Posts: 537
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 146 times
Been thanked: 26 times
Contact:

Re: Pushbutton Trigger

Post by JLeith »

I have really appreciated the Flowcode 40 version 8.
Question
A) Does your relay has NO and NC contacts? - The relay is NO until the P1 Input goes low from the coin detector.
B) Looks like you have the Pachinko machine. - Yes
C) Can I ask you what model is it? Its a 1977 - Sanko
D) Do you try to repair it or completely change the electronics? - Its all mechanical - I'm adding a ramp inside to dispense 45 game balls. I need the PIC to send 3 pulse to send 3 winnings in the pachinko will dispense 45 game balls. I have ordered a solenoid that will do the task if I can get the PIC to detect when the Relay activates

I changed to the PortB0 as you indicated but it won't trigger to activate the solenoid.

I have added the solenoid to your design Tried and tried to get the trigger but no luck.
PIC40__Pachinco_9.fcfx
(55.08 KiB) Downloaded 177 times
Viktor do you have a Pachinko Machine ?

John

viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 43 times
Been thanked: 60 times
Contact:

Re: Pushbutton Trigger

Post by viktor_au »

Hello John.

No, I don't have a Pachinko machine, but read about it and consider your project as a good one.
An electronics + fun = a very good project.

You wrote: PIC to send 3 pulse to send 3 winnings in the pachinko will dispense 45 game balls.

Can you please give a bit more information.
About relay: what happens when relay is activated?
About solenoid: what activates solenoid? Does the user do it? How fast solenoid should be?
Does it work constantly? What stops it?

Would be great if you write something like:
If Coin is inserted
relay is activated,
LCD + LED shows some info to user ( token number, etc)
After delay the solenoid is activated by PIC and 'solenoid kicks up ' 3 balls at a time (with delay in ? milliseconds?)
User should notice the machine state.
When no ball left, PIC should stop the game (LCD + LED info).

User avatar
JLeith
Posts: 537
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 146 times
Been thanked: 26 times
Contact:

Re: Pushbutton Trigger

Post by JLeith »

Hi Viktor
Can you please give a bit more information.

I hope This picture will help
Token to PIC.jpg
Token to PIC.jpg (101.32 KiB) Viewed 189882 times
I can change the Port On Item (D) to RB0 to help with trigger.
The Item D is the input that Is Logic 0 input
The input B0 is like a Push Button Example

The solenoid is mounted in the back of the Pachinko machine and pushes a 3 balls at 120ms interval to trigger 45 games balls
So in the PIC40 design
1. Look for B0 at any time in displaying the info on the LCD
2. When B0 is detected the Solenoid will be is a relay driven at 120ms on then off just Designing a Solenoid in the PIC 40 for reference.
3. The Hard part is how to detect B0 action at any time ?

John

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Pushbutton Trigger

Post by kersing »

Just wondering, why not connect the P1 signal to B1 and skip the additional components? Or connect an infrared detector/sensitive photodiode to the PIC to detect the coin?
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
JLeith
Posts: 537
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 146 times
Been thanked: 26 times
Contact:

Re: Pushbutton Trigger

Post by JLeith »

Hello Kersing

Just wondering, why not connect the P1 signal to B1 and skip the additional components? Or connect an infrared detector/sensitive photodiode to the PIC to detect the coin?
The Circuit boards for the Photo diode and the P1 were from a earlier projects for a Pinball Machine I worked on. I just reused the Interface boards.

The major Hill is getting the PIC to detect B0 in the PIC40 during a LCD message with a 5-10ms Relay Ground to B0.
Maybe when I figure out or have others help I might be able to use P1 into the B0 port ?

John

viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 43 times
Been thanked: 60 times
Contact:

Re: Pushbutton Trigger

Post by viktor_au »

Hello John

Thank you for the information.

I have attached Arduino Mega design. I have started with PIC years ago and moved to Arduino finally.
It is easy for me to work with Arduino. You can change/adapt it to PIC.
Have a look at the attached FC8 program 'Mega_PachinkoMod_x'.

About Ard Mega design

This is a very basic / draft version. It is not finished.
Each game has a time limit. Time starts only when the 1st ball is up.
Note: FC8 simulation time is not correct.

There is a ball tray at the bottom of machine for apprx 300 balls.
User loads 250 balls out of it into the Feeder Tray (at the top of the machine).
Ard Mega design uses 50 balls for testing only.
Balls suppose to roll down into the Playing Tray.
The balls fall vertically through an array of pins, levers, cups, traps and obstacles until they enter a payoff target or reach the bottom of the playfield.
As machine has 3 winning 'butterflies', we need to add 3 end-switches, to collect information about the number of winnings. Ball-up sensor - or the end-switch used. Sensor counts how many balls went/thrown up.
Note: FC8 Ard Mega design: only one butterfly sensor is activated.
-----------
If a launched ball lands in one of certain places (butterfly) it will be counted and added back into the Feeder Tray.
Time for play is extended, but still counting down.
If the time is out and user has some won balls in the feeder tray - they can be changed for prize or money.
If game time length is the same as the default value, the won score will be saved in EEPROM memory and will remain in memory (with power off) until the stored value for the game time length is changed OR until ALL stored values are restored OR until a higher score is recorded. Note: not activated in that version.
To play: push Playing Lever and snap-release to force the ball up. Important to very the forcing power to throw the ball into a needed trajectory. Does solenoid can imitate that? If not - something else can be used.

Logics:
User inserts the coin.
Game starts after the first shot/ball out is sensed.
Time will be counted down after the first shot is done.
Please have a look on PIC diagram.
When coin is inserted, the transistor base goes LOW, the relay -> On,
NO -> disconnects.
NC-> connects PIC B0 to the ground? Is it a good idea? Maybe better to connect B0 to +5v?
In Ard Mega design the +5v supplied to MC pin.
Solenoid question.
Matrix flowcode solenoid tutorial suggests to connect the solenoid via transistor (check the diagram).
Note: Ard Mega design doesn't use solenoid.

Display
Ssd1306 i2c is used in this design as it occupies only 2 pins (C4,C5).
-------------------------
Please note.
This is a very quick design. Not finalised.
You have to change it to your needs.
If you have more sensors connected (on table), change the code, etc
Attachments
Mega_PachincoMod_4.fcfx
(48.51 KiB) Downloaded 131 times
Coin_Sensor_5.jpg
Coin_Sensor_5.jpg (96.13 KiB) Viewed 189871 times

User avatar
JLeith
Posts: 537
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 146 times
Been thanked: 26 times
Contact:

Re: Pushbutton Trigger

Post by JLeith »

Hi Viktor

Excellent design.
Question
1. On the PNP won't the relay be on for say 5ms sending a Logic 1 to BO ?
2. How to detect when B0 is high when sending info to the LCD or ( SSD1306 )

will play on the bread board and see how it works.

Thank you
John

chipfryer27
Valued Contributor
Valued Contributor
Posts: 617
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 195 times
Contact:

Re: Pushbutton Trigger

Post by chipfryer27 »

Hi

Enjoying these posts and your project appears to have caught the interest of many :)

As per a previous post, the INT0 pin is Port B0 so you need to move anything else you have assigned to that pin elsewhere. Viktor's diagram has the display on Port B2-B7 so B0 is free to detect the coins.

The INT0 interrupt can be defined to trigger on a rising or falling pulse (rising in Viktor's HW example) however the pin needs to be held low to prevent it floating via a resistor.

Regards

viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 43 times
Been thanked: 60 times
Contact:

Re: Pushbutton Trigger

Post by viktor_au »

Hello John

Re: Relay time
I am not sure John.
I think it is less than 10mS.
Please find out:
https://mechatrofice.com/arduino/relay-timer-switch
Understanding Time Delay Relay Functions - https://www.macromatic.com/support/know ... -functions
5V Relay Module – How it Works and Application - https://www.geya.net/5v-relay-module-how-it-works-
How to setup - https://www.circuitbasics.com/setting-u ... e-arduino/

Re: How to detect when B0 is high
Ard Mega has D4 pin connected to relay (not B0).
PIC has B0 connected to relay contact.
I am not sure why do you ask that.
As in FC6/8 switch represents the relay NC contact, the SwCoin or SwRelay does the job -> it detects the B0 state.

I changed the label of this switch from SwCoin to SwRelay for easy understanding.

coin_state = SwRelay::ReadState()

User avatar
JLeith
Posts: 537
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 146 times
Been thanked: 26 times
Contact:

Re: Pushbutton Trigger

Post by JLeith »

Hello Viktor and Chipfryer27

This is a treat getting help in making the project work.

I have a flip PIC drawing
Mega Design.jpg
Mega Design.jpg (65.66 KiB) Viewed 189850 times
I use the LCD 8 pin have not SSD 2pin

I will work out the design. I ordered the Solenoid from China so it will be hopefully by end of April.

John

viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 43 times
Been thanked: 60 times
Contact:

Re: Pushbutton Trigger

Post by viktor_au »

Hello
Please pay attention to chipfryer27 note about the B0 pin state.
It need the 10k resistor (added to schematic).
You have to click on 'thank you' btn for chipfryer27.

Looks like you don't plan to use the 'butterfly' end-switches.
How do you count the win balls?

PS
Relay NO/NC contacts changed
Attachments
PIC_schematic_2.jpg
PIC_schematic_2.jpg (78.76 KiB) Viewed 189847 times

viktor_au
Posts: 342
Joined: Fri Jan 26, 2018 12:30 pm
Location: South Australia
Has thanked: 43 times
Been thanked: 60 times
Contact:

Re: Pushbutton Trigger

Post by viktor_au »

Is it possible John to show the front panel of your Pachinko machine?
Not a very small size picture, but a big one?

chipfryer27
Valued Contributor
Valued Contributor
Posts: 617
Joined: Fri Jun 06, 2014 3:53 pm
Has thanked: 184 times
Been thanked: 195 times
Contact:

Re: Pushbutton Trigger

Post by chipfryer27 »

Hi

I agree with Viktor, a picture of the machine would be nice to see. As a child on holiday (many) years ago I used to play similar in the very under-equipped amusement arcades. One venue even had pre-decimalisation machines and you had to buy "old" currency to use, at inflated prices. Probably worth a fortune today if they survived.

Viktor raises a good question as to how you will count the number of balls though. Is it enough to just assume three have been issued?

Regards

Post Reply