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.

Papplewick Pumping Station SUBMARINE Day. 31st March - 1st April 2024.

$$$

&&&

::::

Who is online?

In total there are 2 users online :: 0 Registered, 0 Hidden and 2 Guests

None


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

Latest topics

» Information on camouflage patterns for German seahund
Cheap Arduino Auto leveler  EmptyFri Mar 15, 2024 4:36 pm by david f

» WW2 mini sub build
Cheap Arduino Auto leveler  EmptyTue Mar 12, 2024 1:56 pm by geofrancis

» Not the hobby I expected :)
Cheap Arduino Auto leveler  EmptySun Mar 10, 2024 6:30 pm by cat

» 868/915 Mhz as a viable frequency for submarines.
Cheap Arduino Auto leveler  EmptyWed Mar 06, 2024 4:50 pm by tsenecal

» Sheerline gasket material
Cheap Arduino Auto leveler  EmptyMon Feb 19, 2024 9:24 pm by Michaelc

» Choice of CAD software and Printer for 3D printing
Cheap Arduino Auto leveler  EmptyThu Feb 15, 2024 1:53 pm by david f

» Engel Nautlus
Cheap Arduino Auto leveler  EmptyTue Feb 13, 2024 9:15 am by palmert6

» RF 27/433MHz maximum depth in pools (1-5 ppm chlorine, 6-8pH)
Cheap Arduino Auto leveler  EmptyThu Feb 08, 2024 2:05 pm by david f

» Arduino proportional control of a piston tank
Cheap Arduino Auto leveler  EmptyThu Feb 08, 2024 1:37 pm by david f

Statistics

Our users have posted a total of 12425 messages in 1980 subjects

We have 1003 registered users

The newest registered user is Stefan Udovenko КПДЮ

3 posters

    Cheap Arduino Auto leveler

    avatar
    geofrancis


    Posts : 282
    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);
    }

    Deep Diver (Fred), david f and C-3PO like this post

    C-3PO
    C-3PO


    Posts : 95
    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

    Deep Diver (Fred), david f and geofrancis like this post

    avatar
    17b


    Posts : 8
    Join date : 2023-06-19

    Cheap Arduino Auto leveler  Empty Re: Cheap Arduino Auto leveler

    Post  17b Thu Dec 28, 2023 11:30 pm

    Hi Guys, inspired by this code and the YT Video i made a leveller/depth controller by myself. All work till now is documented on my HP. Unfortunately its only in german.
    Code and Layout can be sent per mail if anyone ist interested.

    This is Work in Progress

    https://www.rc-sub.de/component/content/article/161-lage-tiefenregler-auf-arduino-basis?catid=27:elektronik-mit-arduino&Itemid=2080

    Deep Diver (Fred), david f, C-3PO and geofrancis like this post

    C-3PO
    C-3PO


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

    Cheap Arduino Auto leveler  Empty Re: Cheap Arduino Auto leveler

    Post  C-3PO Fri Dec 29, 2023 8:26 am

    Hi 17b,

    Great project - I cannot remember - you might want to check out i2c pullup resistors - not sure if Pro Mini has them on board


    I2C and pull-up resistors

    For effective data transmission with the Inter-Integrated Circuit (I2C) protocol using Arduino, it’s often necessary to use external pull-up resistors on the designated I2C pins. Most Arduino boards don’t have pre-installed pull-up resistors on these pins, but instead they offer exposed pads for surface mount resistors. This gives more flexibity on how these pins can be used. More specifically:


    Regards
    C-3PO
    avatar
    17b


    Posts : 8
    Join date : 2023-06-19

    Cheap Arduino Auto leveler  Empty Re: Cheap Arduino Auto leveler

    Post  17b Fri Dec 29, 2023 8:47 am

    Hi, the MPU6050 has two 2k2 Resistors onboard. The Leveller works flawlessly

    C-3PO likes this post

    C-3PO
    C-3PO


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

    Cheap Arduino Auto leveler  Empty Re: Cheap Arduino Auto leveler

    Post  C-3PO Fri Dec 29, 2023 9:01 am

    Hi 17b,

    Great - I did not know that - "everyday is a school day..."

    Regards
    C-3PO
    avatar
    geofrancis


    Posts : 282
    Join date : 2021-09-24

    Cheap Arduino Auto leveler  Empty Re: Cheap Arduino Auto leveler

    Post  geofrancis Fri Dec 29, 2023 2:56 pm

    17b wrote:Hi Guys, inspired by this code and the YT Video i made a leveller/depth controller by myself. All work till now is documented on my HP. Unfortunately its only in german.
    Code and Layout can be sent per mail if anyone ist interested.

    This is Work in Progress

    https://www.rc-sub.de/component/content/article/161-lage-tiefenregler-auf-arduino-basis?catid=27:elektronik-mit-arduino&Itemid=2080

    for pid control you should look at this library
    https://github.com/br3ttb/Arduino-PID-Library
    avatar
    17b


    Posts : 8
    Join date : 2023-06-19

    Cheap Arduino Auto leveler  Empty Re: Cheap Arduino Auto leveler

    Post  17b Fri Dec 29, 2023 6:19 pm

    geofrancis wrote:

    for pid control you should look at this library
    https://github.com/br3ttb/Arduino-PID-Library

    I will check it for further improvements. Seems to be easy to use. Exactly the right for me.

    BTW, are there actually any levellers out there which use PID? As i know from german manufacturers like Brüggen or Momo, they only use P for their levellers. I still have some old completely analog levellers from Nils Canditt who use PID, but they are discontinued since maybe 10 years or so.

    Deep Diver (Fred) and david f like this post

    avatar
    geofrancis


    Posts : 282
    Join date : 2021-09-24

    Cheap Arduino Auto leveler  Empty Re: Cheap Arduino Auto leveler

    Post  geofrancis Fri Dec 29, 2023 7:34 pm

    17b wrote:
    geofrancis wrote:

    for pid control you should look at this library
    https://github.com/br3ttb/Arduino-PID-Library

    I will check it for further improvements. Seems to be easy to use. Exactly the right for me.

    BTW, are there actually any levellers out there which use PID? As i know from german manufacturers like Brüggen or Momo, they only use P for their levellers. I still have some old completely analog levellers from Nils Canditt who use PID, but they are discontinued since maybe 10 years or so.


    You can just set the I and d to zero if you dont need it for leveling but you will need it for depth control.

    Deep Diver (Fred) and david f like this post


      Current date/time is Tue Mar 19, 2024 9:35 am