1. Do not share user accounts! Any account that is shared by another person will be blocked and closed. This means: we will close not only the account that is shared, but also the main account of the user who uses another person's account. We have the ability to detect account sharing, so please do not try to cheat the system. This action will take place on 04/18/2023. Read all forum rules.
    Dismiss Notice
  2. 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!
  3. 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
  4. 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

Arduino setup help

Discussion in 'SimTools compatible interfaces' started by gazz, Feb 25, 2012.

  1. stowaway

    stowaway New Member

    Joined:
    Mar 16, 2009
    Messages:
    213
    Location:
    Gold Coast - Australia
    Balance:
    1Coins
    Ratings:
    +0 / 0 / -0
    Thanks fo ryour help. I might just focos on the simualator part and use the dash with some LEDS and a shift register (gut it, and put a black plastic sheet over it, not using the gauges)

    I think my bus goes to a few microchips and its over my head to figure out which pin should be + - PWM etc, as there is like 36 choices
  2. gazz

    gazz Member

    Joined:
    Feb 16, 2012
    Messages:
    35
    Location:
    Scarborough
    Balance:
    105Coins
    Ratings:
    +3 / 0 / -0
    My Motion Simulator:
    Arduino
    Sorry for going over your head, i'm fine with basic electronics, hardware and making things, but programming is hard for me, not helped by me having problems typing (arthritic fingers) so lots of mistakes when writing code,
    i guess i've done what most good programmers do, assume everyone knows what i do,

    to me, when someone says 'write this, that and call xxx in the program' i cant understand it, i can barely understand a piece of code presented to me that i can copy and paste.

    Anyway:::
    if you can find any accessory gauges in the trucks.... i.e. aftermarket ones mounted on the dash for say oil pressure when the stock gauge pod dosent show that reading (or even buy some gauges, they are pretty cheap) they will have 3 terminals, power, earth and signal,
    feed the signal wire a pwm output from the arduino with the gauge powered up and the needle will move, i.e. the led fade sketch will make the needle swing back and forth,

    the gauge will be noisy due to the frequency of the pwm signal from the arduino, it needs to be a 31Khz pwm signal to make the gauge work quietly, i'm figuring out how to change timer 4 on my mega to 31Khz now, without affecting the other timers that run the millis and delay functions, and the servo lib. that i am using,
  3. eaorobbie

    eaorobbie Well-Known Member SimTools Developer Gold Contributor

    Joined:
    May 26, 2009
    Messages:
    2,574
    Occupation:
    CAD Detailer
    Location:
    Ellenbrook, Western Australia
    Balance:
    20,447Coins
    Ratings:
    +1,684 / 23 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    Have you thought of using two arduinos, one modded to 31 and the other left standard.
    X Sim can talk to multiply card without any issues.

    Been following this post cause i completed my dashboards with simplt leds and 7 seg guages but wish to the future to build a life like dash for my sim. Once I finish with my current docs and modding a Stepper motor into an Linear Actuator, mechanically works just awaiting electronics to test code that i have written, a live dashboard is high on the list.
    Thanks for ya info. :cheers:
  4. stowaway

    stowaway New Member

    Joined:
    Mar 16, 2009
    Messages:
    213
    Location:
    Gold Coast - Australia
    Balance:
    1Coins
    Ratings:
    +0 / 0 / -0
    Thanks Gazz, after your inspiration I deided to do a bit of research into Air Core (I always tend to reply before research :( )

    Anyway as you were saying, I can control the gauges with a h-bridge. (I already have a little audromoto I'm going to try and use it with). Although it takes 2 PWM lines for 1 gauge. So im going to gut mine and use only tachometer and speedo. Then I plan on taking some insperation from Earobbie, and hooking up a bunch of LED's to it also.
  5. gazz

    gazz Member

    Joined:
    Feb 16, 2012
    Messages:
    35
    Location:
    Scarborough
    Balance:
    105Coins
    Ratings:
    +3 / 0 / -0
    My Motion Simulator:
    Arduino
    Woohoo,
    made some real progress today,

    Found a post from 2010 on the arduino forum where someone had done something similar to what i want, a simple serial connection, 8 bit resolution, decimal inputs which are hopefully easy to work with,
    and very easy to add other axis's to the arduino code to read extra axis's from X-sim,

    The bloke who wrote the origional is 'herctrap' on the arduino forum, i have just modified the code a bit to work with my gauges and specific output needs (i.e. oil pressure, water temp etc)
    Code:
    int rpm; //rev counter
    int i;  //?
    int leds; //idiot lights
    int Speed; //speedo
    int fuel; //fuel gauge
    int oil; //oil pressure gauge
    int previous_potion = 0; //?
    int rotate; //?
    int water; //water temp gauge
    
    char kind_of_data; 
    
    
    void setup(){
    
      Serial.begin(115200);  //open serial connection at a decent speed
      TCCR4B = (TCCR4B & 0xF8) | 0x01 ; //sets timer 4 to 31Khz
      pinMode(22, OUTPUT);  //led for low fuel
      pinMode(23, OUTPUT); //led for overheat
    }
    
    
    
    void loop()
    {
      //****************************** READ DATA FROM SERIAL ******************************
      while(Serial.available() > 0)
      {
    
        kind_of_data = Serial.read();
        if (kind_of_data == 'R' ) Read_Rpm();
        if (kind_of_data == 'F' ) Read_Fuel();
        if (kind_of_data == 'W' ) Read_Water();
        if (kind_of_data == 'O' ) Read_Oil();
    
      }
    
    
      //****************************** READ DATA FROM SERIAL END ******************************
    }
    
    void  Read_Rpm(){
    
      delay(1);
      int Rpm100 = Serial.read()- '0';
      delay(1);
      int Rpm10 = Serial.read()- '0';
      delay(1);
      int Rpm1 = Serial.read()- '0';
    
      int rpm = 100*Rpm100 + 10*Rpm10 + Rpm1;
      tone(9, map(rpm,127,255,45,433)); //outputs frequency from 45 to 422Hz at 50% duty cycle
    
    
    }
    
    void Read_Fuel(){
      delay(1);
      int Fuel100 = Serial.read()- '0';
      delay(1);
      int Fuel10 = Serial.read()- '0';
      delay(1);
      int Fuel1 = Serial.read()- '0';
    
      fuel = 100*Fuel100 + 10*Fuel10 + Fuel1;
    
      analogWrite(6,map(fuel,127,255,0,255));  //outputs PWM signal to simulate resistance to earth
      if (fuel<155) digitalWrite(22,HIGH); //low fuel led on when needle just above empty line
      if (fuel>155) digitalWrite(22,LOW);  
    
    } 
    
    
    void Read_Water(){
      delay(1);
      int Water100 = Serial.read()- '0';
      delay(1);
      int Water10 = Serial.read()- '0';
      delay(1);
      int Water1 = Serial.read()- '0';
    
      water = 100*Water100 + 10*Water10 + Water1;
    
      analogWrite(7,map(water,127,255,0,255));
       if (water>200) digitalWrite(23,HIGH); //overheat led on when over 110 degrees C on gauge
      if (water<200) digitalWrite(23,LOW); 
    
    } 
    
    
    void Read_Oil(){
      delay(1);
      int Oil100 = Serial.read()- '0';
      delay(1);
      int Oil10 = Serial.read()- '0';
      delay(1);
      int Oil1 = Serial.read()- '0';
    
      oil = 100*Oil100 + 10*Oil10 + Oil1;
    
      analogWrite(8,map(oil,127,255,0,255));
    }
    
    i like the way he's used the simple 'if' commands to activate the low fuel warning light, so i did the same to activate the overheat light in my water gauge too,

    i've added the // comments, feel free to correct me if i got them wrong,

    And i've got the oil, water and fuel gauges running silently, the TCCR4B = (TCCR4B & 0xF8) | 0x01 ; bit in the setup part of the sketch sets timer 4 to run a 31Khz, the gauges coils still vibrate, but the sound they make is out of our hearing range, maybe the local bats wont like it, but i sure do :D