Main Restorations Software Audio/Jukebox/MP3 Everything Else Buy/Sell/Trade
Project Announcements Monitor/Video GroovyMAME Merit/JVL Touchscreen Meet Up Retail Vendors
Driving & Racing Woodworking Software Support Forums Consoles Project Arcade Reviews
Automated Projects Artwork Frontend Support Forums Pinball Forum Discussion Old Boards
Raspberry Pi & Dev Board controls.dat Linux Miscellaneous Arcade Wiki Discussion Old Archives
Lightguns Arcade1Up Try the site in https mode Site News

Unread posts | New Replies | Recent posts | Rules | Chatroom | Wiki | File Repository | RSS | Submit news

  

Author Topic: mamehooker and arduino mega, can it work?  (Read 9807 times)

0 Members and 1 Guest are viewing this topic.

abispac

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1497
  • Last login:Yesterday at 01:01:09 pm
mamehooker and arduino mega, can it work?
« on: January 19, 2019, 01:40:52 pm »
so wondering around the internet i found that some folks at MFME forums have managed to use an arduino mega as an ipac and it seems to work like a charm, them some dude named eric claimed he used all the time with mame. im trying to set this up and it works just fine.
code for using arduino on mamehooker is simple:
Code: [Select]
void setup() {
  Serial.begin(9600);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(54, INPUT);
pinMode(55, OUTPUT);
}
void loop() {
  while (Serial.available() > 0) {
    int pin = Serial.parseInt();
    int value = Serial.parseInt();
  if (Serial.read() == 'x') {
    digitalWrite(pin, value);
    Serial.println();
    }
  }
}


now after that i just modify the rom ini with something like

Code: [Select]
[General]
MameStart=cmo 4 baud=9600_parity=N_data=8_stop=1
MameStop=cmc 4
StateChange=
OnRotate=
OnPause=
[KeyStates]
RefreshTime=
[Output]
lamp1=cmw 4 2., cmw 4 %s%, cmw 4 x
lamp2=cmw 4 3., cmw 4 %s%, cmw 4 x
lamp3=cmw 4 4., cmw 4 %s%, cmw 4 x
lamp4=cmw 4 5., cmw 4 %s%, cmw 4 x
lamp5=cmw 4 6., cmw 4 %s%, cmw 4 x
lamp8=cmw 4 9., cmw 4 %s%, cmw 4 x
lamp6=cmw 4 7., cmw 4 %s%, cmw 4 x
lamp0=
lamp9=cmw 4 10., cmw 4 %s%, cmw 4 x
lamp12=cmw 4 13., cmw 4 %s%, cmw 4 x
lamp7=cmw 4 8., cmw 4 %s%, cmw 4 x
lamp10=cmw 4 11., cmw 4 %s%, cmw 4 x
lamp11=cmw 4 12., cmw 4 %s%, cmw 4 x
lamp13=cmw 4 13., cmw 4 %s%, cmw 4 x
lamps work like a charm.
I just need help with one thing i can not figure out,the hopper,  i would like the output 55 to be the hopper trigger so on pin 55 should  stay on, not flashing until input 54 wich is the sensor sends a number of pulses, anyway heres the code hope someone can help me out. thanks
« Last Edit: January 29, 2019, 10:16:40 pm by abispac »

Howard_Casto

  • Idiot Police
  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 19399
  • Last login:March 16, 2024, 05:59:16 pm
  • Your Post's Soul is MINE!!! .......Again??
    • The Dragon King
