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 Serial Data Output / Sega G-Loc Project  (Read 902 times)

0 Members and 1 Guest are viewing this topic.

BertyB2

  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 2
  • Last login:February 17, 2024, 03:01:40 am
  • I want to build my own arcade controls!
MAMEHooker Serial Data Output / Sega G-Loc Project
« on: November 09, 2023, 03:10:33 am »
Hi Team,

I am working on retrofitting MAME / Arduino into a G-Loc Deluxe arcade machine. I am still early in the process but I am working on code to get MAMEHooker to send serial commands to my Arduino for the requested motor position and speed, but I am not getting any data sent over the serial port.

My G-Loc INI is as follows;
Code: [Select]
[General]
MameStart=cmo 4 baud=9600_parity=N_data=8_stop=1
MameStop=cmc 4
StateChange=
OnRotate=
OnPause=
[KeyStates]
RefreshTime=
[Output]
left_motor_position_nor=cmw 4 Q, cmw 4 %S%, cmw 4 x,
right_motor_position_nor=cmw 4 R., cmw 4 %S%, cmw 4 x,
left_motor_position=
right_motor_speed=cmw 4 T, cmw 4 %S%, cmw 4 x,
right_motor_position
left_motor_speed=cmw 4 S, cmw 4 %S%, cmw 4 x,
start_lamp=cmw 4 5, cmw 4 %S%, cmw 4 x,

So, the hope is that COM port 4 is opened, and then the raw variables are sent out. For example, if the value for "left_motor_position_nor" is the integer 23, the command to be sent over COM4 would be "Q23x".

Similarly, if the value of left_motor_speed is the integer 7, then the command to be sent over COM4 is meant to be S7x.

My Arduino code so far is designed to parse these COM commands and appears to be working when I send commands manually via the Arduino IDE serial monitor.

Code: [Select]
int motorPosQ = 14;
int motorPosR = 15;
int motorSpeedS = 0;
int motorSpeedT = 0;
boolean newCommandReceivedQ = false;
boolean newCommandReceivedR = false;

void setup() {
  Serial.begin(9600);
  pinMode(3, OUTPUT);  // Set the PWM pin for motor S
  pinMode(5, OUTPUT);  // Set the PWM pin for motor T
}

void loop() {
  while (Serial.available() > 0) {
    char command = Serial.read();
    int value = 0;

    if (command == 'x') {
      break;
    }

    if (Serial.available() > 0) {
      value = Serial.parseInt();
    }

    switch (command) {
      case 'Q':
        motorPosQ = value;
        newCommandReceivedQ = true;
        break;
      case 'R':
        motorPosR = value;
        newCommandReceivedR = true;
        break;
      case 'S':
        motorSpeedS = map(value, 1, 7, 0, 255);
        analogWrite(3, motorSpeedS);
        break;
      case 'T':
        motorSpeedT = map(value, 1, 7, 0, 255);
        analogWrite(5, motorSpeedT);
        break;
      default:
        // Handle unrecognized command here
        break;
    }
  }

  // Print the values of the four motors
  Serial.print("Motor Q: ");
  Serial.println(motorPosQ);
  Serial.print("Motor R: ");
  Serial.println(motorPosR);
  Serial.print("Motor S Speed: ");
  Serial.println(motorSpeedS);
  Serial.print("Motor T Speed: ");
  Serial.println(motorSpeedT);

  // Read analog inputs from potentiometers
  if (!newCommandReceivedQ) {
    int analogValueQ = analogRead(A0);
    motorPosQ = map(analogValueQ, 0, 1023, 0, 32);
  }
  if (!newCommandReceivedR) {
    int analogValueR = analogRead(A1);
    motorPosR = map(analogValueR, 0, 1023, 0, 32);
  }

  // Print the values of the two motor positions
  Serial.print("Motor Q Position: ");
  Serial.println(motorPosQ);
  Serial.print("Motor R Position: ");
  Serial.println(motorPosR);

  delay(3000);
}

So it looks like I have stuffed something up in the MAMEHooker INI. I've tried to use Putty to see what data is being sent out of COM4 and cannot see anything. Your wisdom is greatly apprecaited!  :)

baritonomarchetto

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 806
  • Last login:Today at 07:40:31 am
Re: MAMEHooker Serial Data Output / Sega G-Loc Project
« Reply #1 on: November 09, 2023, 12:12:12 pm »
Hopefully Howard will chime in and correct me, but the %s% variable is not an integer, but a boolean. It represents the output actual state (high or low).
Is it possible that the positions are defined by a PWM frequency? Check the format directly in mamehooker

baritonomarchetto

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 806
  • Last login:Today at 07:40:31 am
Re: MAMEHooker Serial Data Output / Sega G-Loc Project
« Reply #2 on: November 09, 2023, 05:39:04 pm »
This is some valuable info I found lurking the internet:
"Actually when the game is active each board drives the motor always at 100% duty.
As it does not have any breaks and it needs to hold the moving part with the player's weight - it always does 100% pwm duty and then alternates between up/down every 32μs. 32μs up, 32μs down. 64μs full cycle.
This holds the motor in place.
When the cab goes up on startup, I'm getting 37.5μs "up", 26.5μs "down", so around 58.5% up.
When it slowly returns back down, it is 30.2μs "up", 33.8μs "down".
Basically it is 15Khz (15625Hz) pwm, but it drives "direction", not "enable" pin."

I think it confirms that position and velocity are PWM signals and their signal variables booleans.
Try my code eventually (it is tested and fully working)
https://coinoparena.forumfree.it/m/?t=77556101
« Last Edit: November 09, 2023, 05:58:14 pm by baritonomarchetto »

BertyB2

  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 2
  • Last login:February 17, 2024, 03:01:40 am
  • I want to build my own arcade controls!
Re: MAMEHooker Serial Data Output / Sega G-Loc Project
« Reply #3 on: November 09, 2023, 06:29:33 pm »
Thanks for the reply. MAMEHooker shows the variable outputs for the motor position and speed output.

For motor position, it is a integer value between 0-32. For motor speed, another integer value between 1-7. For motor speed, 1 is no movement and 7 is maximum speed.

The program I am writing does things a little differently to the original hardware in that I am not reporting motor position or speed back to the game board, but back to the Arduino.

I'll take another look at the GLoc INI as I wasn't aware that "%s%" was used for Boolean.

baritonomarchetto

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 806
  • Last login:Today at 07:40:31 am
Re: MAMEHooker Serial Data Output / Sega G-Loc Project
« Reply #4 on: November 10, 2023, 12:22:38 am »
AFAIK %s% is the actual state of the output. If you say mamehooker shows those numbers, probably it's not a boolean as I had intended up to now but a byte or a int.
I am sorry my previous experience is not applicable here. I had success with rumble motors because they work as PWM, with rumble intensity given by the frequency of state change.