The Association of Model Submariners.

Would you like to react to this message? Create an account in a few clicks or log in to continue.

* THE FORUM FOR ALL THOSE INTERESTED IN BUILDING AND OPERATING MODEL SUBMARINES *



Join the AMS - Registered Forum users can become members of the AMS and it's free ...... To join send an email with your name , address and phone number to amstreasure@googlemail.com


For a guide to past events see the "Shows and Events" section.

//

$$$

&&&

::::

Who is online?

In total there are 3 users online :: 0 Registered, 0 Hidden and 3 Guests :: 1 Bot

None


Most users ever online was 180 on Tue Nov 05, 2019 6:03 am

Latest topics

» WW2 mini sub build
Cheap Arduino Auto leveler  EmptyYesterday at 9:05 pm by SimonH

» ExpressLRS - 868/915 Mhz equipment
Cheap Arduino Auto leveler  EmptyTue Nov 28, 2023 12:26 pm by geofrancis

» Flight controllers as sub levelers
Cheap Arduino Auto leveler  EmptyTue Nov 21, 2023 9:38 am by geofrancis

» Bournville 2023
Cheap Arduino Auto leveler  EmptyMon Nov 13, 2023 8:24 pm by Tom(ADMIN)

» Raspberry Pi Pico + ePaper display hat
Cheap Arduino Auto leveler  EmptyFri Nov 10, 2023 11:25 am by SimonH

» Help with 1:48 scale WW2 German U boat
Cheap Arduino Auto leveler  EmptyWed Nov 08, 2023 8:26 pm by tsenecal

» Problem with Futaba FX-30 and 40 MHz module
Cheap Arduino Auto leveler  EmptyMon Nov 06, 2023 2:53 pm by david f

» Resurgam, Nordenfelts II & IV - George Garrett's works.
Cheap Arduino Auto leveler  EmptyMon Nov 06, 2023 2:48 pm by david f

» Letter to BMFA to request the sharing of the 35MHz frequency for model subs in the UK.
Cheap Arduino Auto leveler  EmptyWed Nov 01, 2023 5:22 pm by geofrancis

Statistics

Our users have posted a total of 12334 messages in 1969 subjects

We have 993 registered users

The newest registered user is tywade81@gmail.com

2 posters

    Cheap Arduino Auto leveler

    avatar
    geofrancis


    Posts : 258
    Join date : 2021-09-24

    Cheap Arduino Auto leveler  Empty Cheap Arduino Auto leveler

    Post  geofrancis Thu May 11, 2023 2:38 pm

    I just found this video on youtube showing a very cheap arduino based sub leveler based on Atmega328 and a MPU6050 IMU looks interesting, I havent tested it myself.




    Code:
     
    #include Wire.h
    #include MPU6050_light.h
    #include Servo.h
    #include ServoInput.h

    //Define Variables we'll be connecting to
    double Setpoint, Input, Output, Gain1, Gain2;

    ServoInputPin-3- TR;                //angled brackets here
    //Signal diveplane from receiver to PWM pin 2
    ServoInputPin-2- Switch(800, 1800);  //angled brackets here
    //switch signal from receiver  PWM pin 3 cal for 3Pos switch Transmitter channel 5 (mc-10)

    const int NumPositions = 3;

    Servo servoTR;                    
     //creates a Servo with the name „servoTR“ =Tiefenruder

    MPU6050 mpu(Wire);

    void setup()
    {
        Serial.begin(9600);
        Serial.flush();
        Wire.begin();
        mpu.begin();
        //Serial.println(F("Calculating gyro offset, do not move MPU6050"));
        //delay(1000);
        mpu.calcGyroOffsets();
        Serial.println("Done.");


        //Input = mpu.getAngleX();
        Setpoint = 100;     //0-Referenz of gyro, approx. in degrees servo arm (0...180)
        Gain1 = 5;          
        Gain2 = 7;          

        servoTR.attach(8); // Servo  signal wire (yellow)  connected to pin 8
    }

    void loop()
    {
        mpu.update();

        float rudder = TR.getAngle();                
    // get angle of servo (0 - 180) TR input from receiver
     
        int position = Switch.map(1, NumPositions);  // get Switch pos 1-3
      
      
        if (position ==1)
     {
        servoTR.write(Setpoint - mpu.getAngleX() * Gain1);  
      }
        else if (position==2)
       {
        servoTR.write(Setpoint - mpu.getAngleX() * Gain2);
       }
      
        else
      {
        Output = rudder;          // schleift Senderinput durch zu TR Servo
        servoTR.write(Output);
      }
        
        
    // Serial.print("Switch Position: ");
    // Serial.println(position);
    //    
    // Serial.println(rudder);
      
    //    
    //  Serial.println("\tY: " + String(mpu.getAngleY()));
    //    delay(50);
    }

    david f and C-3PO like this post

    C-3PO
    C-3PO


    Posts : 92
    Join date : 2018-11-21
    Location : Northamptonshire UK

    Cheap Arduino Auto leveler  Empty Re: Cheap Arduino Auto leveler

    Post  C-3PO Sat May 13, 2023 11:23 am

    I have not tried code - but to get it to compile you need to add  < & > as per yellow highlights

    Cheap Arduino Auto leveler  Levell10

    Why do people hammer their code in the loop millions of times per second!!!

    Regards
    Jonathan

    david f and geofrancis like this post


      Current date/time is Sun Dec 03, 2023 12:53 am