Re: mamehooker and aruino mega, can it work?
« Reply #1 on: January 19, 2019, 03:47:11 pm »
Well are there a fixed number of pulses (1-9 or whatever)?  You just need to send multiple commands for each state slot, turning the appropriate output off, waiting (there's a command for that) and then turning it back on again.  You should be able to figure that out via the drop down menus for adding commands within the app. 

abispac

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1497
  • Last login:Yesterday at 01:01:09 pm
Re: mamehooker and aruino mega, can it work?
« Reply #2 on: January 19, 2019, 05:18:10 pm »
You should be able to figure that out via the drop down menus for adding commands within the app.
:laugh2: cmon man , make it easy for me  :laugh2: but you right, im a test and fail and hopefully succeed and post result. thanks man

abispac

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1497
  • Last login:Yesterday at 01:01:09 pm
Re: mamehooker and aruino mega, can it work?
« Reply #3 on: January 20, 2019, 11:24:16 am »
Well are there a fixed number of pulses (1-9 or whatever)?  You just need to send multiple commands for each state slot, turning the appropriate output off, waiting (there's a command for that) and then turning it back on again.  You should be able to figure that out via the drop down menus for adding commands within the app.
i sent you a pm.  :)

Zipper

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 92
  • Last login:November 26, 2022, 12:32:50 pm
  • I've Built My Own Arcade Controls!!
Re: mamehooker and aruino mega, can it work?
« Reply #4 on: January 20, 2019, 04:10:19 pm »
I use mamehooker with an Arduino. It works well. Here I’m reading Neo Geo outputs to do credit LEDs and marquees.

This is the Neo cab I made with the Arduino inside.

Incase it helps, all my code is here in a build log:
https://forum.arcadeotaku.com/viewtopic.php?f=6&t=35743
Reading outputs from Mame on a Pi is fairly straightforward too.

... the Pi is under the screen.
This was based on a great bit of code I found in github which you may find useful:
https://github.com/arfink/
You don’t need an Arduino at all... just control the Pi pins from Mame!

 8)
« Last Edit: January 20, 2019, 04:44:12 pm by Zipper »

abispac

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1497
  • Last login:Yesterday at 01:01:09 pm
Re: mamehooker and aruino mega, can it work?
« Reply #5 on: January 20, 2019, 05:49:13 pm »
thanks for the info, i will take a look, im not planing on using a pi just the arduino, hope i can finish my proyect.
I use mamehooker with an Arduino. It works well. Here I’m reading Neo Geo outputs to do credit LEDs and marquees.

This is the Neo cab I made with the Arduino inside.

Incase it helps, all my code is here in a build log:
https://forum.arcadeotaku.com/viewtopic.php?f=6&t=35743
Reading outputs from Mame on a Pi is fairly straightforward too.

... the Pi is under the screen.
This was based on a great bit of code I found in github which you may find useful:
https://github.com/arfink/
You don’t need an Arduino at all... just control the Pi pins from Mame!

 8)

baritonomarchetto

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 805
  • Last login:Yesterday at 02:42:27 am
Re: mamehooker and aruino mega, can it work?
« Reply #6 on: January 21, 2019, 01:45:47 am »
I made some testing too, some month ago :)
Abispac's code resembles mine (which in turn resembles that of others...)


abispac

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1497
  • Last login:Yesterday at 01:01:09 pm
Re: mamehooker and aruino mega, can it work?
« Reply #7 on: January 21, 2019, 06:43:16 am »
I made some testing too, some month ago :)
Abispac's code resembles mine (which in turn resembles that of others...)

well, led outputs are easy, i dont have a problem with that , is just the hopper that dont work right.

Zipper

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 92
  • Last login:November 26, 2022, 12:32:50 pm
  • I've Built My Own Arcade Controls!!
