Posted on

Robot 2WD Roboromania autonom ocolire obstacole

Robot 2WD Roboromania autonom ocolire obstacole

robot

Unul dintre cele mai simple coduri pentru Robot 2WD autonom cu ocolire obstacole.

Avem nevoie de :
o placă de dezvoltare tip Arduino UNO (oricare)
un modul driver motoare L298N
un senzor cu ultrasunete
șasiu cu 2 motoare 2WD
cabluri Dupont

robot-2wd-roboromania

Cel mai simplu cod :

//––––––––––––––

// Robot 2WD Roboromania autonom ocolire obstacole
// roboromania.ro     pentru ID Arduino.1.6.8 atentie sa aveti „libraries” – > „NewPing”

// ––––––––––––––-

// Robot 2WD Roboromania autonom ocolire obstacole – versiunea corectata (si testata) 2018.02.03
// roboromania.ro

#include <NewPing.h>

#define TRIG_PIN 8
#define ECHO_PIN 7
#define MAX_DISTANCE 400
#define COLL_DIST 20 // distanta de coliziune la care robot stop si inapoi este de : 20cm
NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE);

// L298n module
// 1(+)inainte dreapta = DrFr
// 2(+)inapoi dreapta = DrSp
// 3(+)inainte stanga = StFr
// 4(+)inapoi stanga = StSp

int DrFr = 3;
int DrSp = 2;
int StFr = 4;
int StSp = 5;

void setup() {
Serial.begin(9600);
pinMode(DrFr,OUTPUT);
pinMode(StFr,OUTPUT);
pinMode(DrSp,OUTPUT);
pinMode(StSp,OUTPUT);
digitalWrite(DrFr,LOW);
digitalWrite(StFr,LOW);
digitalWrite(DrSp,LOW);
digitalWrite(StSp,LOW);
}

int scan() {
return (sonar.ping() / US_ROUNDTRIP_CM); //masurare distanta in cm
}

void loop() {
int Dist = scan(); // masuram distanta curenta
// Serial.println(Dist);
if (( Dist > 0 ) || ( Dist < COLL_DIST )) { // daca distanta curenta < decit distanta de coliziune
moveStop();
moveBackward();
delay(500);
turnRight();
delay(300);
} else {
moveForward();
}
}

void moveStop() {
digitalWrite(DrFr,LOW);
digitalWrite(StFr,LOW);
digitalWrite(DrSp,LOW);
digitalWrite(StSp,LOW);
}

void moveForward() {
digitalWrite(DrFr,HIGH);
digitalWrite(StFr,HIGH);
digitalWrite(DrSp,LOW);
digitalWrite(StSp,LOW);
}

void moveBackward() {
digitalWrite(DrFr,LOW);
digitalWrite(StFr,LOW);
digitalWrite(DrSp,HIGH);
digitalWrite(StSp,HIGH);
}

void turnRight() {
digitalWrite(DrFr,LOW);
digitalWrite(StFr,HIGH);
digitalWrite(DrSp,HIGH);
digitalWrite(StSp,LOW);
}

void turnLeft() {
digitalWrite(DrFr,HIGH);
digitalWrite(StFr,LOW);
digitalWrite(DrSp,LOW);
digitalWrite(StSp,HIGH);
}

 

//––––––––––-

Atenție la declararea pinilor. Dacă copiați codul atenție la fonturi.

car-2wd-2019

Succes !

Creative Commons License
„Robot 2WD Roboromania autonom ocolire obstacole” de Popescu Viorel licențiat sub Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.

Posted on

How to Flash the ESP8266 ….

How to Flash the ESP8266 ….

ATENŢIE : Dacă distrugeţi modulul este pe propria dumneavoastră răspundere. Mai bine îl aduceţi la sediu şi îl schimbăm noi.

Conexiuni cu fire Dupont :

poza-pini-esp8266

Puteți să montați 2 întrerupătoare pe firul portocaliu (Flash) și pe firul rosu – CH_PD (Reset).

Se deschide ESP 8266 Flasher (esp8266_flasher.exe) şi Arduino 1.6.4 sau oricare

1

2

Tools –>Port : COMxx (Exemlpu : COM18)       După aflarea COM-ului se scrie în “esp8266_flasher.exe”

3

închidem Arduino 1.6.4

Se selectează “Bin”

“ESP_8266_v0.9.5.2 AT Firmware.bin” sau “ESP_8266_BIN0.92.bin”

5

–> Download (trebuie închis Arduino 1.6.4)

7

8

Până când va scrie: “Leaving… Failed to leave Flash mode”

E gata.

Închidem  “ESP 8266 Flasher” si verificăm ce am făcut !

Scoatem firul portocaliu de la GND

Reset ESP8266 (Scoatem şi băgăm firul roşu la pin CH_PD)

Deschidem “Arduino 1.6.4” sau oricare.

–> Tool –> Port : COM18

–> File: –> Preference:

10

URLs: “http://arduino.esp8266.com/stable/package_esp8266com_index.json“  –> OK

Board: –> Boards Manager –> Type: –> Contributed –> esp8266 by ESP8266 Community

INSTALL –> Close

lib2

Sketch –> Include Library –> Manage Libraries

Library Manager : căutare:  ESP8266

lib1

Alege : ESP8266 Built-In By Simon Peter,Markus…

INSTALL –> Close

Deschidem : Arduino

ino

CODE :

// –––––––––––––

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

IPAddress ip(192,168,1,100); // choose IP address
IPAddress subnet(255,255,255,0);

ESP8266WebServer server(80);

void handleRoot() {
String page = „<!DOCTYPE html>\n”;

page += „<html>\n<body>\n<h1>Multumim pentru Achizitie</h1><br>http://RoboRomania.ro\n</body></html>”;
server.send(200, „text/html”, page);
}

// what to do when accessed through http://ip_address/something_undefined
void handleNotFound(){
String message = „File not found\n\n”;
message += „URI: „;
message += server.uri();
message += „\nMethod: „;
message += (server.method() == HTTP_GET)?”GET”:”POST”;
message += „\nArguments: „;
message += server.args();
message += „\n”;
for (uint8_t i=0; i<server.args(); i++){
message += ” ” + server.argName(i) + „: ” + server.arg(i) + „\n”;
}
server.send(404, „text/plain”, message);
}

void setup(void){
Serial.begin(74880); // so you can see debug messages automatically sent by ESP8266
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(ip, ip, subnet); // declared as: bool softAPConfig (IPAddress local_ip, IPAddress gateway, IPAddress subnet)
WiFi.softAP(„RoboRomania-8266”, „roborobo”, 7); // network name, network password, wifi channel

IPAddress myIP = WiFi.softAPIP();
Serial.println();
Serial.print(„AP IP address: „);
Serial.println(myIP);

server.on(„/”, handleRoot); // what to do when accessed through browser using http://IP_address

// what to do when accessed through http://ip_address/test
server.on(„/test”, [](){
server.send(200, „text/plain”, „This is another page”);
});

server.onNotFound(handleNotFound);

server.begin();
Serial.println(„HTTP server started…”);
}

void loop(void){
server.handleClient();
}

// –––––––––––––––

–> Upload

Gata.  Verificăm dacă merge.

Reset ESP8266 (Scoatem şi băgăm firul roşu la pin CH_PD)

Căutăm rețea ….

12

Poţi să te conectezi.\

ATENŢIE : Dacă distrugeţi modulul este pe propria dumneavoastră răspundere. Mai bine îl aduceţi la sediu şi îl schimbăm noi.

Creative Commons License
„How to Flash the ESP8266” de Popescu Viorel licențiat sub Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.