Close

Retarder Handle Part 5 (Final)

A project log for Real Scania Truck Home Simulator

The Scrapyard and Arduino make a great combination!

jeroen-van-der-veldenJeroen van der Velden 12/16/2015 at 11:491 Comment

I found it!! The final piece of this mind breaking code to connect a Scania 4-Series Retarder to your PC Home Truck Simulator.


How to Guide:

1# Buy a Scania Retarder Part No.1349967 Here or Here

2# Buy a cheap Arduino Leonardo

3# Upload my Code below with Arduino IDE to your Leonardo

4# Connect Retarder PIN 2 to Leonardo 5V, Connect Retarder PIN 6 to Leonardo PIN GND and Finally Connect Retarder PIN 7 to Leonardo PIN A0

5# Assign a key for your in-game Retarder (0 Decrease and 9 Increase) in the ETS2 Setting menu ***

6# Disable "Automatic Retarder" in the game settings in ETS2

7# Have fun!

***Instead of 0 and 9 you can also assign different keys in ETS2, but then you have to modify the code below a little bit. Just find Keyboard.print 0 and Keyboard.print 9 below.

unsigned long startTime, endTime = 1000;
byte handlePos, oldHandlePos, currentPos;
int8_t diff;
int val;
bool posSent = true;

void setup()
{
  Serial.begin(9600);
  val = getAnalog();
  Serial.print("\nCurrent handle position = ");
  Serial.print(handlePos);
  Serial.println("\n\n");
  currentPos = oldHandlePos = handlePos;
}

void loop()
{
  val = getAnalog();
  if(handlePos != currentPos)
  {
    startTime = millis();
    currentPos = handlePos;
    posSent = false;
    diff = 0;
  }  
    if(!posSent && millis() - startTime > endTime)
    {
      Serial.print("Handle Position =  ");
      Serial.print(handlePos);
      Serial.print("\t");
      diff = handlePos - oldHandlePos;
      Serial.print("Difference =  ");
      Serial.println(diff);
    
    // if diff is negative number to positive number
    if(diff < 0)
    {
    for (int i = 0; i < (diff * -1); i++)
    {
      Keyboard.print("9");
      delay(500);
    }
    }
    
    // if diff is positive number to positive number
    if(diff > 0)
    {
    for (int i = 0; i < diff; i++)
    {
      Keyboard.print("0");
      delay(500);
    }
    }
    
      oldHandlePos = handlePos;
      posSent = true;
    }
}

int getAnalog()
{
  val = analogRead(0);
  if(val < 187) handlePos = 0;
  else if(val < 350) handlePos = 1;
  else if(val < 518) handlePos = 2;
  else if(val < 679) handlePos = 3;
  else if(val < 861) handlePos = 4;
  else handlePos = 5;
// Code by "Jeroen van der Velden"
// Hackaday Project 8448
// https://hackaday.io/project/8448
}


Next piece of Truck Hardware will be the Cruise Control. With this code and some modifications to the code we will be able to use the original Scania 4-series Cruisecontrol (ACC).

Thanks for following!

Discussions

Eddy von Ballmoos wrote 07/17/2022 at 15:09 point

Hello Jeoren
I am looking at your project for a long time. Was amazed how you managed to connect a 4-Series Scania dash to ETS2
I got a dash out of a wrecked 2016 R-Model Scania.
Big thanks to your precious work. Was able, out of your work,  to get some of my gear to work with ETS2 and ATS.

Greetings from Switzerland

Eddy von Ballmoos

  Are you sure? yes | no