• Die Forumsregeln und Nutzungsbedingungen findet ihr in der Navbar unter Impressum !
    Bitte unbedingt beachten!
    Wie überall im Leben gibt es Spielregeln, so auch hier!
    Die Datenschutzerklärung zum DSGVO findet ihr ebenfalls in der Navbar unter Datenschutzerklärung !
    Hinweis nach DSGVO :
    Es ist hier keinerlei Angabe erforderlich. Alle Angaben in diesem Bereich sind öffentlich sichtbar und werden freiwillig gemacht. Mit einem Eintrag in diesem Bereich erkenne ich dieses an, und bestätige die Datenschutzerklärung zur DSGVO für das Forum gelesen zu haben.

    Danke

Graupner Probleme mit Digitalem Servo PDI-6225MG-300

wortmann30

New member
Registriert
27.02.2006
Beiträge
681
Hallo zusammen,

kenn jemand von euch das 300° Servo PDI-6225MG-300?

Es ist ein Digitales Servo mit einem JR Stecker.

ich versuche diese mit einem Arduino Testprogramm anzusteuern aber ich kann dem Freund nur ein leises Kacken entlocken, wenn ich ein normales 180° Servo anhänge läuft dies wie es soll.
Also scheint es nicht an der Ansteuerung zu liegen, ich bin echt Ratlos.

Grüße Marc
 
Hallo Marc,

hast du die Spannungsversorgung von den 5V des Arduino oder eine extra Spannungsversorgung?
Der Arduino bzw. der USB Anschluss haben nicht genug Strom um einen digitalen Servo anzusteuern.
Bei einer externen Spannungsquelle immer daran denken die Minus Leitungen miteinander zu verbinden.
 
Hi

ja habe ich ich versorge es über eine Batterie mit 5v und Masse ist verbunden.

Auch mit einem Labor Netzgerät hilft das nichts.
 
