Popularny post Spidi-Andi Napisano Luty 7, 2025 Popularny post Udostępnij Napisano Luty 7, 2025 (edytowany) Witam. Chciałbym przedstawić mój pierwszy pojazd gąsienicowy zbudowany od podstaw. Pojazd ma panel sterowania poprzez przeglądarkę www. Sterowanie: Można nim sterować z telefonu laptopa tableta. Łączy się przez wifi router pojazd W przyszłości będzie na bluetooth. Co zostało wykorzystane: Esp32 z wyświetlaczem Oled Adapter rozszerzeń do Esp32 Sterownik silników L298N 2 x akumulatorki 18650 2 x silniczniczki z przekładnią Obudowę po wycinałem z deseczek sklejek i posklejane do kupy. Diagram podłączenia elementów: Kolejność pinów: Jeśli chcesz podpiąć wyświetlacz oled na przykład SSD1306 128x64. VCC - 3.3v GND - GND GPIO 21 - SDA GPIO 22 - SCL Kod: #include <WiFi.h> #include <WebServer.h> #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> // Replace with your network credentials const char* ssid = "SSID"; // Twoje SSID const char* password = "PASS"; // Twoje Hasło // Create an instance of the WebServer on port 80 WebServer server(80); // Motor 1 int motor1Pin1 = 14; int motor1Pin2 = 27; int enable1Pin = 13; // Motor 2 int motor2Pin1 = 26; int motor2Pin2 = 25; int enable2Pin = 12; // OLED display TWI address #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET -1 #define SCREEN_ADDRESS 0x3C Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); // Setting PWM properties const int freq = 30000; const int resolution = 8; int dutyCycle = 0; String valueString = String(0); void handleRoot() { const char html[] PROGMEM = R"rawliteral( <!DOCTYPE HTML><html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="icon" href="data:,"> <style> html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center; } .button { -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; background-color: #4CAF50; border: none; color: white; padding: 12px 28px; text-decoration: none; font-size: 26px; margin: 1px; cursor: pointer; } .button2 {background-color: #555555;} </style> <script> function moveForward() { fetch('/forward'); } function moveLeft() { fetch('/left'); } function stopRobot() { fetch('/stop'); } function moveRight() { fetch('/right'); } function moveReverse() { fetch('/reverse'); } function updateMotorSpeed(pos) { document.getElementById('motorSpeed').innerHTML = pos; fetch(`/speed?value=${pos}`); } </script> </head> <body> <h1>Motor Control</h1> <p><button class="button" onclick="moveForward()">FORWARD</button></p> <div style="clear: both;"> <p> <button class="button" onclick="moveLeft()">LEFT</button> <button class="button button2" onclick="stopRobot()">STOP</button> <button class="button" onclick="moveRight()">RIGHT</button> </p> </div> <p><button class="button" onclick="moveReverse()">REVERSE</button></p> <p>Motor Speed: <span id="motorSpeed">0</span></p> <input type="range" min="0" max="100" step="25" id="motorSlider" oninput="updateMotorSpeed(this.value)" value="0"/> </body> </html>)rawliteral"; server.send(200, "text/html", html); } void handleForward() { Serial.println("Forward"); digitalWrite(motor1Pin1, LOW); digitalWrite(motor1Pin2, HIGH); digitalWrite(motor2Pin1, LOW); digitalWrite(motor2Pin2, HIGH); server.send(200); } void handleLeft() { Serial.println("Left"); digitalWrite(motor1Pin1, LOW); digitalWrite(motor1Pin2, HIGH); digitalWrite(motor2Pin1, HIGH); digitalWrite(motor2Pin2, LOW); server.send(200); } void handleStop() { Serial.println("Stop"); digitalWrite(motor1Pin1, LOW); digitalWrite(motor1Pin2, LOW); digitalWrite(motor2Pin1, LOW); digitalWrite(motor2Pin2, LOW); server.send(200); } void handleRight() { Serial.println("Right"); digitalWrite(motor1Pin1, HIGH); digitalWrite(motor1Pin2, LOW); digitalWrite(motor2Pin1, LOW); digitalWrite(motor2Pin2, HIGH); server.send(200); } void handleReverse() { Serial.println("Reverse"); digitalWrite(motor1Pin1, HIGH); digitalWrite(motor1Pin2, LOW); digitalWrite(motor2Pin1, HIGH); digitalWrite(motor2Pin2, LOW); server.send(200); } void handleSpeed() { if (server.hasArg("value")) { valueString = server.arg("value"); int value = valueString.toInt(); if (value == 0) { ledcWrite(enable1Pin, 0); ledcWrite(enable2Pin, 0); digitalWrite(motor1Pin1, LOW); digitalWrite(motor1Pin2, LOW); digitalWrite(motor2Pin1, LOW); digitalWrite(motor2Pin2, LOW); } else { dutyCycle = map(value, 25, 100, 200, 255); ledcWrite(enable1Pin, dutyCycle); ledcWrite(enable2Pin, dutyCycle); Serial.println("Motor speed set to " + String(value)); } } server.send(200); } void setup() { Serial.begin(115200); // Set the Motor pins as outputs pinMode(motor1Pin1, OUTPUT); pinMode(motor1Pin2, OUTPUT); pinMode(motor2Pin1, OUTPUT); pinMode(motor2Pin2, OUTPUT); // Configure PWM Pins ledcAttach(enable1Pin, freq, resolution); ledcAttach(enable2Pin, freq, resolution); // Initialize PWM with 0 duty cycle ledcWrite(enable1Pin, 0); ledcWrite(enable2Pin, 0); // Inicjalizacja OLED if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1306 allocation failed")); for (;;); } display.display(); delay(2000); display.clearDisplay(); display.setTextSize(1); display.setTextColor(SSD1306_WHITE); display.setCursor(0, 0); display.print("Connecting to WiFi..."); display.display(); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.println("Connecting to WiFi..."); } Serial.println("Connected to WiFi"); display.clearDisplay(); display.setCursor(0, 0); display.setTextSize(1,2); display.print("Connected"); display.setCursor(0, 20); display.print("IP Address: "); display.setCursor(0, 40); display.print(WiFi.localIP()); display.display(); // Define routes server.on("/", handleRoot); server.on("/forward", handleForward); server.on("/left", handleLeft); server.on("/stop", handleStop); server.on("/right", handleRight); server.on("/reverse", handleReverse); server.on("/speed", handleSpeed); // Start the server server.begin(); } void loop() { server.handleClient(); } Mój pojazd: Film z postępu prac: Edytowano Luty 7, 2025 przez Spidi-Andi Źle wstawiłem link do filmiku 6
orb777 Luty 9, 2025 Udostępnij Luty 9, 2025 Fajny i na esp32, będę zaglądał. Rzuciłem okiem na kod i zdaje się, że w takiej formie bez (opcjonalnego?) wyświetlacza dalej nie pójdzie. Dodałbym warunki pomijające użycie oled-a lub kompilację warunkową. Dnia 7.02.2025 o 17:55, Spidi-Andi napisał: if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1306 allocation failed")); for (;;); } 1
Spidi-Andi Luty 10, 2025 Autor tematu Udostępnij Luty 10, 2025 20 godzin temu, orb777 napisał: Fajny i na esp32, będę zaglądał. Rzuciłem okiem na kod i zdaje się, że w takiej formie bez (opcjonalnego?) wyświetlacza dalej nie pójdzie. Dodałbym warunki pomijające użycie oled-a lub kompilację warunkową. Dziękuję za radę. Ja początkujący w programowaniu. Uczę sie razem z ChatGpT. Ty zapewne programujesz sam. Tez bym tak chciał :). Ale kto nie dąży do celu ten nie osiągnie. Pozdrawiam
orb777 Luty 10, 2025 Udostępnij Luty 10, 2025 @Spidi-Andi , spoko luz, liczy się fun, pojaździk już masz. 1
Popularny post aimeiz Luty 15, 2025 Popularny post Udostępnij Luty 15, 2025 Fajny projekt. Ćwiczę podobny, ale w wersji trójkołowej. Wyświetlacz użyłem głównie do pokazywania która wersja kodu jest wgrana, czy połączył się z wifi i jaki ma adres IP. Jak się nie podłączy wyświetlacza to reszta kodu działa. Można użyć ESP-32CAM, będzie mógł na stronce wyświetlał obraz z kamery, tyle że brak jest wolnych portów w ESP32CAM jak działa kamera. Trzeba użyć ekspanderów. Zrobiłam na module STM32 Bluepill taki uniwersalny ekspander I2C: kilka PWM, Kilka GPIO In i out, pwm-y dla serwomechanizmów, ADC do monitorowania baterii. Pracuję nad dobraniem parametrów PID napędów,żeby się kółka równo obracały. Jak na razie równiej się kręcą bez regulatora PID :(. 3
Pomocna odpowiedź
Bądź aktywny - zaloguj się lub utwórz konto!
Tylko zarejestrowani użytkownicy mogą komentować zawartość tej strony
Utwórz konto w ~20 sekund!
Zarejestruj nowe konto, to proste!
Zarejestruj się »Zaloguj się
Posiadasz własne konto? Użyj go!
Zaloguj się »