Re: mamehooker and aruino mega, can it work?
« Reply #8 on: January 21, 2019, 10:24:42 am »
At the moment your arduino code looks for an 'x', then turns on/off the pin (lamp) that it just read over serial.
If mame has a hopper output (you'd need to check), then maybe suffix that output with 'y' in the ini file... then, with "if (Serial.read() == 'y')" you can do something else other than light up a lamp.
Check out my example if it helps. I read in 3 digits and treat them all differently. One is a 'tens' digit for the credit display, one is a 'units' for the credit display... and the 3rd indicates which marquee to light up.
I've not done it the most efficient way at all, but muddled through and it works well.

abispac

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1497
  • Last login:Yesterday at 01:01:09 pm
Re: mamehooker and aruino mega, can it work?
« Reply #9 on: January 21, 2019, 02:09:31 pm »
At the moment your arduino code looks for an 'x', then turns on/off the pin (lamp) that it just read over serial.
If mame has a hopper output (you'd need to check), then maybe suffix that output with 'y' in the ini file... then, with "if (Serial.read() == 'y')" you can do something else other than light up a lamp.
Check out my example if it helps. I read in 3 digits and treat them all differently. One is a 'tens' digit for the credit display, one is a 'units' for the credit display... and the 3rd indicates which marquee to light up.
I've not done it the most efficient way at all, but muddled through and it works well.
it would probably helpmore if i knew what x and y are for or even better, a list of mamehooker commands

baritonomarchetto

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 805
  • Last login:Yesterday at 02:42:27 am
Re: mamehooker and aruino mega, can it work?
« Reply #10 on: January 22, 2019, 02:04:44 am »
You have set a 3 variables serial message coming from mamehooker: the first is the arduino pin you want to control, the second the state of the pin you want to set and the third is a terminal message (x) that tells arduino to do its magic. In this case is a simple digitalWrite that resembles the new state of the pin, but it could be any function.

abispac

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1497
  • Last login:Yesterday at 01:01:09 pm
Re: mamehooker and aruino mega, can it work?
« Reply #11 on: January 26, 2019, 12:40:22 pm »
You have set a 3 variables serial message coming from mamehooker: the first is the arduino pin you want to control, the second the state of the pin you want to set and the third is a terminal message (x) that tells arduino to do its magic. In this case is a simple digitalWrite that resembles the new state of the pin, but it could be any function.
im damn potato, cant do s h i t with this arduino LOL im a keep trying do...

baritonomarchetto

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 805
  • Last login:Yesterday at 02:42:27 am
Re: mamehooker and aruino mega, can it work?
« Reply #12 on: January 27, 2019, 02:29:30 am »
Howard asked you on post #2 some detail. For sure giving him an answer could help you ;)
Don't expect people write code for you (it's difficult to debug an hardware without... the hardware!) but some help could come.

abispac

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1497
  • Last login:Yesterday at 01:01:09 pm
Re: mamehooker and aruino mega, can it work?
« Reply #13 on: January 27, 2019, 09:30:30 pm »
Howard asked you on post #2 some detail. For sure giving him an answer could help you ;)
Don't expect people write code for you (it's difficult to debug an hardware without... the hardware!) but some help could come.
well english is my second lenguage so i thought when he said i could figure it out my self from the drop down menu, to actually find the answer myself.

abispac

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1497
  • Last login:Yesterday at 01:01:09 pm
Re: mamehooker and aruino mega, can it work?
« Reply #14 on: January 27, 2019, 09:31:14 pm »
Im a drop the arduino and start a new topic with a pacdrive. thanks guys.

Howard_Casto

  • Idiot Police
  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 19399
  • Last login:March 16, 2024, 05:59:16 pm
  • Your Post's Soul is MINE!!! .......Again??
    • The Dragon King
Re: mamehooker and aruino mega, can it work?
« Reply #15 on: January 28, 2019, 02:20:06 am »
Because English is your second language, the private message you sent me left me scratching my head.  I wasn't sure what you were wanting help with exactly.  When the guys jumped in I assumed the info they gave you would be enough for you to figure it out.   Sorry I wasn't more help.

abispac

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1497
  • Last login:Yesterday at 01:01:09 pm
Re: mamehooker and aruino mega, can it work?
« Reply #16 on: January 28, 2019, 07:27:45 pm »
Because English is your second language, the private message you sent me left me scratching my head.  I wasn't sure what you were wanting help with exactly.  When the guys jumped in I assumed the info they gave you would be enough for you to figure it out.   Sorry I wasn't more help.
Basacly i dont mind buying you a beer or pay whatever amount you ask for the solution, please forgive me if im to hard to understand.let me know if you want me to explain everything again.

