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 Code for Fan Speed from Dashboard

Discussion in 'SimTools compatible interfaces' started by CoachKalk, Sep 30, 2014.

  1. CoachKalk

    CoachKalk Member

    Joined:
    Jul 29, 2014
    Messages:
    92
    Balance:
    970Coins
    Ratings:
    +16 / 0 / -0
    My Motion Simulator:
    3DOF, DC motor, JRK
    I am working on adding a fan that will be controlled by the roller coaster speed from the Dashboard. I have a basic circuit tested out - not using the arduino at all, but just using a 2N222 transistor as a switch. I am just manually switching the transistor at the base turn a fan on/off to make sure I have it correct.

    I am now ready to control the base pin via an arduino PWM pin. I have copied a code that @eaorobbie included in a previous thread below. I copied the code into the Arduino software and tried to compile/verify it to check for errors.

    I am getting the following error message:
    FanSpeed.ino: In function 'void loop()':
    FanSpeed:18: error: incompatible types in assignment of 'int' to 'int [6]'

    I know very little about Arduino code so I am hoping someone can guide me in a fix.

    CODE from eaorobbie below ......................................................................

    int Speed;
    int MaxSpeed = 350;
    int MinPWM = 20;
    int FanSpeed = 0;
    int bufferArray[6];
    void setup(){

    pinMode(3,OUTPUT);
    Serial.begin(9600);
    }
    void loop(){
    //****************************** READ DATA FROM SERIAL ******************************
    DriveFan();
    if (Serial.available() >= 4) { //if 4 bits available in the Serial buffer...

    int i;
    for (i=0; i<4; i=i+1) { // read and label each byte.
    bufferArray = Serial.read();
    Serial.flush();
    }

    if (bufferArray[0] == 'S'){
    unsigned int SpeedSmTools = ((bufferArray[1]-48)*100) + ((bufferArray[2]-48)*10) + bufferArray[3]-48;
    Serial.print("You have recieved the Speed of: ");
    Serial.println(SpeedSmTools);
    FanSpeed = map(SpeedSmTools, 0, MaxSpeed, MinPWM, 255);
    Serial.print("You have set the Fan Speed to: ");
    Serial.println(FanSpeed);
    }
    }
    }
    void DriveFan() {
    analogWrite(3,FanSpeed);
    }
  2. 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,391Coins
    Ratings:
    +1,683 / 23 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    Ok should be able to find a suitable one amongst those I wrote a while back.

    Attached Files:

    • Useful Useful x 1
  3. CoachKalk

    CoachKalk Member

    Joined:
    Jul 29, 2014
    Messages:
    92
    Balance:
    970Coins
    Ratings:
    +16 / 0 / -0
    My Motion Simulator:
    3DOF, DC motor, JRK
    @eaorobbie - Wow! That is a lot of code! :) To be honest, I have no idea which one to use. Will it depend on my dashboard setup? I have tried to go through the tutorials but I cannot seem to get numbers to show up in the dashboard with No Limits. I just now patched in the newest No Limits patch to make sure speed is included. The other pain is that No Limits will not let me minimize the screen so I am not sure if numbers are there during play, but go back to 0's when game ends. I was hoping the last numbers would be saved.

    I have enabled Dashboard in the Game Manage. Any help with Dashboard would be very much appreciated as well.

    Thanks,
    Steve
  4. Mazhar Salam

    Mazhar Salam Member

    Joined:
    Mar 27, 2014
    Messages:
    43
    Location:
    Melbourne
    Balance:
    907Coins
    Ratings:
    +24 / 1 / -0
    My Motion Simulator:
    2DOF, Arduino
    hi thanks for the codes, I have saved a copy to be used in the future when implementing air speed
  5. 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,391Coins
    Ratings:
    +1,683 / 23 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    Your welcome sorry I don't posses the time to sit down and sort through it all, the end product did work with the games that have dashout support.
    If you are familiar with the Ard IDE it wont be a issue, but please any problem ask away I will try and jog the grey matter back into life.
    Please feel free to post a finished product , code and information so others may add it too.
    • Friendly Friendly x 1
  6. CoachKalk

    CoachKalk Member

    Joined:
    Jul 29, 2014
    Messages:
    92
    Balance:
    970Coins
    Ratings:
    +16 / 0 / -0
    My Motion Simulator:
    3DOF, DC motor, JRK
    @eaorobbie - I looked through the codes and think I found several that should work. I am just struggling on the dashboard settings and trying to figure out what No Limits is sending to the dashboard then what needs to be done so the Arduino can read it.

    I will post some screen shots of what I have done in awhile. Hopefully you or someone can point me in the right direction.
    • Like Like x 1
  7. CoachKalk

    CoachKalk Member

    Joined:
    Jul 29, 2014
    Messages:
    92
    Balance:
    970Coins
    Ratings:
    +16 / 0 / -0
    My Motion Simulator:
    3DOF, DC motor, JRK
    Ok, this is where I am at.

    First, I will show the code I think should work. Then, the screen shots that I have attempted to work through. Obviously, I need some help.

    // This just works with one variable from the Game Dash.
    int Speed ;
    int SpeedGameDash = 0;
    int bufferArray[4];
    void setup(){
    pinMode(11,OUTPUT);
    Serial.begin(9600);
    }
    void loop(){
    //****************************** READ DATA FROM SERIAL ******************************
    ReadData();
    CalcPWM();
    }
    void ReadData(){
    if (Serial.available() == 4) { //if 4 bits available in the Serial buffer...
    int i;
    for (i=0; i<4; i=i+1) { // read and label each byte.
    bufferArray = Serial.read();
    }
    if (bufferArray[0] == 'S'){
    SpeedGameDash = ((bufferArray[1]-48)*100) + ((bufferArray[2]-48)*10) + // Take values 1-3.
    ((bufferArray[3]-48)*1);
    //Serial.print("You have set the Speed to a Value of:");
    //Serial.println(SpeedGameDash);
    }
    }
    }
    void CalcPWM() {
    if (SpeedGameDash > 0){
    int oldSpeed = Speed;
    Speed = map(SpeedGameDash, 0 ,400, 0 , 255);
    if (oldSpeed != Speed){
    //Serial.print("Fan Speed set to :");
    //Serial.println(Speed);
    analogWrite(11,Speed);
    }
    }
    }

    [​IMG]

    [​IMG]

    [​IMG]
  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,391Coins
    Ratings:
    +1,683 / 23 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    Ok first remove the Interface 4, only the GameDash needs to talk to the Ard on Com12 (for your setup).

    Ok now I don't have NoLimits installed,
    So I will bump @value1 does the No Limits Plugin contain a speed value that we can use in the GameDash. If not could we trouble you to add this please. Cheers.

    Now if Speed exists , its in most cases set to Dash 1 and we need to create a little script there to change the value to what we need to send to the Ard.

    For example:
    Assetto Corsa supplies a number with decimal places and can be several digits long so I insert this script:

    Round 0
    Pad 3 0

    Ok the first line ROUNDS the number to the nearest whole number , no decimal places (0)
    The second line Pad the number to make it easy for the Ard to read the value as fast as we can, ie keeps the speed to a 3 digit number , ie: 0 = 000 , 10 = 010 and so on.

    Once enter Press save.

    What can be handy is to use a 2nd monitor to see whats going on with the GameDash and you can change the scripts while it runs to find the right values, again sorry I don't have the game presently installed or I would test it for you.
    • Informative Informative x 1
  9. CoachKalk

    CoachKalk Member

    Joined:
    Jul 29, 2014
    Messages:
    92
    Balance:
    970Coins
    Ratings:
    +16 / 0 / -0
    My Motion Simulator:
    3DOF, DC motor, JRK
    @eaorobbie - I will make the changes you mentioned. I have been talking with @value1 about No Limits and speed and it should be good to go. I am not sure what form it send the data though.

    Can I mess with the setup and try it with just the arduino plugged in? Leaving all motors out of it?

    Thanks,
  10. CoachKalk

    CoachKalk Member

    Joined:
    Jul 29, 2014
    Messages:
    92
    Balance:
    970Coins
    Ratings:
    +16 / 0 / -0
    My Motion Simulator:
    3DOF, DC motor, JRK
    @eaorobbie - can you take a look at the Output Settings in the Game Dash? Does that look ok? Does that depend on what the Arduino code is looking for?

    Also, on screenshots of other poster, I see actual descriptions instead of Dash 1, etc .... How is that done? Every time a try a run and then go back into Game Dash, the Game Name is back to no selection even though I had selected No Limits before starting the game. Is that typical of the Game Dash or do I have something not saved correctly?
  11. eXntrc

    eXntrc Member

    Joined:
    Dec 3, 2014
    Messages:
    35
    Balance:
    636Coins
    Ratings:
    +44 / 0 / -0
    My Motion Simulator:
    Arduino
    @eaorobbie can you share what code and setup you have so far? I'm attempting to do the same thing.
  12. SilentChill

    SilentChill Problem Maker

    Joined:
    Jul 19, 2014
    Messages:
    2,619
    Occupation:
    Railway Maintenance
    Location:
    Morecambe, Lancashire, England
    Balance:
    20,396Coins
    Ratings:
    +3,480 / 34 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 6DOF
    Hi @CoachKalk have you had any success in getting the fans working with no limits ?

    I am going to use the fans out of my PSU's and get them hooked up onto the rig. I really dont have a clue where to start. I have a spare Arduino and motomonster but no idea how to wire it up or even if I need to use the motomonster ??

    I think @eaorobbie has been offline for a couple of months.
  13. SilentChill

    SilentChill Problem Maker

    Joined:
    Jul 19, 2014
    Messages:
    2,619
    Occupation:
    Railway Maintenance
    Location:
    Morecambe, Lancashire, England
    Balance:
    20,396Coins
    Ratings:
    +3,480 / 34 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 6DOF
    Ok this is what I have done so far I can control the fans manually by putting values in the "motorgo" but I cant seem to get the dash data to tell the monstermoto to power the fans please help someone @RufusDufus @RacingMat @value1 @eaorobbie @yobuddy @ anyone else :)

    Must be something simple i'm missing, My knowledge is very very weak so the whole code I have added to @eaorobbie original code may be wrong

    #define BRAKEVCC 0
    #define CW 1
    #define CCW 2
    #define BRAKEGND 3
    #define CS_THRESHOLD 100

    int inApin[2] = {7, 4}; // INA: Clockwise input
    int inBpin[2] = {8, 9}; // INB: Counter-clockwise input
    int pwmpin[2] = {5, 6}; // PWM input
    int cspin[2] = {2, 3}; // CS: Current sense ANALOG input
    int enpin[2] = {0, 1}; // EN: Status of switches output (Analog pin)
    int statpin = 13;


    // This just works with one variable from the Game Dash.
    int Speed ;
    int SpeedGameDash = 0;

    int bufferArray[4];

    void setup()

    {
    pinMode(11,OUTPUT);

    Serial.begin(9600);
    pinMode(statpin, OUTPUT);

    // Initialize digital pins as outputs
    for (int i=0; i<2; i++)
    {
    pinMode(inApin, OUTPUT);
    pinMode(inBpin, OUTPUT);
    pinMode(pwmpin, OUTPUT);
    }

    // Initialize braked
    for (int i=0; i<2; i++)
    {
    digitalWrite(inApin, LOW);
    digitalWrite(inBpin, LOW);
    }
    }


    void loop(){
    //****************************** READ DATA FROM SERIAL ******************************

    ReadData();
    CalcPWM();


    motorGo(0, CW, Speed); //Motor1 IS THIS WHERE I AM GOING WRONG ?????
    motorGo(1, CW, Speed); //Motor2 IS THIS WHERE I AM GOING WRONG ?????



    if ((analogRead(cspin[0]) < CS_THRESHOLD) && (analogRead(cspin[1]) < CS_THRESHOLD))
    digitalWrite(statpin, HIGH);
    }

    void motorOff(int motor)
    {
    // Initialize braked
    for (int i=0; i<2; i++)
    {
    digitalWrite(inApin, LOW);
    digitalWrite(inBpin, LOW);
    }
    analogWrite(pwmpin[motor], 0);
    }

    void motorGo(uint8_t motor, uint8_t direct, uint8_t pwm)
    {
    if (motor <= 1)
    {
    if (direct <=4)
    {
    // Set inA[motor]
    if (direct <=1)
    digitalWrite(inApin[motor], HIGH);
    else
    digitalWrite(inApin[motor], LOW);

    // Set inB[motor]
    if ((direct==0)||(direct==2))
    digitalWrite(inBpin[motor], HIGH);
    else
    digitalWrite(inBpin[motor], LOW);
    analogWrite(pwmpin[motor], pwm);
    }
    }
    }

    void ReadData(){

    if (Serial.available() == 4) { //if 4 bits available in the Serial buffer...

    int i;
    for (i=0; i<4; i=i+1) { // read and label each byte.
    bufferArray = Serial.read();
    }

    if (bufferArray[0] == 'S'){
    SpeedGameDash = ((bufferArray[1]-48)*100) + ((bufferArray[2]-48)*10) + // Take values 1-3.
    ((bufferArray[3]-48)*1);
    //Serial.print("You have set the Speed to a Value of:");
    //Serial.println(SpeedGameDash);
    }
    }
    }
    void CalcPWM() {

    if (SpeedGameDash > 0){
    int oldSpeed = Speed;
    Speed = map(SpeedGameDash, 0 ,400, 0 , 255);
    if (oldSpeed != Speed){
    //Serial.print("Fan Speed set to :");
    //Serial.println(Speed);
    analogWrite(11,Speed);
    }
    }
    }



    Thanks for looking hope someone can help :)
  14. SilentChill

    SilentChill Problem Maker

    Joined:
    Jul 19, 2014
    Messages:
    2,619
    Occupation:
    Railway Maintenance
    Location:
    Morecambe, Lancashire, England
    Balance:
    20,396Coins
    Ratings:
    +3,480 / 34 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 6DOF
    STOP PRESS !!!! STOP PRESS !!!!!!

    I think , i think I got it working.................... more to follow :D
    • Like Like x 2
    • Winner Winner x 2
  15. SilentChill

    SilentChill Problem Maker

    Joined:
    Jul 19, 2014
    Messages:
    2,619
    Occupation:
    Railway Maintenance
    Location:
    Morecambe, Lancashire, England
    Balance:
    20,396Coins
    Ratings:
    +3,480 / 34 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 6DOF



    Looking good but needs tweaking, the voltage never drops to zero so the 80mm fan spins all the time.
    • Like Like x 5
  16. Nick Moxley

    Nick Moxley Well-Known Member

    Joined:
    Dec 13, 2013
    Messages:
    2,779
    Occupation:
    Owner/Operator- Moxleys Rantals
    Location:
    Winnipeg Manitoba Canada
    Balance:
    17,054Coins
    Ratings:
    +2,504 / 30 / -2
    My Motion Simulator:
    2DOF, 3DOF, DC motor, JRK
    Interesting.
  17. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    20,465
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    144,626Coins
    Ratings:
    +10,741 / 52 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    Nice work @SilentChill...that 80mm fan really howls like a banshee as it winds up, so perhaps a bigger one running at a lower speed.
  18. Nick Moxley

    Nick Moxley Well-Known Member

    Joined:
    Dec 13, 2013
    Messages:
    2,779
    Occupation:
    Owner/Operator- Moxleys Rantals
    Location:
    Winnipeg Manitoba Canada
    Balance:
    17,054Coins
    Ratings:
    +2,504 / 30 / -2
    My Motion Simulator:
    2DOF, 3DOF, DC motor, JRK
    Or even a Run of Tubing with the fan opposite the other end, Similar to my Air cooling system but just a single run
  19. SilentChill

    SilentChill Problem Maker

    Joined:
    Jul 19, 2014
    Messages:
    2,619
    Occupation:
    Railway Maintenance
    Location:
    Morecambe, Lancashire, England
    Balance:
    20,396Coins
    Ratings:
    +3,480 / 34 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 6DOF

    Its the little server PSU fans that is howling the 80mm is quiet put it is constantly turning. I need to understand how the code works and what data it is receiving from the dash so I can get the voltage down to zero. Seems no coders on here can help ???

    I will persist in trying to get it to work properly.
  20. Mamati

    Mamati Member

    Joined:
    Jan 12, 2011
    Messages:
    52
    Location:
    Istanbul/Turkey
    Balance:
    158Coins
    Ratings:
    +6 / 1 / -0
    Hello,
    I want to use my Arduino Uno R3 and Monster Moto for controlling the Fan speed on my 2DOF NoLimits Roller coaster.
    Is there anyone who can give codes for that?