<< return to Pixycam.com

Pixy connection with esp32 and blynk app

Hai, i have a Submarine robot project, i have a code to create an automatic control and manual control system. the hardware i used is pixycam2, esp32 doit devkit, l298n and 6v dc motor. and software i used to control its blynk app.

#define BLYNK_TEMPLATE_ID “TMPL67cLbSTQw”

#define BLYNK_TEMPLATE_NAME “Kapal Laoet”

#define BLYNK_AUTH_TOKEN “j-Q0NwIcSDBuvwZpp5oqllC6dtZ90xTv”

// Comment this out to disable prints and save space

#define BLYNK_PRINT Serial

#include <WiFi.h>

#include <Pixy2.h>

#include <WiFiClient.h>

#include <BlynkSimpleEsp32.h>

char auth[] = BLYNK_AUTH_TOKEN;

// Your WiFi credentials.

// Set password to “” for open networks.

char ssid[] = “EbemULTRA”;

char pass[] = “ITBGanteng2022”;

Pixy2 pixy;

int IN1 = 4;

int IN2 = 5;

int IN3 = 12;

int IN4 = 13;

// Variabel untuk mode (0: manual, 1: otomatis)

int mode = 0;

const int enA = 19;

BLYNK_WRITE(V0) {

mode = param.asInt();

}

BLYNK_WRITE(V1) { //depan turun

digitalWrite(IN2, param.asInt());

}

BLYNK_WRITE(V2) { //belakang turun

digitalWrite(IN4, param.asInt());

}

BLYNK_WRITE(V3) { //depan naik

digitalWrite(IN1, param.asInt());

}

BLYNK_WRITE(V4) { //belakang naik

digitalWrite(IN3, param.asInt());

}

void controlMotor(int y) {

if (y > 90 && y < 120) { // Objek di tengah, maju

//digitalWrite(IN1, HIGH);



//analogWrite(enA, 255);

} else if (y < 90) { // Objek di sebelah kiri, belok kanan

digitalWrite(IN1, HIGH);

digitalWrite(IN2, LOW);

digitalWrite(IN3, HIGH);

digitalWrite(IN4, LOW);

//analogWrite(enA, 255);

} else if (y > 120) { // Objek di sebelah kanan, belok kiri

digitalWrite(IN1, LOW);

digitalWrite(IN2, HIGH);

digitalWrite(IN3, LOW);

digitalWrite(IN4, HIGH);

// analogWrite(enA, 255);

} else {

// Objek tidak terdeteksi atau terlalu jauh, berhenti

digitalWrite(IN1, LOW);

digitalWrite(IN2, LOW);

digitalWrite(IN3, LOW);

digitalWrite(IN4, LOW);

}

}

void setup()

{

// Debug console

Serial.begin(115200);

pixy.init();

//pinMode(enA, OUTPUT);

pinMode(IN1, OUTPUT);

pinMode(IN2, OUTPUT);

pinMode(IN3, OUTPUT);

pinMode(IN4, OUTPUT);

//Blynk.begin(auth, ssid, pass);

// You can also specify server:

Blynk.begin(auth, ssid, pass, “blynk.cloud”, 8080);

//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

}

void loop() {

Blynk.run();

pixy.ccc.getBlocks();

if (pixy.ccc.numBlocks) {

for (int i = 0; i < pixy.ccc.numBlocks; i++) {

  int x = pixy.ccc.blocks[i].m_x;

  int y = pixy.ccc.blocks[i].m_y;

  if (mode == 1) { // Mode otomatis

    controlMotor(y); // Panggil fungsi untuk mengontrol motor

  }

}

}

}

pixycam2 and esp32 are connected with pin 1 (SPI MISO, UART Rx), pin 6 (GND), pin 4 (SPI MOSI), and pin 3 (SPI SCK) on pixycam2 to pin 23 (MOSI), pin 19 (MISO), pin 18 (SCK), and pin GND on esp32.

esp32 is connected to the l298n motor driver via pin 4, pin 5, pin 12 and pin 13. l298n connects to the dc motor.

i has successfully manual control the subs with blynk app, but when i changed it to auto mode it doesn’t works. i think the problem is pixycam2 and esp32 doesn’t communicate at all.
i need your help guys.

Hello,
We don’t have ESP32 support, so getting the ESP32 talking to Pixy may require some extra work/debugging. Have you seen this guide?

https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide

The section on the Serial Protocol is walks though how one might get communications working by starting simple

Edward

what microcontroller you can suggest to replace esp32?

and i already read that documentation, and still doesnt works

Hello,
What response did you get when sending the version query?

https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:porting_guide#the-serial-protocol

Edward