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. gazz

    gazz Member

    Joined:
    Feb 16, 2012
    Messages:
    35
    Location:
    Scarborough
    Balance:
    105Coins
    Ratings:
    +3 / 0 / -0
    My Motion Simulator:
    Arduino
    Please can someone help me,
    i just want to see a servo moving controlled by x-sim to keep my spirits up, as i'm having a hard time learning this programming stuff.

    i have an arduino mega, connected via usb on com4,
    i've tried the following sketch:

    Code:
    #include <Servo.h>
    
    Servo myservo;
    int pos=0;
    
    void setup()
    {
      Serial.begin(9600);
      myservo.attach(9);
    }
    
    void loop()
    {
      for(pos = 0; pos < 180; pos=Serial.read())
      {
        myservo.write(pos);
        delay(15);
      }
    }
    i then started Force profiler 2, as well as Force sender,

    Selected 'testplugin' on force sender, and hit 'try send data'

    in force profiler 2, input setup, i got a set of moving axis, first one is '21 effekt 21 : slider 1'
    test tablet i set slider 21 to auto move,
    Math setup i added axis 1, then add line for 'output 1:1' and selected sender input 21, and i have the line at the bottom drawing, and the numbers in 'result' going up and down.

    Output setup, USO, i selected USB serial com4, added it to the list, axis a1 is shown, 8 bit resolution, binary output,
    9600 baud, 8, no parity, 1 stopbit.
    and i put S~a01~E in the 'datapacket with axisinformations' box,

    Everything else is left alone,

    i click start, and the servo connected to pin 9 of my arduino moves from it's lower stop to around centre, but is jittering about like hell, i've got a constiant stream of data into the arduino according to it's RX led,
    no change if i stop the auto move slider 21 and move it manually,

    i'm so near and yet so far,

    can someone tell me what i have not changed/clicked?

    The servo works perfectly btw, i've had it running with firmata loaded to the arduino, and a sketch in processing to move the servo in response to the mouse cursor position, and that works,
  2. stowaway

    stowaway New Member

    Joined:
    Mar 16, 2009
    Messages:
    213
    Location:
    Gold Coast - Australia
    Balance:
    1Coins
    Ratings:
    +0 / 0 / -0
    Hi,

    Im writing a program with my Arduino UNO.. Except Im not using any of the Arduino Libraries, i ditched the arduino IDE as suggested by a few people here.

    However have a look at this post :
    post36645.html#p36645

    it may help you with some arduino code.
  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
    In ya top code ya not capturing the info xsim is sending you.
    If I can find some time Sunday I can write ya the simple code needed to make the servos drive.
    Plus what game do ya need to hook it too and i will setup a profile if i got the game.
    A model sim can be good fun and good for testing if you are going with the jrks as they react the same as as the serovs will
  4. bsft

    bsft

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    except when you blow jrks like I do :rofl:
  5. gazz

    gazz Member

    Joined:
    Feb 16, 2012
    Messages:
    35
    Location:
    Scarborough
    Balance:
    105Coins
    Ratings:
    +3 / 0 / -0
    My Motion Simulator:
    Arduino
    cheers for the replies,

    i'll look at those pages on not using the arduino libraries, i had already thought i need more than the standard arduino sketches to make it work as the interface between the sim and my real dashboard.

    The game is OMSI, i doubt many people would want it, as your not racing or owt, it's more driving smoothly and safely, negotiating other vehicles, obeying all traffic rules and so on, all in a 15 ton double decker bus with a top speed of 72KPH!!! :)

    but http://www.omnibussimulator.de/omsiwiki ... _Interface gives info on the plugin interface used in this game, not sure if it's any help.
  6. gazz

    gazz Member

    Joined:
    Feb 16, 2012
    Messages:
    35
    Location:
    Scarborough
    Balance:
    105Coins
    Ratings:
    +3 / 0 / -0
    My Motion Simulator:
    Arduino
    going to get a better servo when the shops open today, as the one i have is a bit jittery even when run from a RC system... i pulled it from the wings of a plane i crashed 4 years ago, so probably got damaged then.

    But i still cant figure out what i need to set in x-sim to get the servo to respond, but not sure if it's down to the x-sim settings of the arduino, as i believe the servo.h file may need tweaking for different servo's, due to the different pulse lengths they need or something,

    getting very confusing now,
    would wish for a plug and play solution, but wheres the fun in that.
  7. DanielDk

    DanielDk Member

    Joined:
    Feb 27, 2012
    Messages:
    38
    Balance:
    386Coins
    Ratings:
    +12 / 1 / -0
    Hi gazz

    Check out my new project!! and help me test it :) :

    dan-s-3dofduino-arduino-based-interface-for-x-sim2-t3741.html
    i think it allready does what you are looking for ( and very fast and smooth too)
  8. 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
    can be done alots simplier but like the use of higher bit rate
  9. gazz

    gazz Member

    Joined:
    Feb 16, 2012
    Messages:
    35
    Location:
    Scarborough
    Balance:
    105Coins
    Ratings:
    +3 / 0 / -0
    My Motion Simulator:
    Arduino
    Okay, i loaded the script onto my arduino, mega 1280,

    put led's via resistors to pins 32 and 33, only got one servo atm, connected to pin 7.

    I turn on the arduino, the servo moves to mid position.... i start x-sim force profiler and force injector,
    get the sliders auto moving, stock values (1000 top and bottom of slider range)

    but i'm stuck what to do next... i've set output, USO, 'comport speed and control' to : 115200, 8, no, 1.

    16 bit resolution and decimal output.

    and i entered '~36~X~a01~35~~a01~~42~' in the 'datapacketwith axisinfos' box,
    but clicking start gets me an error 'check axis numbers and count'

    I found out if i remove the 'X' it starts up without the error, but i get a red led,

    I imagine it's a stupid mistake on my part, as i dont quite understand what needs to go where in the force sender yet,

    Any chance of a walk through to what i need to put in the force senders boxes and tick boxes to get the servo i have connected to pin7 of the arduino to move with the force injectors movement??

    i'm wondering if it's to do with the math setup?? all i have is output 1:1, called the axis X, and left everything else stock.
  10. gazz

    gazz Member

    Joined:
    Feb 16, 2012
    Messages:
    35
    Location:
    Scarborough
    Balance:
    105Coins
    Ratings:
    +3 / 0 / -0
    My Motion Simulator:
    Arduino
    Holy crap batman, i'm getting somewhere!!!

    i removed the 'a01' from the string '~36~X~a01~35~~a01~~42~'
    clicked start and got a green light, with the force sender on auto, the gauge moved a bit every so often,

    i've since found out i basically have a zero/full deflection control,

    i have left the force sender on it's standard values, using the test plugin, so 1000 at the top of the slider, 1000 at the bottom,

    i've found that if i move the calibration slider in the math setup page right to the bottom, the servo will move when the slider passes a certian point, however moving the slider manually, it's a single point, going past it one way the servo goes to zero, moving past it the other way servo goes to full.

    So i guess now i have to figure out how to set things up for a servo for the output it wants.... and again i'm stuck, i'll keep playing with numbers, but i'm not sure what i need to be playing with to get a slider that moves the servo along the length of it, enabeling me to stop it at anypoint and have the servo be in that position.
  11. gazz

    gazz Member

    Joined:
    Feb 16, 2012
    Messages:
    35
    Location:
    Scarborough
    Balance:
    105Coins
    Ratings:
    +3 / 0 / -0
    My Motion Simulator:
    Arduino
    WooooWoooooWooooooot

    yay, that was it, thankyou very much for pointing it out.

    i now have me servo moving from min to max and back in response to the auto slider,

    i can now feel i'm getting somewhere at last, i may even be able to figure out how to work the rev counter i have... that needs to be fed a varying frequency between 0 and 433Hz at 50% duty cycle (i have driven it using the arduino's tone library, so hopefully i can modify the code to change one servo to a frequency output)
  12. DanielDk

    DanielDk Member

    Joined:
    Feb 27, 2012
    Messages:
    38
    Balance:
    386Coins
    Ratings:
    +12 / 1 / -0
    Good catch sirnoname!
    Thats my bad sorry bout that gazz! - i've fixed that and added some more comments in the code...

    thanks!
  13. gazz

    gazz Member

    Joined:
    Feb 16, 2012
    Messages:
    35
    Location:
    Scarborough
    Balance:
    105Coins
    Ratings:
    +3 / 0 / -0
    My Motion Simulator:
    Arduino
    okay, i'm really getting somewhere now,

    i've modified the script Dan very kindly pointed me to, and i've got all 3 of my air-core gauges working, one of them must be a bit dammaged as it's jerky and the coils are pretty noisey, the other is nice and smoooooth, but the coils sing a bit too, but i know that's due to the abrupt pwm signal they are being fed,
    these gauges have been sat in the bottom of my toolbox for about 5 years.

    The rpm gauge is moving beautifully, but then it does have it's own board for interpreting the signal and running the air-core.

    Now, i'm not being ungratefull here or owt, but it was mentioned this script can be done a lot simpler, any pointers to how to do that??

    i am not sure i need the high speed data transfer, but if it dosent use many resources then it's fine (i will eventually be driving 2 x frequency controlled gauges, 3 x pwm driven gauges and 4 x servo gauges, plus a fair few led's for idiot lights on the dash)

    and also the error checking, is that needed? for a motion platform it's a good idea, but for my use the worst that will happen with a bad packet is the needle points to the wrong value :)

    i tried to make it run 4 gauges, 1 servo and 3 air cores, but it wouldent have it, i imagine that's due to the error check feature?

    And the high bit rate, is that needed? as i believe the arduino is an 8 bit devise, so it cant give me any more resolution on the gauges, just thinking 0-255 numbers would be easier to work with... i think,

    i dont even know what the omsi simulator outputs yet, that's my nest step, but i've moved so far in the past few hours it's still catching me up.
  14. stowaway

    stowaway New Member

    Joined:
    Mar 16, 2009
    Messages:
    213
    Location:
    Gold Coast - Australia
    Balance:
    1Coins
    Ratings:
    +0 / 0 / -0
    Do you have an actaul rev counter? Or is it just a servo?

    if you have an actual rev counter can you upload a pic?
  15. gazz

    gazz Member

    Joined:
    Feb 16, 2012
    Messages:
    35
    Location:
    Scarborough
    Balance:
    105Coins
    Ratings:
    +3 / 0 / -0
    My Motion Simulator:
    Arduino
    gauges.jpg
    It's an actual rev counter, from an iveco turbo daily, originally fed from a hall effect sensor in the bellhousing to pick up the magnet in the flywheel as it whizzed past (diesel engined vehicle, so no ignition pulse to read from)

    the gauges by the side of it mounted on the same plastic holder are from the same vehicle,
    all 3 are air-core gauges,
    fuel and water gauges use 3 pins (so 2 coil ends are common to one of the pins), and there's a resistor between the + and signal pins, other pin is earth.

    The rev counter uses 4 pins (so separated + and - sine and co-sine coils) but it has a circuitboard that counts the pulses and takes care of feeding the relevant coils and polarity of them.. so no glitches as the needle passes between coils) PCB has 3 inputs, + 12v, earth and pulsed input.
    same way as an electronic speedometer works, and i hope a tachograph works, as that's what i want to work on next.

    The 4th gauge in the photo is the face from another spare gauge that had a bent shaft, so i just glued a servo on the back of the face (and got some super glue down the shaft... part of the reason for it's jerkyness i keep moaning about) then i made a needle with some scrap plastic shaved to a kind of needle shape, glues to the servo arm, this gauge pod is just a quick mockup for testing with,

    Once i get the code sorted, i will be getting proper complete gauges from a bus to go in my dash,

    My plan is to use as many air-core gauges as i can, as they are near silent, my rev counter is inaudiable when the needle is sweeping, but the fuel and water gauges produce an annoying high pitched hum (singing coils) due to the square wave signal it's getting, need to put an R/C filter in there and see if it helps, but i need to do some component harvesting to get some capacitors.
  16. stowaway

    stowaway New Member

    Joined:
    Mar 16, 2009
    Messages:
    213
    Location:
    Gold Coast - Australia
    Balance:
    1Coins
    Ratings:
    +0 / 0 / -0
    Excellent!

    Well thank you very much. You just gave me an idea of how to improve my simulator. I didnt read your thread properly to begin with, I didnt realise you were making a rev and speedo :)

    But now i will follow it very closely. Im lucky enough that my old man owns a trucking company, so I just went and pulled this out a truck wreck. Its out of a volvo prime mover, Ill open it tonight and see if I can make it into my own Servo Dash Board.

    photo.JPG
  17. stowaway

    stowaway New Member

    Joined:
    Mar 16, 2009
    Messages:
    213
    Location:
    Gold Coast - Australia
    Balance:
    1Coins
    Ratings:
    +0 / 0 / -0
    unforuntely my board has many many inputs, (it controls a LCD screen as well)

    It has some sort of servo or motor on it, I have pulled one off to try and see if i could get it run.. I tried using standard Servo signal, and PWM with varying signals, but I couldnt get it to move..
    it may aslo require 24volt which im only using 5 or 9volts. The truck runs off 24 volts.. :(
  18. gazz

    gazz Member

    Joined:
    Feb 16, 2012
    Messages:
    35
    Location:
    Scarborough
    Balance:
    105Coins
    Ratings:
    +3 / 0 / -0
    My Motion Simulator:
    Arduino
    Cool,

    That gauge pod could well be can bus controlled, apparantly that can be run off an arduino but needs lots of work and the knowlage of the can codes,

    But if it is definitely the type that has seperate sensors to feed the gauges, then great,
    If you can find the rev counter connections start with that,

    you will need 24 volts, so find a power brick from a force feedback steering wheel, as they are usually 24 volts, find where to feed the power into the gauge pod, when you apply power to the pod, you'll see the needles flick a little and probably raise ever so slightly off the stops,

    Then load the TonePitchFollower sketch on the arduino, http://arduino.cc/en/Tutorial/Tone2
    But dont bother with the photo resistor, instead put a potentiomiter in it's place... one side of the track to +5v from the arduino, other side of the track to - on the arduino, and the centre pin of the pot to A0 on the arduino,

    You will now have a variable frequency output at 50% duty cycle, which is what most rev counters want,

    Then inplace of the speaker and it's resistor on the breadboard, put a common emitter transitor setup:
    common_emitter.jpg
    Any NPN transistor will do, im using 2N551, and 2N3004 transistors as they are what i had lying around,

    Run a wire from the 'to gauge' point to the rev counters signal input, this will give it a 24 volt variable frequency signal, you must ensure all grounds are tied together... i.e arduino's ground, power bricks - wire, common emitters ground terminal and the gauge pod's - connection must be connected together, but keep the + 24 volts away from the arduino, i.e. dont try running it on external power of 24 volts as i believe it's too high for it,
  19. stowaway

    stowaway New Member

    Joined:
    Mar 16, 2009
    Messages:
    213
    Location:
    Gold Coast - Australia
    Balance:
    1Coins
    Ratings:
    +0 / 0 / -0
    It would just be easier to skip the circuits completely and drive the motors myself directly? But I cant evne do that, they are olny little motors, with 4 pins, one would think the voltage would be regulated down to move them.. but I coudlnt get any movement on them at all (i only tired 9volts and 5 volts)
  20. gazz

    gazz Member

    Joined:
    Feb 16, 2012
    Messages:
    35
    Location:
    Scarborough
    Balance:
    105Coins
    Ratings:
    +3 / 0 / -0
    My Motion Simulator:
    Arduino
    they are known as air-core gauges, 2 coils at right angles to each other, varying the polarity and power in the windings deflects the needles,
    if there are any markings it may be + sine, - sine, + co-sine and - co-sine.

    they apparently pull too much current for the arduino's outputs, so a small H bridge is needed,
    the L239D is ideal... i bought one recently, but decided against using it because people who drive air-core gauges directly with the arduino complain about hesitation at the location where the needle is moving from one coil to the other, as the coils polarity needs switching at that point as well as turning one coil off, the other on and getting the timing just right.

    Also you have to dedicate 4 pins on the arduino to drive a single air-core gauge (2 x digital outputs for the coils polarity, and 2 x pwm outputs to vary the coils....power.... (there is a proper word for that... inductance perhaps?)

    Anyway, i'm using a single output per gauge, pwm for the fuel and water and tone output (variable frequency) for the rev counter,

    my fuel and water gauges have 3 pins, the coils are connected at one end internally and come out on one pin, and there is a resistor is across the 2 pins for the other ends of the coils, this only works for gauges that move about 150 degrees.

    But it means you just need to feed it +12 volts, earth, and the varying pwm signal to make the needle move, i am figuring out how to get the mega to run one of it's timers at 31Khz, as that will stop the coils singing due to the harsh pwm i've been told, but messing with the timers can cause problems elsewhere.

    The rev counter is different, that is a 4 pin air-core, but i have the pulse counter pcb for it, this bolts onto the 4 pins, and have 3 pins for feeding it... +12v, earth and the variable frequency.