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;
[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.
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!