Howard_Casto

  • Idiot Police
  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 19399
  • Last login:March 16, 2024, 05:59:16 pm
  • Your Post's Soul is MINE!!! .......Again??
    • The Dragon King
Re: mamehooker and aruino mega, can it work?
« Reply #17 on: January 28, 2019, 10:00:22 pm »
Well I can't write a script for you or program your Arduino because I don't have the hardware you do.  I can answer specific questions though.  Just going by what you told me it sounds like your issue is the hopper and you want mamehooker to send pulses to it.  It makes far more sense to alter the Arduino code to accept a number for the hopper output and have it send the pulses.  To do that you use a "For Loop" where you turn the pin off, use the "delay" command and then turn the pin back on, looping for whatever value is passed from mamehooker.  I would link to some example code, but the descriptions are going to be in English, so it might be better for you to search for "Arduino For loop" in your own language. 

abispac

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1497
  • Last login:Yesterday at 01:01:09 pm
Re: mamehooker and aruino mega, can it work?
« Reply #18 on: January 29, 2019, 10:15:37 pm »
well , im not sure if the  "for loop" option for arduino suits my needs, so lets start little by little.
With the following code in the arduino and the mamehooker ini for the game, i can send the coins being paid out no problem, 5 coins 5 pulses, x mount of coins = same x amount of pulses. the problem is, the arduino starts with the pin on, when it should be off, if i use LOW instead of OUTPUT in the arduino code it starts with the pin off, but mamehooker wont send the pulses.  Can we start by solving this please. heres the code. Im posting the code again, im using pin 55 as the output, adn a relay to catch the coin pulses, not sure if the video gets the clicks clear enough. Please pardon my ignorance and thanks for the patience.  Ps im using an arduino mega and a 5v relay.
https://mega.nz/embed#!CZFSgSJa!B0ye7KlKuQfPEX7-YjYtFB5ZkX80RSFQwRJEjDJ2EOQ small video

Code: [Select]
void setup() {
  Serial.begin(9600);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
pinMode(55, OUTPUT);
}
void loop() {
  while (Serial.available() > 0) {
    int pin = Serial.parseInt();
    int value = Serial.parseInt();
  if (Serial.read() == 'x') {
    digitalWrite(pin, value);
    Serial.println();
    }
  }
}
Code: [Select]
[General]MameStart=cmo 4 baud=9600_parity=N_data=8_stop=1
MameStop=cmc 4
StateChange=
OnRotate=
OnPause=
[KeyStates]
RefreshTime=
[Output]
lamp1=cmw 4 2., cmw 4 %s%, cmw 4 x
lamp2=cmw 4 3., cmw 4 %s%, cmw 4 x
lamp3=cmw 4 4., cmw 4 %s%, cmw 4 x
lamp4=cmw 4 5., cmw 4 %s%, cmw 4 x
lamp5=cmw 4 6., cmw 4 %s%, cmw 4 x
lamp8=cmw 4 9., cmw 4 %s%, cmw 4 x
lamp6=cmw 4 7., cmw 4 %s%, cmw 4 x
lamp0=
lamp9=cmw 4 10., cmw 4 %s%, cmw 4 x
lamp12=cmw 4 13., cmw 4 %s%, cmw 4 x
lamp7=cmw 4 8., cmw 4 %s%, cmw 4 x
lamp10=cmw 4 11., cmw 4 %s%, cmw 4 x
lamp11=cmw 4 12., cmw 4 %s%, cmw 4 x
lamp13=cmw 4 13., cmw 4 %s%, cmw 4 x
led2=cmw 4 55., cmw 4 %s%, cmw 4 x


Howard_Casto

  • Idiot Police
  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 19399
  • Last login:March 16, 2024, 05:59:16 pm
  • Your Post's Soul is MINE!!! .......Again??
    • The Dragon King
Re: mamehooker and arduino mega, can it work?
« Reply #19 on: January 30, 2019, 12:31:33 am »
So you want the value sent by mamehooker to be inverted when it reaches the Arduino.... well just do that then. 

