Car dashboard for ATS

Hello...I have been programming for a while now, but I am nowhere near perfect. I just got a Ford expedition dashboard at the local flea market. I bought it figuring I could use it in conjunction with American trucking simulator. I got all of the dash lights to work with the game and that's out of the way. Now I'm moving on to the gauges. Has anyone had experience with car stepper motors? I got 10 A4988 stepper motor driver boards for all the motors on the back. The stepper motors on the back have 4 pins. I am using Silas Parker's code and plugin for this. He used servos instead...but I want to use the steppers that are already on the dash.

Here is Silas Parker's website:

Here is an instructable showing the board and coding: https://www.google.com/amp/www.instructables.com/id/Drive-a-Stepper-Motor-with-an-Arduino-and-a-A4988-/%3Famp_page=true

Here is my current code: */
#include <Servo.h>

const int SPEEDO_PIN = A0;
const int RPM_PIN = A1;
const int FUEL_PIN = A5;
const int LEFT_INDICATOR = A2;
const int RIGHT_INDICATOR = A3;
const int PARKING_BREAK = A4;
const int FUEL_WARNING = 12;

// defines servo names
Servo speedo;
Servo rpm;
Servo fuel;
Servo cruise;

#define PACKET_SYNC 0xFF
#define PACKET_VER 2

#define SERVO_DIR_NORMAL false
#define SERVO_DIR_INVERT true
#define BAUD (9600)
int serial_byte;

void setup()
{
Serial.begin(115200);

speedo.attach(SPEEDO_PIN);
speedo.write(180);
rpm.attach(RPM_PIN);
rpm.write(180);
fuel.attach(FUEL_PIN);
fuel.write(40);
cruise.write(180);

pinMode(LEFT_INDICATOR, OUTPUT);
pinMode(RIGHT_INDICATOR, OUTPUT);
pinMode(PARKING_BREAK, OUTPUT);
pinMode(FUEL_WARNING, OUTPUT);

//range-splitter LED's
pinMode(22, OUTPUT);
pinMode(24, OUTPUT);
pinMode(26, OUTPUT);

digitalWrite(LEFT_INDICATOR, 0);
digitalWrite(RIGHT_INDICATOR, 0);
digitalWrite(PARKING_BREAK, 0);
digitalWrite(FUEL_WARNING, 0);

delay(600);

speedo.write(0);
rpm.write(0);
fuel.write(0);
digitalWrite(LEFT_INDICATOR, 1);
digitalWrite(RIGHT_INDICATOR, 1);
digitalWrite(PARKING_BREAK, 1);
digitalWrite(FUEL_WARNING, 1);

digitalWrite(22, 1);
digitalWrite(24, 1);
digitalWrite(26, 1);

delay(600);

speedo.write(180);
rpm.write(180);
fuel.write(85);
digitalWrite(LEFT_INDICATOR, 0);
digitalWrite(RIGHT_INDICATOR, 0);
digitalWrite(PARKING_BREAK, 0);
digitalWrite(FUEL_WARNING, 0);
digitalWrite(22, 0);
digitalWrite(24, 0);
digitalWrite(26, 0);

delay(1000);
}

void read_serial_byte_set_servo(Servo& servo, bool invert)
{
serial_byte = Serial.read();
serial_byte = (serial_byte < 0) ? 0 : ((serial_byte > 180) ? 180 : serial_byte);
if (invert)
servo.write(180 - serial_byte);
else
servo.write(serial_byte);
}

void read_serial_byte_set_servo_fuel(Servo& servo, bool invert)
{
serial_byte = Serial.read();
serial_byte = (serial_byte < 0) ? 0 : ((serial_byte > 180) ? 180 : serial_byte);
if (invert)
servo.write(85 - serial_byte); //set lower than the tach and speedo to limit movement.
else
servo.write(serial_byte);
}

void skip_serial_byte()
{
(void)Serial.read();
}

void digitalWriteFromBit(int port, int value, int shift)
{
digitalWrite(port, (value >> shift) & 0x01);
}

void loop()
{
if (Serial.available() < 16)
return;

serial_byte = Serial.read();
if (serial_byte != PACKET_SYNC)
return;

serial_byte = Serial.read();
if (serial_byte != PACKET_VER)
{
// lcd.clear();
// lcd.print("PROTOCOL VERSION ERROR");
return;
}

read_serial_byte_set_servo(speedo, SERVO_DIR_INVERT); // Speed
read_serial_byte_set_servo(rpm, SERVO_DIR_INVERT); // RPM

skip_serial_byte(); // Brake air pressure
skip_serial_byte(); // Brake temperature
read_serial_byte_set_servo_fuel(fuel, SERVO_DIR_INVERT); // Fuel ratio
skip_serial_byte(); // Oil pressure
skip_serial_byte(); // Oil temperature
skip_serial_byte(); // Water temperature
skip_serial_byte(); // Battery voltage

if (cruise.read() < 180)
{

}
if (cruise.read() > 179)
{
}

// Truck lights byte
serial_byte = Serial.read();
digitalWriteFromBit(LEFT_INDICATOR, serial_byte, 5);
digitalWriteFromBit(RIGHT_INDICATOR, serial_byte, 4);

// Warning lights bytes

serial_byte = Serial.read();
digitalWriteFromBit(PARKING_BREAK, serial_byte, 7);
digitalWriteFromBit(FUEL_WARNING, serial_byte, 3);

// Enabled flags
serial_byte = Serial.read();

// Text length
int text_len = Serial.read();

// Followed by text
if (0 < text_len && text_len < 127)
{
for (int i = 0; i < text_len; ++i)
{

while (Serial.available() == 0) // Wait for data if slow
{
delay(2);
}
}
}
}

So my code is fine the way it is...I just would like some guidance on how to convert the code to let me use the stepper motor drivers and steppers instead of the servos. Thanks!

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Your dashboard probably has these in it.

If you google x27.168 arduino

you may find some driving info.

Thanks.. Tom.. :slight_smile:

Thank you for the response! I didn't know how to use the forum and I just posted without even thinking. Thank you for the advice on how to use the forum.

So what would I have to change in my code to set up stepper motor drivers rather than servos??? The board has 3 wires that will go into the Arduino...ENABLE, DIRECTION, and STEP. I would like to know how to take the single servo data wire and bring it into a DIRECTION and a STEP wire so that the board can tell the steppers to move. The enable just gets set to low for normal operation. What I'm basically trying to say is that I don't know how to get the servo pins to correlate to a STEP and a DIRECTION in th code to work with the plug-in. The plug-in is in the original post under Silas Parker.

Hello Joseph3502,

sorry to revive an old thread, did you ever get Silas Parker's code working with stepper motors?

Thanks in advance

Matt