Main > Driving & Racing Cabinets
Adding Race Leader lights - advice needed
jorgenjl2:
--- Quote from: buttersoft on March 21, 2023, 09:23:48 pm ---So you run MAMEhooker as admin, set mame path and enable hooking. Then, I hope Baritonomarchetto's is ok with me cribbing from his post and site(http://forum.arcadecontrols.com/index.php/topic,167200.msg1761662.html#msg1761662)
--- Quote ---/*
Arduino - Mamehooker outputs read setup sketch
This sketch lets Arduino read outputs signals from
Howard Casto's Mamehooker.
Pins from #2 to #13 are set to outputs and can be used
to send hardware outputs signals.
Here is an example of mamehooker .ini code
(message sent to Arduino serial port COM4):
[General]
MameStart=cmo 4 baud=9600_parity=N_data=8_stop=1
MameStop=cmc 4
StateChange=
OnRotate=
OnPause=
[KeyStates]
RefreshTime=
[Output]
lamp0=
lamp1=cmw 4 3., cmw 4 %s%, cmw 4 x
lamp2=cmw 4 4., cmw 4 %s%, cmw 4 x
lamp3=cmw 4 5., cmw 4 %s%, cmw 4 x
lamp4=cmw 4 6., cmw 4 %s%, cmw 4 x
lamp5=cmw 4 7., cmw 4 %s%, cmw 4 x
lamp6=cmw 4 8., cmw 4 %s%, cmw 4 x
lamp7=cmw 4 9., cmw 4 %s%, cmw 4 x
lamp8=cmw 4 10., cmw 4 %s%, cmw 4 x
lamp9=cmw 4 11., cmw 4 %s%, cmw 4 x
lamp10=cmw 4 12., cmw 4 %s%, cmw 4 x
lamp11=cmw 4 13., cmw 4 %s%, cmw 4 x
Code adapted from fruit-emu.com (majoris and eric)
by Barito, 2018
*/
int pin;
int value;
void setup() {
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);
Serial.begin(9600);
}
void loop(){
while (Serial.available()>0){
pin = Serial.parseInt();
value = Serial.parseInt();
if (Serial.read() == 'x'){
digitalWrite(pin, value);
}
}
--- End quote ---
The actual arduino code is the part from "int pin;". Before that in an example ini file. When you run a MAME game and everything is set right, MAMEhooker generates an ini file with the same name as the game zip. That way you know what the outputs are called. Outrunners is a side-by-side driving game running from a single board. One instance of the game is for two players, and generates the orunners.ini file below, to which has been added some com port config info to start and stop things.
--- Quote ---[General]
MameStart=cmo 9 baud=9600_parity=N_data=8_stop=1
MameStop=cmc 9
StateChange=
OnRotate=
OnPause=
[KeyStates]
RefreshTime=
[Output]
MA_Check_Point_lamp=cmw 9 2., cmw 9 %s%, cmw 9 x
MA_Race_Leader_lamp=cmw 9 6., cmw 9 %s%, cmw 9 x
MA_Steering_Wheel_motor=
MA_DJ_Music_lamp=
MA_<<_>>_lamp=
MB_Check_Point_lamp=cmw 9 4., cmw 9 %s%, cmw 9 x
MB_Race_Leader_lamp=cmw 9 5., cmw 9 %s%, cmw 9 x
MB_Steering_Wheel_motor=
MB_DJ_Music_lamp=
MB_<<_>>_lamp=
--- End quote ---
MAMEhooker sends a message each time the state of one of those outputs changes - as long as there's any instructions next to that output. in this example the com port is configured up the top, and the Leader and Checkpoint lamps for P1 and P2 are sending data over it. So, each time the MA checkpoint lamp turns on or off it writes "2." to com port 9, then writes the state of the lamp (%s%) to com port 9, then terminates (x's) the com port write). The arduino code, above, reads the serial message, and acts on it to turn on an output.
The MAMEhooker docs folder goes into much more detail about different devices and different commands and ways to use them. Most TP games, M2emu, and others can be directly seen by MAMEhooker once you turn outputs on in either TP itself, or Boom's FFB plugin. Howard's site contains info about titlebar hooking for emulators/games that MAMEhooker doesn't automatically see, like Supermodel.
Note that an arduino can't deliver much current. You should use transistors or relays to deliver more. Baritono's site linked above provides some options for doing that.
--- End quote ---
Awesome! How did you get Mamehooker to send serial commands to the Arduino? I have a led strip configured via my Arduino nano to turn on and do various effects that look great. I also have it so that in the Arduino ide serial monitor I can send “6.,1,x” to turn on the led strip and “6.,0,x” to turn it off which works great. I also have mamehooker configured and I can see the games lamps changing as expected in the mamehooker debug window but no matter what I do, Mamehooker sends nothing to the Arduino. I have tried:
1) Mamehooker as right click admin and as regular open and with hooking
2) Tried multiple games that all show fine in debug window
3) Go to test option in mamehooker to get around ini games and send test commands but nothing is sent
4) Tried a 2nd computer
5) tried a different ch340 driver on the second computer
6) Read the install doc again
7) Created bat to open Mamehooker and set Mamehook.exe to admin option in properties
Yours just sends serial commands without anything else? Am I missing something stupid? You can just go to the test menu in Mamehooker and send “cmw 4 6., cmw 4 %s%, cmw 4 x” and it works fine changing the 4’s to your com port?
buttersoft:
i haven't actually tried the command interface in MAMEhooker itself. But it works as shown, yes. I program the arduino with that code, and then script the orunners.ini file as so.
Have you tried programming only that code onto your arduino, and leaving the rest out, for testing?
baritonomarchetto:
Launch mamehooker with admin privileges only the first time you run it. Then there's no more the need for admin privileges (it could be detrimental after first run, not sure why but I can confirm I had problems in more than one PC when admin priv. were given).
Is mamehooker sending serial messages to the correct COM port? It must be the arduino's COM port
jorgenjl2:
Thanks guys. Mamehooker was working fine and it was my Arduino code. I downloaded Serial Port Monitor (free 14 day trial) and I was able to use the Mamehooker test menu (after a few opening and closing ports to still monitor but not conflict on the port) to validate that my mamehooker test was using 6 followed by a 1 (or 0 for off) followed by an x. Whereas my arduino test was sending "6,1,x" all at once and my parsing of the code used a comma. Anyhow I fixed the code and we are in business. I will post a tutorial with all of my code and how exactly I am did all of this once I have it finalized. Thanks!
baritonomarchetto:
You were not using the code buttersoft linked you, then, being that tested and working...
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version