Right now you have: 

digitalWrite(pin, value);

Instead of writing "value" you need to write the inverse so make an "if then" statement to invert it.  So replace that line with the following lines:


if (value = 0)
{
     digitalWrite(pin, 1);
}
else
{
    digitalWrite(pin,0);
}


The might not work btw because I'm essentially coding blind without the hardware, but I think that should allow you to start with LOW

baritonomarchetto

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 805
  • Last login:Yesterday at 02:42:27 am
Re: mamehooker and arduino mega, can it work?
« Reply #20 on: January 30, 2019, 12:39:19 am »
It's likely using "!value" in place of "value" will work too
digitalWrite(pin, !value);
pinMode defines if the pin is an input or an output, so declaring LOW arduino trash the (non correct) information and define it as an input (default): that's why it stops working.
« Last Edit: January 30, 2019, 12:42:51 am by baritonomarchetto »

Howard_Casto

  • Idiot Police
  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 19399
  • Last login:March 16, 2024, 05:59:16 pm
  • Your Post's Soul is MINE!!! .......Again??
    • The Dragon King
Re: mamehooker and arduino mega, can it work?
« Reply #21 on: January 30, 2019, 01:14:15 pm »
I always forget about "not" commands....  different syntax in my language of choice. 

Anyway, you'd know more than me.  I've done exactly two projects with Arduino.  I just know that inverting it in mamehooker is way more involved so that isn't the way to do it. 

abispac

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1497
  • Last login:Yesterday at 01:01:09 pm
Re: mamehooker and arduino mega, can it work?
« Reply #22 on: January 30, 2019, 02:24:02 pm »
Yesterday was late and I'm at work right now, can't wait to get back home and test both options, will post my results, thanks guys

abispac

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1497
  • Last login:Yesterday at 01:01:09 pm
Re: mamehooker and arduino mega, can it work?
« Reply #23 on: January 30, 2019, 06:50:00 pm »
It's likely using "!value" in place of "value" will work too
digitalWrite(pin, !value);
pinMode defines if the pin is an input or an output, so declaring LOW arduino trash the (non correct) information and define it as an input (default): that's why it stops working.
did not work, pin starts on HIGH still
Code: [Select]
if (value = 0)
{
     digitalWrite(pin, 1);
}
else
{
    digitalWrite(pin,0);
}

abispac

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1497
  • Last login:Yesterday at 01:01:09 pm
Re: mamehooker and arduino mega, can it work?
« Reply #24 on: January 30, 2019, 06:55:29 pm »
So you want the value sent by mamehooker to be inverted when it reaches the Arduino.... well just do that then. 

Right now you have: 

digitalWrite(pin, value);

Instead of writing "value" you need to write the inverse so make an "if then" statement to invert it.  So replace that line with the following lines:


if (value = 0)
{
     digitalWrite(pin, 1);
}
else
{
    digitalWrite(pin,0);
}


The might not work btw because I'm essentially coding blind without the hardware, but I think that should allow you to start with LOW
this worked, pin started off but i fire up mamehooker and mame and the coins dont trigger the relay. it just stays off.
Code: [Select]
void setup() {
  Serial.begin(9600);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
pinMode(55, OUTPUT);
}
void loop() {
  while (Serial.available() > 0) {
    int pin = Serial.parseInt();
    int value = Serial.parseInt();
  if (value = 0)
{
     digitalWrite(pin, 1);
}
else
{
    digitalWrite(pin, 0);
}

  }
}

abispac

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1497
  • Last login:Yesterday at 01:01:09 pm
Re: mamehooker and arduino mega, can it work?
« Reply #25 on: January 30, 2019, 07:39:17 pm »
Howard, do you think it will be easyer to achieve this with the pacdrive? as in MFME does? if so, then ill just doit with a pacdrive.

slickam

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 52
  • Last login:March 18, 2024, 06:46:08 pm
  • I want to build my own arcade controls!
