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 uno stepper gauge rev meter help.

Discussion in 'SimTools compatible interfaces' started by antenna, Jun 24, 2012.

  1. antenna

    antenna New Member

    Joined:
    Jun 3, 2012
    Messages:
    1
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    Hi to all.
    I'm a new italian user, so sorry for my english. I've found this great forum searching for build a simple rpm meter for my sim, and after viewing other user post i realize my first project. The platform is an arduino uno connected to an h bridge to drive a small stepper motor from real car cluster( a clone of switec x25). I,'m using x-sim 3. The bound rate is setting to 115200 , x-sim sending data at 8 bit, decimal output. If i start the simulator the meter moves accordly but with some issue, is slow to reach the high point of the scale and sometimes instead of return to min, hold a casual position. I try to change the pause in converter from 33ms to 40ms and slower but seems only affected the accuracy of the movement, if set to lower value instead the motor jitter or not moving at all.
    I've tried the example sketch motor knob and other and the stepper works properly.
    I think the problem is that arduino analog.read function is too slow to reading the data coming from x-sim as decimal output. Maybe if i send it in binary form the aquisition could be faster but i need a help for the code. I post the currently used.
    Thanks in advance.

    Code:
    #include <Stepper.h>
    
    
    Stepper stepper(720, 2, 3, 4, 5);
    
    
    int rpm;
    int nextStep;
    int pos = 0;
    
    
    char kind_of_data;
    
    
    void setup(){
      
    Serial.begin(115200);
      
    stepper.setSpeed(30);
    
    
    }
    
    
    void loop()
    {
      
    while(Serial.available() > 0)
    {
    
        kind_of_data = Serial.read();
        if (kind_of_data == 'R' ) Read_rpm();
        
        
    }
    
    }
    void Read_rpm(){
      delay(1);
      int rpm100 = Serial.read()- '0';
      delay(1);
      int rpm10 = Serial.read()- '0';
      delay(1);
      int rpm1 = Serial.read()- '0';
    
      rpm = 100*rpm100 + 10*rpm10 + rpm1;
      rpm = map(rpm,127,255,0,600);
     
      nextStep = rpm - pos;
      stepper.step(nextStep);
      pos = rpm; 
    } 

  2. nicko_esx

    nicko_esx Member

    Joined:
    May 28, 2012
    Messages:
    37
    Location:
    argentina
    Balance:
    696Coins
    Ratings:
    +16 / 0 / -0
    My Motion Simulator:
    Arduino