- 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);
}
Who is online?
In total there are 11 users online :: 0 Registered, 0 Hidden and 11 Guests
None
Most users ever online was 180 on Tue Nov 05, 2019 6:03 am
Latest topics
Search
Most Viewed Topics
Statistics
Our users have posted a total of 12534 messages in 1992 subjects
We have 1020 registered users
The newest registered user is JSAF
Similar topics
3 posters
Cheap Arduino Auto leveler
geofrancis- Posts : 323
Join date : 2021-09-24
- Post n°1
Cheap Arduino Auto leveler
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.
Deep Diver (Fred), david f and C-3PO like this post
C-3PO- Posts : 95
Join date : 2018-11-21
Location : Northamptonshire UK
- Post n°2
Re: Cheap Arduino Auto leveler
Deep Diver (Fred), david f and geofrancis like this post
17b- Posts : 9
Join date : 2023-06-19
- Post n°3
Re: Cheap Arduino Auto leveler
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
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- Posts : 95
Join date : 2018-11-21
Location : Northamptonshire UK
- Post n°4
Re: Cheap Arduino Auto leveler
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
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
17b- Posts : 9
Join date : 2023-06-19
- Post n°5
Re: Cheap Arduino Auto leveler
Hi, the MPU6050 has two 2k2 Resistors onboard. The Leveller works flawlessly
C-3PO likes this post
C-3PO- Posts : 95
Join date : 2018-11-21
Location : Northamptonshire UK
- Post n°6
Re: Cheap Arduino Auto leveler
Hi 17b,
Great - I did not know that - "everyday is a school day..."
Regards
C-3PO
Great - I did not know that - "everyday is a school day..."
Regards
C-3PO
geofrancis- Posts : 323
Join date : 2021-09-24
- Post n°7
Re: Cheap Arduino Auto leveler
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
17b- Posts : 9
Join date : 2023-06-19
- Post n°8
Re: Cheap Arduino Auto leveler
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
geofrancis- Posts : 323
Join date : 2021-09-24
- Post n°9
Re: Cheap Arduino Auto leveler
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
17b- Posts : 9
Join date : 2023-06-19
- Post n°10
Re: Cheap Arduino Auto leveler
Folks, i nearly finished my depth Controller. As i promised, i will share my Designs and Code. Right now the depth Controller ist very well useable, i use it in my 202 Friedrich Schürer. There is also a second different build with an X-Mixer and no depth sensor. My next step is to merge them into one universal Board, the PCBs from China arrive next week.
Here is a link to my (german) Webpage:
https://www.rc-sub.de/elektronik-mit-picaxe/161-lage-tiefenregler-auf-arduino-basis
Please remember, this is still Work in Progress.
If you have any questions, feel free to ask.
Here is a link to my (german) Webpage:
https://www.rc-sub.de/elektronik-mit-picaxe/161-lage-tiefenregler-auf-arduino-basis
Please remember, this is still Work in Progress.
If you have any questions, feel free to ask.
Deep Diver (Fred) and geofrancis like this post
Tue Oct 29, 2024 4:46 pm by tsenecal
» RC Drift Gyro for pitch control
Sun Oct 20, 2024 2:04 pm by geofrancis
» WW2 mini sub build
Thu Oct 17, 2024 2:34 pm by geofrancis
» sonar data link
Mon Oct 14, 2024 4:31 pm by geofrancis
» Robbe Seawolf V2
Sat Oct 12, 2024 3:52 pm by geofrancis
» ExpressLRS - 868/915 Mhz equipment
Fri Oct 11, 2024 8:58 pm by Marylandradiosailor
» Flight controllers as sub levelers
Fri Oct 11, 2024 8:14 pm by geofrancis
» 868/915 Mhz as a viable frequency for submarines.
Thu Oct 10, 2024 3:21 am by tsenecal
» Microgyro pitch controller corrosion
Wed Oct 02, 2024 11:32 am by geofrancis