Re: mamehooker and arduino mega, can it work?
« Reply #26 on: January 30, 2019, 08:04:41 pm »
That should probably be "if (value == 0)".

baritonomarchetto

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 805
  • Last login:Yesterday at 02:42:27 am
Re: mamehooker and arduino mega, can it work?
« Reply #27 on: January 31, 2019, 12:33:57 am »
You removed the end message to the code ("x"): why is that?
It's very unlikely that settin !value doesn't work...
Another way to write it could be
Code: [Select]
value=!value;
digitalWrite(pin, value);
But it's equivalent.
« Last Edit: January 31, 2019, 12:36:10 am by baritonomarchetto »

abispac

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1497
  • Last login:Yesterday at 01:01:09 pm
Re: mamehooker and arduino mega, can it work?
« Reply #28 on: January 31, 2019, 07:34:21 am »
You removed the end message to the code ("x"): why is that?
It's very unlikely that settin !value doesn't work...
Another way to write it could be
Code: [Select]
value=!value;
digitalWrite(pin, value);
But it's equivalent.
Arduino:1.8.8 (Windows 10), Tarjeta:"Arduino Mega ADK"

C:\Users\Shaggy\Documents\Arduino\sketch_jan31a\sketch_jan31a.ino: In function 'void loop()':

sketch_jan31a:20:9: error: expected unqualified-id before '!' token

     int !value = Serial.parseInt();

         ^

sketch_jan31a:22:24: error: 'value' was not declared in this scope

     digitalWrite(pin, !value);

                        ^

exit status 1
expected unqualified-id before '!' token

Este informe podría contener más información con
"Mostrar salida detallada durante la compilación"
opción habilitada en Archivo -> Preferencias.

Zipper

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 92
  • Last login:November 26, 2022, 12:32:50 pm
  • I've Built My Own Arcade Controls!!
Re: mamehooker and arduino mega, can it work?
« Reply #29 on: January 31, 2019, 02:45:26 pm »
int !value = Serial.parseInt();

Remove the exclamation from that.

abispac

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1497
  • Last login:Yesterday at 01:01:09 pm
Re: mamehooker and arduino mega, can it work?
« Reply #30 on: January 31, 2019, 09:09:52 pm »
int !value = Serial.parseInt();

Remove the exclamation from that.
as stated before, pin starts on high or on, wich if i where using a hopper it would be spiting all coins.

Howard_Casto

  • Idiot Police
  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 19399
  • Last login:March 16, 2024, 05:59:16 pm
  • Your Post's Soul is MINE!!! .......Again??
    • The Dragon King
Re: mamehooker and arduino mega, can it work?
« Reply #31 on: January 31, 2019, 10:16:25 pm »
Why don't you immediately set it to low after initialization then?

It's starting to sound like you want to get this working for gambling purposes.  I'm not sure if I feel comfortable with that. 

baritonomarchetto

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 805
  • Last login:Yesterday at 02:42:27 am
Re: mamehooker and arduino mega, can it work?
« Reply #32 on: February 01, 2019, 12:30:39 am »
He has not understeded the code, nor what mamehooker is outputting, in my opinion, and trying to have this thing working by "creative" code manipulation... It will never work.

abispac

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1497
  • Last login:Yesterday at 01:01:09 pm
Re: mamehooker and arduino mega, can it work?
« Reply #33 on: February 01, 2019, 12:46:29 pm »
Why don't you immediately set it to low after initialization then?

It's starting to sound like you want to get this working for gambling purposes.  I'm not sure if I feel comfortable with that.
I would love to have a working casino machine with name games in my house, I already have a working casino cabinet with mfme so no, I don't want to profit this things , if I wanted to do that I could just buy the igrosoft boards and go with it, maybe it would be even cheaper as those boards are about 80 bucks. I will continue to search for a solution , thanks for any help.
« Last Edit: February 01, 2019, 06:05:22 pm by abispac »

abispac

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1497
  • Last login:Yesterday at 01:01:09 pm