Poste doch mal deinen Code (einfügen mit # neben den Videos)
 
Es ist einmal der zum testen:
Code:
// Servo Library einbinden
#include <Servo.h>
 
// Neues Servo Objekt erstellen
Servo myservo;
// Wert des Potentiometers hier speichern
int val;
 
// setup() wird einmal zu Programmbeginn ausgeführt
void setup()
{
  // Servo an Pin 9 koppeln
  myservo.attach(9);
  // Serielle Kommunikation starten
  Serial.begin(9600);
}
 
// loop() wird endlos wiederholt
void loop()
{
  // Stellung des Potentiometers an Anlog-Eingang 5 auslesen
  val = analogRead(5);
  // 10-bit Wert des Analogeingangs (0-1023) in Winkel 0-180 umrechnen
  val = map(val, 0, 1023, 0, 180);
 
  // Errechneten Winkel zur Kontrolle an den PC übertragen (Seriellen Monitor starten!)
  Serial.println(val);
  // Einstellwinkel in Grad an das Servo-Objekt schicken
  myservo.write(val);
  // Kurze Pause, damit der Servo die neue Position anfahren kann
  delay(50);
}

Und der der reell verwendet wird nachher mit Display, bei beiden das gleiche.
Code:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Servo.h>
#include <Fonts/FreeMonoBoldOblique12pt7b.h>

Servo myservo;  // create servo object to control a servo

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

int potpin = A7;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin
int val1;   // variable to scale Servo rotation to %

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define NUMFLAKES     10 // Number of snowflakes in the animation example

#define LOGO_HEIGHT   16
#define LOGO_WIDTH    16
static const unsigned char PROGMEM logo_bmp[] =
{ B00000000, B11000000,
  B00000001, B11000000,
  B00000001, B11000000,
  B00000011, B11100000,
  B11110011, B11100000,
  B11111110, B11111000,
  B01111110, B11111111,
  B00110011, B10011111,
  B00011111, B11111100,
  B00001101, B01110000,
  B00011011, B10100000,
  B00111111, B11100000,
  B00111111, B11110000,
  B01111100, B11110000,
  B01110000, B01110000,
  B00000000, B00110000 };

void setup() {
  //Serial.begin(9600);
  //  Serial.println(F("Start"));

  myservo.attach(9);  // attaches the servo on pin 9 to the servo object

  //SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    //Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }

  // Show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen.
  display.display();
  delay(2000); // Pause for 2 seconds

  // Clear the buffer
  display.clearDisplay();

  // Draw a single pixel in white
  display.drawPixel(10, 10, SSD1306_WHITE);

  // Show the display buffer on the screen. You MUST call display() after
  // drawing commands to make them visible on screen!
  display.display();
  delay(2000);
  display.setFont(&FreeMonoBoldOblique12pt7b);
  display.clearDisplay();
  display.setTextSize(1);      // Normal 1:1 pixel scale
  display.setTextColor(SSD1306_WHITE); // Draw white text
  display.cp437(true);         // Use full 256 char 'Code Page 437' font
}

void loop() {

  // put your main code here, to run repeatedly:
  analogReference(EXTERNAL);
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  myservo.write(val);                  // sets the servo position according to the scaled value
  display.setCursor(0, 12);     // Start at top-left corner

  // Not all the characters will fit on the display. This is normal.
  // Library will draw what it can and the rest will be clipped.
  display.clearDisplay();
  display.print("Absaugung oben ");
//  display.setCursor(0, 36);     // Start at top-left corner
  val1 = map(val, 0, 180, 0, 100);
  display.print(val1); display.print("%");

  display.display();
  delay(15);   
  }

Mit Standard Servos geht das...
 
Hallo Marc,

du kommandierst ja einen Winkel (0-180°) den die Servo Libary umrechnet. Ich habe das wie folgt gemacht:

void setup()
{
Fahrtenregler.attach(9); // Pin D9 PPM Signal zum Fahrtenregler
Fahrtenregler.writeMicroseconds(1500); // PPM Signal zum Fahrtenregler
}


Im loop:

Fahrtenregler.writeMicroseconds(PPM_Fahrtenregler); // Ausgabewert für Fahrtenregler

PPM_Fahrtenregler ist dann der Wert von 800 bis 2000µs -> 0,8 bis 3 ms.

Damit funktioniert das.
 
Hallo Bert

Danke für deinen Vorschlag aber wäre es möglich das du mir das in meinem 2. Sketch einfügst?
Ich habe davon leider so ziemlich keine Ahnung und das Sketch auch nicht selber geschrieben.
 
Hallo Marc,

das kostet einen :prost
Code:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Servo.h>
#include <Fonts/FreeMonoBoldOblique12pt7b.h>

Servo myservo;  // create servo object to control a servo

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

int potpin = A7;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin
int Sollwert;   // Variable für den Servo im Bereich 800 bis 2000µs

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define NUMFLAKES     10 // Number of snowflakes in the animation example

#define LOGO_HEIGHT   16
#define LOGO_WIDTH    16
static const unsigned char PROGMEM logo_bmp[] =
{ B00000000, B11000000,
  B00000001, B11000000,
  B00000001, B11000000,
  B00000011, B11100000,
  B11110011, B11100000,
  B11111110, B11111000,
  B01111110, B11111111,
  B00110011, B10011111,
  B00011111, B11111100,
  B00001101, B01110000,
  B00011011, B10100000,
  B00111111, B11100000,
  B00111111, B11110000,
  B01111100, B11110000,
  B01110000, B01110000,
  B00000000, B00110000 };

void setup() {
  //Serial.begin(9600);
  //  Serial.println(F("Start"));

  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo.writeMicroseconds(1500);      // PPM Signal zum Servo (Mittelstellung)
  
  //SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    //Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }

  // Show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen.
  display.display();
  delay(2000); // Pause for 2 seconds

  // Clear the buffer
  display.clearDisplay();

  // Draw a single pixel in white
  display.drawPixel(10, 10, SSD1306_WHITE);

  // Show the display buffer on the screen. You MUST call display() after
  // drawing commands to make them visible on screen!
  display.display();
  delay(2000);
  display.setFont(&FreeMonoBoldOblique12pt7b);
  display.clearDisplay();
  display.setTextSize(1);      // Normal 1:1 pixel scale
  display.setTextColor(SSD1306_WHITE); // Draw white text
  display.cp437(true);         // Use full 256 char 'Code Page 437' font
}

void loop() {

  // put your main code here, to run repeatedly:
  analogReference(EXTERNAL);
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  Sollwert = map(val, 0, 1023, 800, 2000);     // scale it to use it with the servo (value between 0 and 180)
  myservo.writeMicroseconds(Sollwert);         // Servoposition in Abhängigkeit vom Eingngswert des Potis
  display.setCursor(0, 12);     // Start at top-left corner

  // Not all the characters will fit on the display. This is normal.
  // Library will draw what it can and the rest will be clipped.
  display.clearDisplay();
  display.print("Absaugung oben ");
//  display.setCursor(0, 36);     // Start at top-left corner
  val1 = map(val, 0, 180, 0, 100);
  display.print(val1); display.print("%");

  display.display();
  delay(15);   
  }

Meine Änderungen habe ich in Deutsch kommentiert. Sollte so funktionieren, da ich die Adafruit Libary nicht habe hat der Complier keinen vollen Durchlauf gemacht.

Arduino ist wirklich ne nette Sache, allerdings nur Programme downloaden die man nicht versteht ist wie einen 3D Drucker zu haben und nur Sachen anderer Leute auszudrucken.
Kauf dir das Buch "Arduino für Einsteiger" von Massimo Banzi, damit habe ich das auch gelernt. Es gibt von der ct noch ein make Magazin 3/2017 das ist auch gut.
Und hier im Forum

Viel Spaß damit!
 
Hallo Bert,

kam erst jetzt dazu es zu testen. Es kommt leider ein Fehler:
Unbenannt.jpg
:( Kannst du vielleicht nochmal drüber sehen?

Danke
 

Anhänge

  • Unbenannt.JPG
    Unbenannt.JPG
    104,6 KB · Aufrufe: 212
Hallo Marc.
Hast du die Servosteuerung und das Display Teil aus 2 verschiedenen Quellen kopiert?
Wenn ja, dann setze oben in die Deklaration wo -int val;- steht noch eine Zeile:
int vall; ein
Oder versuche an beiden Stellen wo vall steht in val zu ändern, und guck was dann passiert.
Weil ich habe mich jetzt nicht tiefer damit auseinandergesetzt.
 
Hi

nein das Sketch hat mir jemand geschrieben nur leider hat der keine Ahnung warum es nicht mir den 300 grad Servos läuft, daher meine frage hier.

Es ist ursprünglich hier: https://www.modelltruck.net/showthread.php?61681-Probleme-mit-Digitalem-Servo-PDI-6225MG-300&p=752009&viewfull=1#post752009 das Zweite.

Was da nicht Passt ist das im Anfang der Sketches diese Variable vorher "Val1" hieß und irgendwie hat Bert die umbenannt in "Sollwert".
Das habe ich angepasst. Weil viel kapier ich davon auch nicht...
Nun ist es so:
Code:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Servo.h>
#include <Fonts/FreeMonoBoldOblique12pt7b.h>

Servo myservo;  // create servo object to control a servo

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

int potpin = A7;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin
int Sollwert;   // Variable für den Servo im Bereich 800 bis 2000µs

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define NUMFLAKES     10 // Number of snowflakes in the animation example

#define LOGO_HEIGHT   16
#define LOGO_WIDTH    16
static const unsigned char PROGMEM logo_bmp[] =
{ B00000000, B11000000,
  B00000001, B11000000,
  B00000001, B11000000,
  B00000011, B11100000,
  B11110011, B11100000,
  B11111110, B11111000,
  B01111110, B11111111,
  B00110011, B10011111,
  B00011111, B11111100,
  B00001101, B01110000,
  B00011011, B10100000,
  B00111111, B11100000,
  B00111111, B11110000,
  B01111100, B11110000,
  B01110000, B01110000,
  B00000000, B00110000 };

void setup() {
  //Serial.begin(9600);
  //  Serial.println(F("Start"));

  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo.writeMicroseconds(1500);      // PPM Signal zum Servo (Mittelstellung)
  
  //SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    //Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }

  // Show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen.
  display.display();
  delay(2000); // Pause for 2 seconds

  // Clear the buffer
  display.clearDisplay();

  // Draw a single pixel in white
  display.drawPixel(10, 10, SSD1306_WHITE);

  // Show the display buffer on the screen. You MUST call display() after
  // drawing commands to make them visible on screen!
  display.display();
  delay(2000);
  display.setFont(&FreeMonoBoldOblique12pt7b);
  display.clearDisplay();
  display.setTextSize(1);      // Normal 1:1 pixel scale
  display.setTextColor(SSD1306_WHITE); // Draw white text
  display.cp437(true);         // Use full 256 char 'Code Page 437' font
}

void loop() {

  // put your main code here, to run repeatedly:
  analogReference(EXTERNAL);
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  Sollwert = map(val, 0, 1023, 800, 2000);     // scale it to use it with the servo (value between 0 and 180)
  myservo.writeMicroseconds(Sollwert);         // Servoposition in Abhängigkeit vom Eingngswert des Potis
  display.setCursor(0, 12);     // Start at top-left corner

  // Not all the characters will fit on the display. This is normal.
  // Library will draw what it can and the rest will be clipped.
  display.clearDisplay();
  display.print("Absaugung oben ");
//  display.setCursor(0, 36);     // Start at top-left corner
  Sollwert = map(val, 0, 180, 0, 100);
  display.print(Sollwert); display.print("%");

  display.display();
  delay(15);   
  }

Was nun passiert, es lässt sich kompilieren und auch hochladen.
Wenn ich jetzt am, Poti drehe ändert sich die Anzeige im Display von 0% bis zu 568% aber das 300° Servo knackt immer noch und bewegt sich nicht.
Ein Parallel angeschlossenes Standard Servo dreht sich. Aber auch nur noch ca. 110° keine 180° mehr. :(
 
Bist du sicher, das das Servo in Ordnung ist?
Weil, ich bin jetzt mal der Meinung es müsste sich drehen, wenn auch mit falschen Werten falls das Programm nicht stimmt.
Wenn das normale Servo dreht, müsste das digitale sich auch drehen.
Ich habe leider kein solches Servo zum testen.

Ach das hieß val1 ich habe das als vall gelesen.
Dann ersetze unten mal bitte das val1 beide Male mal durch Sollwert
 
Hallo Marc,

hast du das Digitalservo schon einmal woanders dran gehabt und hat es da funktioniert?

Code:
int val1;

void loop() {

  // put your main code here, to run repeatedly:
  analogReference(EXTERNAL);
  val = analogRead(potpin);                          // reads the value of the potentiometer (value between 0 and 1023)
  Sollwert = map(val, 0, 1023, 800, 2000);       // Potisignal Ausgangssignal 800 bis 2000 µs
  myservo.writeMicroseconds(Sollwert);          // Servoposition in Abhängigkeit vom Eingangswert des Potis
  display.setCursor(0, 12);                            // Start at top-left corner

  // Not all the characters will fit on the display. This is normal.
  // Library will draw what it can and the rest will be clipped.
  display.clearDisplay();
  display.print("Absaugung oben ");
  display.setCursor(0, 36);     // Start at top-left corner

  val1 = map(val, 0, 1023, 0, 100);                  // das ist für die Anzeige -> Potiwert = 0-100%
  display.print(val1); display.print("%");          

  display.display();
  delay(15);   
  }
 
Zum Thema Servos, ich habe diese servos neu gekauft und noch nirgend am Laufen gehabt.
Aber ich habe 2 gekauft und irgendwie wäre es ja ein sehr großer Zufall wenn die beide kaputt wären.

Also das ist ganz komisch... Aber ich versuche es mall zusammen zu fassen was im Moment passiert.

Aktuell hab ich das Sketch geladen:
Code:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Servo.h>
#include <Fonts/FreeMonoBoldOblique12pt7b.h>

Servo myservo;  // create servo object to control a servo

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

int potpin = A7;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin
int Sollwert;   // Variable für den Servo im Bereich 800 bis 2000µs
int val1;

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define NUMFLAKES     10 // Number of snowflakes in the animation example

#define LOGO_HEIGHT   16
#define LOGO_WIDTH    16
static const unsigned char PROGMEM logo_bmp[] =
{ B00000000, B11000000,
  B00000001, B11000000,
  B00000001, B11000000,
  B00000011, B11100000,
  B11110011, B11100000,
  B11111110, B11111000,
  B01111110, B11111111,
  B00110011, B10011111,
  B00011111, B11111100,
  B00001101, B01110000,
  B00011011, B10100000,
  B00111111, B11100000,
  B00111111, B11110000,
  B01111100, B11110000,
  B01110000, B01110000,
  B00000000, B00110000 };

void setup() {
  //Serial.begin(9600);
  //  Serial.println(F("Start"));

  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo.writeMicroseconds(1500);      // PPM Signal zum Servo (Mittelstellung)
  
  //SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    //Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }

  // Show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen.
  display.display();
  delay(2000); // Pause for 2 seconds

  // Clear the buffer
  display.clearDisplay();

  // Draw a single pixel in white
  display.drawPixel(10, 10, SSD1306_WHITE);

  // Show the display buffer on the screen. You MUST call display() after
  // drawing commands to make them visible on screen!
  display.display();
  delay(2000);
  display.setFont(&FreeMonoBoldOblique12pt7b);
  display.clearDisplay();
  display.setTextSize(1);      // Normal 1:1 pixel scale
  display.setTextColor(SSD1306_WHITE); // Draw white text
  display.cp437(true);         // Use full 256 char 'Code Page 437' font
}

void loop() {

  // put your main code here, to run repeatedly:
  analogReference(EXTERNAL);
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  Sollwert = map(val, 0, 1023, 500, 2500);     // scale it to use it with the servo (value between 0 and 180)
  myservo.writeMicroseconds(Sollwert);                  // sets the servo position according to the scaled value
  display.setCursor(0, 12);     // Start at top-left corner

  // Not all the characters will fit on the display. This is normal.
  // Library will draw what it can and the rest will be clipped.
  display.clearDisplay();
  display.print("Absaugung oben ");
//  display.setCursor(0, 36);     // Start at top-left corner
  
  val1 = map(val, 0, 1023, 0, 100);
  display.print(val1); display.print("%");

  display.display();
  delay(15);   
  }

Der Arduino wird vom PC derzeit über den USB mit Power versorgt.
Das servo hängt an 4 AAA Batterien.

So wenn ich das ganze nun starte also power auf dem Arduino gebe zeigt er das an im Display was er soll aber das servo klickert nur.
So nun habe ich aus irgend einem Grund an dem Servo in diesem Zustand von Hand gedreht, und siehe da er dreht sich dann lässt es sich auch eine weile mit dem Poti verfahren wenn ich jetzt versuche des von Hand aus der Stellung zu bringen kann ich da nichts bewegen.
Irgendwann hört das allerdings auf und es klickert wieder nur, dann kann ich es von Hand wieder verdrehen und es läuft in die Stellung die sein soll. Dort ist es wieder nicht von Hand zu drehen...
Und so geht das Spiel immer wieder...:sauer
 
Versorge mal bitte weiter dein Servo über die 4 AAA und den Arduino nicht über die USB, sondern mit 5 Volt vom Labornetzteil. Anschließen an die Pinne VCC-5V und GND. GND und Minus von Batterien verbinden.
Oder beide ans Labornetzteil bei 5 Volt ohne Strombregrenzung oder mit Begrenzung 2A.
 
So jetzt hab ich was ganz unkonventionelles gemacht und die Elektronik meines Lasers belastet.

Und zwar habe ich darin ein 24V 3A Netzteil, dass den Laser versorgt und einen DC DC stepp down Modul das mir 5 V für die Arduinos erstellt, das hat ich abgezwackt und jetzt geht es eigentlich fast immer irgendwie war der Strom der gezogen wurde zu viel und die Batterien ging kurz in die Knie dann ist das Servo ausgestiegen, anders kann ich mir das nicht erklären...

Verstehe das wer will.

Im Laser werde ich nun ein zweites DC DC stepdown Modul nur für die Servos mit 6V einbauen.

Jetzt habe ich noch einen Anschlag vor.

Für die Abluft Regelung benötige ich zwei Servos. Mit einem Stelle ich das Poti der min Volumenstrom ein und das andere stellt den Max Volumenstrom ein.
Welche teile muss ich da kopieren um zwei Servos zu kontrollieren die mit zwei Potis angesteuert werden.

Im Display sollen dann zwei Zeilen dargestellt werden:
Min XX%
Max XX%

Das wäre ne coole Sache!!!
 
Hallo Marc,

ich helfe ja gerne, aber ich schreibe keine Programme für andere Leute.
Sieh dir mal dein Programm an, druck es aus und markier die Zusammenhänge. Das Programm hat nur ein paar Zeilen und die sind auch noch gut beschrieben.
Der Arduino Complier sagt dir schon wenn was fehlt. Sollte das Ergebnis nicht laufen, stell es hier rein, dann sehen wir uns das zusammen an.
 
Wow ich bin ja fast stolz auf mich, dass ich das verstanden habe... :like

Jetzt laufen beide Servos mit diesem Sketch.
Code:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Servo.h>
#include <Fonts/FreeMonoBoldOblique12pt7b.h>

Servo myservo;  // create servo object to control a servo

Servo myservo2;  // create servo object to control a servo

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

int potpin = A7;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin
int Sollwert;   // Variable für den Servo im Bereich 800 bis 2000µs
int val1;
int potpin2 = A6;  // analog pin used to connect the potentiometer
int val2;    // variable to read the value from the analog pin
int Sollwert2;   // Variable für den Servo im Bereich 800 bis 2000µs
int val12;

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define NUMFLAKES     10 // Number of snowflakes in the animation example

#define LOGO_HEIGHT   16
#define LOGO_WIDTH    16
static const unsigned char PROGMEM logo_bmp[] =
{ B00000000, B11000000,
  B00000001, B11000000,
  B00000001, B11000000,
  B00000011, B11100000,
  B11110011, B11100000,
  B11111110, B11111000,
  B01111110, B11111111,
  B00110011, B10011111,
  B00011111, B11111100,
  B00001101, B01110000,
  B00011011, B10100000,
  B00111111, B11100000,
  B00111111, B11110000,
  B01111100, B11110000,
  B01110000, B01110000,
  B00000000, B00110000 };

void setup() {
  //Serial.begin(9600);
  //  Serial.println(F("Start"));

  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo.writeMicroseconds(1500);      // PPM Signal zum Servo (Mittelstellung)
  
  myservo2.attach(8);  // attaches the servo on pin 9 to the servo object
  myservo2.writeMicroseconds(1500);      // PPM Signal zum Servo (Mittelstellung) 
  
  //SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    //Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }

  // Show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen.
  display.display();
  delay(2000); // Pause for 2 seconds

  // Clear the buffer
  display.clearDisplay();

  // Draw a single pixel in white
  display.drawPixel(10, 10, SSD1306_WHITE);

  // Show the display buffer on the screen. You MUST call display() after
  // drawing commands to make them visible on screen!
  display.display();
  delay(2000);
  display.setFont(&FreeMonoBoldOblique12pt7b);
  display.clearDisplay();
  display.setTextSize(1);      // Normal 1:1 pixel scale
  display.setTextColor(SSD1306_WHITE); // Draw white text
  display.cp437(true);         // Use full 256 char 'Code Page 437' font
}

void loop() {

  // put your main code here, to run repeatedly:
  analogReference(EXTERNAL);
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  Sollwert = map(val, 0, 1023, 500, 2500);     // scale it to use it with the servo (value between 0 and 180)
  myservo.writeMicroseconds(Sollwert);                  // sets the servo position according to the scaled value
  display.setCursor(0, 12);     // Start at top-left corner

  // Not all the characters will fit on the display. This is normal.
  // Library will draw what it can and the rest will be clipped.
  display.clearDisplay();
  display.print("MIN ");
//  display.setCursor(0, 36);     // Start at top-left corner
  
  val1 = map(val, 0, 1023, 0, 100);
  display.print(val1); display.print("%");

  display.display();
  delay(15);   

    // put your main code here, to run repeatedly:
  analogReference(EXTERNAL);
  val2 = analogRead(potpin2);            // reads the value of the potentiometer (value between 0 and 1023)
  Sollwert2 = map(val2, 0, 1023, 500, 2500);     // scale it to use it with the servo (value between 0 and 180)
  myservo2.writeMicroseconds(Sollwert2);                  // sets the servo position according to the scaled value
  display.setCursor(0, 12);     // Start at top-left corner

  // Not all the characters will fit on the display. This is normal.
  // Library will draw what it can and the rest will be clipped.
  display.clearDisplay();
  display.print("MAX ");
//  display.setCursor(0, 36);     // Start at top-left corner
  
  val12 = map(val2, 0, 1023, 0, 100);
  display.print(val12); display.print("%");

  display.display();
  delay(15);  
  }

Jetzt habe ich nur das Problem das auf dem Display immer abwechselnd die Min / Max Wert dargestellt wird.
Wie erklär ich dem Teil das der Zweite Wert in die Zweiten Zeile geschrieben werden soll?

Durch die Änderung
Code:
  analogReference(EXTERNAL);
  val2 = analogRead(potpin2);            // reads the value of the potentiometer (value between 0 and 1023)
  Sollwert2 = map(val2, 0, 1023, 500, 2500);     // scale it to use it with the servo (value between 0 and 180)
  myservo2.writeMicroseconds(Sollwert2);                  // sets the servo position according to the scaled value
  display.setCursor(0, 36);     // Start at top-left corner

In der Pixel Zahl habe ich das untereinander hinbekommen, jetzt flackert es aber immer von oben nach unten?
Zumal hätte ich gerne die Schrift ein klein wenig grösser.
 
Hallo Marc,

schön das es nun geht :ok und das mit dem Display bekommen wir auch hin ;)

display.setCursor(0, 36); // Setzt der Cursor ( also da wo man schreibt) auf die Zeile 0 und die Spalte 36

display.print(val12); // schreibt den Wert aus val2 dort hin wo der Cursor steht

display.print("%"); // schreibt den "TEXT" also hier % dahin wo der Cursor aktuell ist

display.clearDisplay(); // löscht den Inhalt des Displays

Die Anzahl der Zeile und Spalten steht im Datenblatt vom Display, auch ob die mit 0 oder 1 anfangen zu zählen
 
Ja das ist richtig Aber irgendwie dadurch das ich diesen Teil zwei mal definiert habe schreibt er das eben nacheinander und es flackert.
Ich weiß nicht wie ich das in eines bekomme so das es nicht flackert und untereinander ist.
 
Hallo Marc,

du hast zwei Mal: display.clearDisplay(); // löscht den Inhalt des Displays
lösch einfach mal den zweiten einen Eintrag weiter unten

Mit display.setCursor(0, 36); // Setzt der Cursor ( also da wo man schreibt) auf die Zeile 0 und die Spalte 36

Mit display.setCursor(1, 36); // Setzt der Cursor ( also da wo man schreibt) auf die Zeile 1 und die Spalte 36

das musst du vor dem Befehlen

display.print(val12); // schreibt den Wert aus val2 dort hin wo der Cursor steht

display.print("%"); // schreibt den "TEXT" also hier % dahin wo der Cursor aktuell ist

setzen, sonst überschreibt der sich immer wieder
 
So jetzt habe ich mal damit weiter Experimentiert.
du hast zwei Mal: display.clearDisplay(); // löscht den Inhalt des Displays
lösch einfach mal den zweiten einen Eintrag weiter unten

Das hab ich gemacht jetzt ist die erste Linie konstant da und die Zweite flackert noch, also wird immer im ca. 0,5sec Intervall geschrieben.


Mit display.setCursor(0, 36); // Setzt der Cursor ( also da wo man schreibt) auf die Zeile 0 und die Spalte 36

Mit display.setCursor(1, 36); // Setzt der Cursor ( also da wo man schreibt) auf die Zeile 1 und die Spalte 36
Das mit diesen Zahlen habe ich verstanden und den Text auch schon in die Mitte des Displays gesetzt.

das musst du vor dem Befehlen

display.print(val12); // schreibt den Wert aus val2 dort hin wo der Cursor steht

display.print("%"); // schreibt den "TEXT" also hier % dahin wo der Cursor aktuell ist

setzen, sonst überschreibt der sich immer wieder

Das hab ich aber glaube ich nicht verstanden was du meinst.

- - - Aktualisiert - - -

So jetzt habe ich
Code:
display.display();
  delay(15);
nach dem ersten ml Print "MIN" weg genommen jetzt geht es und sieht so aus!
Code:
void loop() {

  // put your main code here, to run repeatedly:
  analogReference(EXTERNAL);
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  Sollwert = map(val, 0, 1023, 500, 2500);     // scale it to use it with the servo (value between 0 and 180)
  myservo.writeMicroseconds(Sollwert);                  // sets the servo position according to the scaled value
  display.setCursor(10, 20);     // Start at top-left corner

  // Not all the characters will fit on the display. This is normal.
  // Library will draw what it can and the rest will be clipped.
  display.clearDisplay();
  display.print("MIN ");
//  display.setCursor(0, 36);     // Start at top-left corner
  
  val1 = map(val, 0, 1023, 0, 100);
  display.print(val1); display.print("%");

  

    // put your main code here, to run repeatedly:
  analogReference(EXTERNAL);
  val2 = analogRead(potpin2);            // reads the value of the potentiometer (value between 0 and 1023)
  Sollwert2 = map(val2, 0, 1023, 500, 2500);     // scale it to use it with the servo (value between 0 and 180)
  myservo2.writeMicroseconds(Sollwert2);                  // sets the servo position according to the scaled value
  display.setCursor(10, 50);     // Start at top-left corner

  // Not all the characters will fit on the display. This is normal.
  // Library will draw what it can and the rest will be clipped.
  display.print("MAX ");
//  display.setCursor(0, 36);     // Start at top-left corner
  
  val12 = map(val2, 0, 1023, 0, 100);
  display.print(val12); display.print("%");

  display.display();
  delay(15);  
  }
 
Hallo Marc,

zwei kleine Tips:
1. Schreib dir deine eigenen Kommentare rein, in einer Woche hast du das nämlich vergessen
2. es gibt da Codezeilen die mit // beginnen, die werden nicht ausgeführt, der Complier sieht die als Kommentare. Kannst du also löschen wenn es keine Kommentare sind.
 
Super das werde ich machen.

Noch eine Sache das ist aber wirklich das letzte in diesem Bezug.

Ich muss noch einmal das Ursprüngliche Programm anpassen das ein Flow Sensor auf z.B. D2 angeschlossen wird und mir Zwei Signale rausgibt, ein High und ein Invertiertes Low wenn der Eingang D2 Pulse war nimmt, wenn für länger als eine Sekunde die Pulse ausbleiben sollen die Ausgänge wieder auf Low respektive auf High gehen.

Dazu habe ich mit Sketchen experimentiert welche aber den Durchfluss messen, dass ist aber fast über das Ziel hinaus geschossen.

1. Darf ich Deine / Eure Hilfe nochmals in Anspruch nehmen und
2. Soll ich das hier posten oder einen neuen Beitrag auf machen da es damit nicht direkt zu tun hat?

Danke
 

Servonaut
Zurück
Oben Unten