1. For downloading SimTools plugins you need a Download Package. Get it with virtual coins that you receive for forum activity or Buy Download Package - We have a zero Spam tolerance so read our forum rules first.

    Buy Now a Download Plan!
  2. Do not try to cheat our system and do not post an unnecessary amount of useless posts only to earn credits here. We have a zero spam tolerance policy and this will cause a ban of your user account. Otherwise we wish you a pleasant stay here! Read the forum rules
  3. We have a few rules which you need to read and accept before posting anything here! Following these rules will keep the forum clean and your stay pleasant. Do not follow these rules can lead to permanent exclusion from this website: Read the forum rules.
    Are you a company? Read our company rules

driving a tachometer R-type

Discussion in 'DIY peripherals' started by RodrigoOp, Jun 14, 2016.

  1. RodrigoOp

    RodrigoOp New Member

    Joined:
    Jun 7, 2016
    Messages:
    26
    Occupation:
    Teacher
    Location:
    Chle
    Balance:
    267Coins
    Ratings:
    +23 / 0 / -0
    My Motion Simulator:
    2DOF, Arduino
    Este es mi tutorial para agregar un Tacometro R-type
    This is my tutorial to add a tachometer R-type

    El tacómetro maneja de 800 a 9500 rpm
    The tachometer handles 800 to 9500 rpm



    El código con un arduino uno:
    The code with a arduino One:

    int i;
    double cylinder = 4; // cyliner count for Tachometer.
    double divideUnit = 120; // 1/120 hz/(rpm * cylinder)
    double hzPerRpm = cylinder / divideUnit;
    int rpmtone;
    int pinTacho = 10;
    unsigned int rpm; // holds the rpm data (0-65535 size)
    unsigned int rpmmax = 10000; // retrieves from rpm live with minimum setting on initialization and Shutdown - Output
    byte rpmdata = 0; // marker that new data are available

    ////////////////////////////////////////////////////////////////////////////////
    // INITIALIZATION
    ////////////////////////////////////////////////////////////////////////////////
    void setup()
    {
    // serial initialization
    Serial.begin(19200);
    pinMode(7, OUTPUT); //para el led que indica cuándo pasar el cambio
    //LED for indicating when the change happen
    }

    ////////////////////////////////////////////////////////////////////////////////
    ///////////////////////////////// Main Loop ////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////
    void loop()
    {

    // read input data
    readSerialData();

    // generate signal and send to tacho
    tacho();

    }

    ////////////////////////////////////////////////////////////////////////////////
    // Procedure: wait for complete trame
    ////////////////////////////////////////////////////////////////////////////////
    void readSerialData()
    {
    byte Data[5]={
    '0','0','0','0','0' };

    // parse the buffer
    if (Serial.available()>4){
    Data[0]=Serial.read(); // read command
    if (Data[0]=='M'){ // if rpm data
    Data[1]=Serial.read(); // store high byte
    Data[2]=Serial.read(); //
    Data[3]=Serial.read(); //
    Data[4]=Serial.read(); // store low byte
    rpm = NormalizeData(Data);
    rpmdata=1; // we got new data!
    if (Serial.available()>4){
    Data[0]=Serial.read(); // re-read command
    }
    }
    if (Data[0] == 'Z' ){ // if Shutdown - Output
    Serial.flush();
    rpmmax=10000; // reset rpmmax
    }
    }
    if (Serial.available()>40) Serial.flush();
    }

    ////////////////////////////////////////////////////////
    void tacho()
    ////////////////////////////////////////////////////////
    {
    if (rpmdata == 1) {
    if (rpm>rpmmax && rpm<50000) {
    rpmmax=rpm;
    }
    if(rpm>50000){
    rpm = 0;
    }
    rpmtone = (int)(rpm * hzPerRpm);
    if(rpmtone > 320) {
    rpmtone = 333;
    }
    // 697 max para mi tacometro a 9500 rpm
    //697 max for my tach at 9500 rpm

    rpmtone = map(rpmtone,0,333,0,675);
    if (rpmtone>495) // ENCIENDE EL LED CUANDO PASAN LAS 8000 RPM
    //LED LIGHTS WHEN PASSING THE 8000 RPM
    { digitalWrite(7, HIGH);
    }else {
    digitalWrite(7, LOW);
    }

    if(rpmtone < 31) {
    rpmtone = 30;
    }

    if(rpm>500){
    tone(pinTacho, rpmtone);
    }
    else{
    noTone(pinTacho);
    }
    ;
    rpmdata=0;
    }
    }

    ////////////////////////////////////////////////////////////////////////////////
    // Function: convert Hex to Dec
    ////////////////////////////////////////////////////////////////////////////////
    unsigned int NormalizeData(byte x[5])
    ////////////////////////////////////////////////////////////////////////////////
    {
    unsigned int result;

    for (int i=1; i<5; i++)
    {
    if (x>47 && x<58 ){ //for xA to xF
    x=x-48;
    }
    if ( x>64 && x<71 ){ //for x0 to x9
    x=x-55;
    }
    }
    result = (x[1]*16*16*16+x[2]*16*16+x[3]*16+x[4]);
    return result;
    }

    la configuración:
    Screenshot_4.jpg

    eso es todo.
    saludos
    Rod
    • Like Like x 5
    Last edited: Jun 20, 2016
  2. Ads Master

    Ads Master

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
  3. mrbeginner

    mrbeginner Active Member Gold Contributor

    Joined:
    Apr 8, 2012
    Messages:
    151
    Occupation:
    What ever come in my way
    Location:
    Finland Niinisalo
    Balance:
    20Coins
    Ratings:
    +53 / 1 / -0
    Simple and clever! Do you use 12v transformer? How much transformer gives current?
  4. RodrigoOp

    RodrigoOp New Member

    Joined:
    Jun 7, 2016
    Messages:
    26
    Occupation:
    Teacher
    Location:
    Chle
    Balance:
    267Coins
    Ratings:
    +23 / 0 / -0
    My Motion Simulator:
    2DOF, Arduino
    no, i use for this test a 3s lipo battery (12.4v full charge), but it's like 12v source
    i'm not sure how much Amps can handle. I not tested yet, when i have more time i can answer your question

    thanks
  5. mrbeginner

    mrbeginner Active Member Gold Contributor

    Joined:
    Apr 8, 2012
    Messages:
    151
    Occupation:
    What ever come in my way
    Location:
    Finland Niinisalo
    Balance:
    20Coins
    Ratings:
    +53 / 1 / -0
    I try to install this in uno but it give me error. Can you tell me what i don't see.. problem.jpg
  6. Kirk

    Kirk Member

    Joined:
    May 19, 2014
    Messages:
    92
    Occupation:
    Sr Software Engineer
    Location:
    Texas
    Balance:
    15,033Coins
    Ratings:
    +113 / 2 / -0
    My Motion Simulator:
    2DOF, DC motor
    In the places you have just 'x', try 'x [ i ]' instead.
  7. PiaMan

    PiaMan Active Member

    Joined:
    Aug 2, 2015
    Messages:
    194
    Location:
    Saskatchewan, CANADA
    Balance:
    561Coins
    Ratings:
    +130 / 2 / -0
    My Motion Simulator:
    3DOF, DC motor, SCN5, Arduino
    I would love a specific pin out diagram. Its hard to see from the video.

    I see the pin 7 and 10 and ground. Im not sure what is going to the tach from the other side. Power? Analog output? Thanks for the idea. Next on my build list!
  8. RodrigoOp

    RodrigoOp New Member

    Joined:
    Jun 7, 2016
    Messages:
    26
    Occupation:
    Teacher
    Location:
    Chle
    Balance:
    267Coins
    Ratings:
    +23 / 0 / -0
    My Motion Simulator:
    2DOF, Arduino
    Screenshot_5.jpg

    @mrbeginner : Replace with this, copy paste have troubles in the forum.

    sorry.
    • Like Like x 1
    • Agree Agree x 1
    Last edited: Jun 20, 2016
  9. RodrigoOp

    RodrigoOp New Member

    Joined:
    Jun 7, 2016
    Messages:
    26
    Occupation:
    Teacher
    Location:
    Chle
    Balance:
    267Coins
    Ratings:
    +23 / 0 / -0
    My Motion Simulator:
    2DOF, Arduino
    pinout tacho.jpg
    @PiaMan a schematic for you.
    bye.
    • Like Like x 2
  10. RodrigoOp

    RodrigoOp New Member

    Joined:
    Jun 7, 2016
    Messages:
    26
    Occupation:
    Teacher
    Location:
    Chle
    Balance:
    267Coins
    Ratings:
    +23 / 0 / -0
    My Motion Simulator:
    2DOF, Arduino
    @Kirk i paste a image, forum have some troubles uploading [ ].
    • Agree Agree x 1
  11. mrbeginner

    mrbeginner Active Member Gold Contributor

    Joined:
    Apr 8, 2012
    Messages:
    151
    Occupation:
    What ever come in my way
    Location:
    Finland Niinisalo
    Balance:
    20Coins
    Ratings:
    +53 / 1 / -0
    thank you. I get it work. But first it take double rpm than the game show. I change double cylinder = 4 to 2 and then my meter work ok.
  12. PiaMan

    PiaMan Active Member

    Joined:
    Aug 2, 2015
    Messages:
    194
    Location:
    Saskatchewan, CANADA
    Balance:
    561Coins
    Ratings:
    +130 / 2 / -0
    My Motion Simulator:
    3DOF, DC motor, SCN5, Arduino
    Thank you
  13. RodrigoOp

    RodrigoOp New Member

    Joined:
    Jun 7, 2016
    Messages:
    26
    Occupation:
    Teacher
    Location:
    Chle
    Balance:
    267Coins
    Ratings:
    +23 / 0 / -0
    My Motion Simulator:
    2DOF, Arduino
    in my case 6 cylinder to get correct set up
  14. RodrigoOp

    RodrigoOp New Member

    Joined:
    Jun 7, 2016
    Messages:
    26
    Occupation:
    Teacher
    Location:
    Chle
    Balance:
    267Coins
    Ratings:
    +23 / 0 / -0
    My Motion Simulator:
    2DOF, Arduino
    This code let you know rpm in your fisical tacho
    /* */ are coments
    //



    int pin=10;

    void setup() {
    // put your setup code here, to run once:

    }


    void loop() {
    /*delay(500);
    tone(pin, 50);// 1000 rpm
    delay(500);
    tone(pin, 110);// 2000 rpm
    delay(500);
    tone(pin, 160);// 3000 rpm
    delay(500);
    tone(pin, 210);// 4000 rpm
    delay(500);
    tone(pin, 265);// 5000 rpm
    delay(500);
    tone(pin, 330);// 6000 rpm
    delay(500);
    tone(pin, 410);// 7000 rpm
    delay(500);
    tone(pin, 495);// 8000 rpm
    delay(500);
    tone(pin, 600);// 9000 rpm*/
    delay(500);
    tone(pin, 747);// 9000 rpm
    }

    bye
  15. mrbeginner

    mrbeginner Active Member Gold Contributor

    Joined:
    Apr 8, 2012
    Messages:
    151
    Occupation:
    What ever come in my way
    Location:
    Finland Niinisalo
    Balance:
    20Coins
    Ratings:
    +53 / 1 / -0
  16. mrbeginner

    mrbeginner Active Member Gold Contributor

    Joined:
    Apr 8, 2012
    Messages:
    151
    Occupation:
    What ever come in my way
    Location:
    Finland Niinisalo
    Balance:
    20Coins
    Ratings:
    +53 / 1 / -0
    I try it again and the problem is when your rpm goes under 1000 then the needle go crazy. it goes straight to max and if i press gas pedal it goes back to normal. Same thing both games Assetto and pcars
  17. RodrigoOp

    RodrigoOp New Member

    Joined:
    Jun 7, 2016
    Messages:
    26
    Occupation:
    Teacher
    Location:
    Chle
    Balance:
    267Coins
    Ratings:
    +23 / 0 / -0
    My Motion Simulator:
    2DOF, Arduino
    i use this sketch to know the limits of your tacho

    int pin=10;

    void setup() {
    }


    void loop() {
    delay(500);
    tone(pin, 50);// 1000 rpm
    delay(500);
    tone(pin, 110);// 2000 rpm
    }



    under tone (pin, 34) my tacho have inconsistences

    search in upper sketch this line

    if(rpmtone < 31) {
    rpmtone = 30;
    }

    change rpmtone with upper value like
    if(rpmtone < 31) {
    rpmtone = 34;
    }


    then replayme
  18. mrbeginner

    mrbeginner Active Member Gold Contributor

    Joined:
    Apr 8, 2012
    Messages:
    151
    Occupation:
    What ever come in my way
    Location:
    Finland Niinisalo
    Balance:
    20Coins
    Ratings:
    +53 / 1 / -0
    Thats the spot!
    Now it works like it should!:D
  19. RodrigoOp

    RodrigoOp New Member

    Joined:
    Jun 7, 2016
    Messages:
    26
    Occupation:
    Teacher
    Location:
    Chle
    Balance:
    267Coins
    Ratings:
    +23 / 0 / -0
    My Motion Simulator:
    2DOF, Arduino
    good news