Re: mamehooker and arduino mega, can it work?
« Reply #34 on: February 01, 2019, 12:47:14 pm »
He has not understeded the code, nor what mamehooker is outputting, in my opinion, and trying to have this thing working by "creative" code manipulation... It will never work.
I'm pretty sure there is a solution , and I will find it

baritonomarchetto

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 805
  • Last login:Yesterday at 02:42:27 am
Re: mamehooker and arduino mega, can it work?
« Reply #35 on: February 02, 2019, 03:28:25 am »
There's a solution for sure man, but you should study the starting code trying to understand every single line. After that you can start toying with it and you will surely find the way.
Actually you have not mastered that code, it's so clear... Spend some time on that first ;)

ericpower91

  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 1
  • Last login:November 20, 2020, 10:19:08 am
  • I want to build my own arcade controls!
Re: mamehooker and arduino mega, can it work?
« Reply #36 on: May 30, 2020, 08:13:30 am »
Hi Guys,




Eric

Howard_Casto

  • Idiot Police
  • Trade Count: (+1)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 19399
  • Last login:March 16, 2024, 05:59:16 pm
  • Your Post's Soul is MINE!!! .......Again??
    • The Dragon King
Re: mamehooker and arduino mega, can it work?
« Reply #37 on: May 30, 2020, 11:49:22 pm »
Please do not use mamehooker for gambling purposes.  I'll be forced to remove my software from the usual sites and quit releasing public updates if I find gambling machines running my software out in the wild. 

abispac

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 1497
  • Last login:Yesterday at 01:01:09 pm
Re: mamehooker and arduino mega, can it work?
« Reply #38 on: June 10, 2022, 02:08:26 am »
works
Code: [Select]
const int optoPin = 8; //this is the pin to which the optoswitch is connected
const int relePin = 3;
int pin;
int value;
bool optoState; //status of the opt
bool lastOptoState; //previous state of the opt
int coins = 0;
unsigned long startTime;
#define TIMEOUT 10000
//mamehooker setting cmw 4 %s%x on led2
 
void setup() {
  pinMode(optoPin, INPUT_PULLUP);
  pinMode(relePin, OUTPUT);
  digitalWrite(relePin, LOW);
  Serial.begin(9600); //start of serial communication
  optoState = digitalRead(optoPin);
}
 
void loop() {
  checkForCredits();
  releaseTokens();
  tokensCountDown();
}
 
void checkForCredits() {
  while (Serial.available() > 0) {
    value = Serial.parseInt();
    if (Serial.read() == 'x') {
      if (value > 0) {
        coins ++;
      }
    }
  }
}
 
void releaseTokens() {
  if (coins > 0) {
    // If the engine is stopped, I memorize the moment it starts.
    // This way I make sure to set the variable only on the rising edge of relePin
    if(digitalRead(relePin) == LOW){
      startTime = millis();
    }
    digitalWrite(relePin, HIGH); //token release
    optoState = digitalRead(optoPin);
  }
  else {
    digitalWrite(relePin, LOW); //STOP token release
  }
 
  // Only if the engine is still running, after 10 seconds from activation, I reset the output
  if(digitalRead(relePin) == HIGH){
    if(millis() - startTime > TIMEOUT ){
      digitalWrite(relePin, LOW); //STOP token release
      Serial.println("refill");
      Serial.print("gettoni non erogati:");
      Serial.println(coins);
      coins = 0;
      delay(100);
    }
  }
 
}
 
void tokensCountDown() {
  if (optoState != lastOptoState) { // if the status of the opt has changed (i.e. something is passing, in or out)
    lastOptoState = optoState;
    delay (100); //"economic" debounce (this is because in the change of state there may be fluctuations that lead to incorrect counts)
    if (lastOptoState == LOW && coins > 0) {
      coins = coins - 1 ; //decrease tokens
      startTime = millis(); //reset timer
      Serial.print("numero gettoni:");
      Serial.println(coins);
    }
  }
}