<< return to Pixycam.com

Pixy2 Error: no response

When I use Arduino UNO to connect Pixy2, an error no response always appears after declaring pixy.init(). The object can be recognized in Pixymon, but the corresponding program cannot be executed in Arduino, please help me This problem. (Used the included cable, other connected components are L298N motor and ESP8266),This is how I connect, Pixy2 is connected on ICSP port

Hello,
Have you tried to unplug the other peripherals from the UNO to make sure there aren’t any conflicts?

Edward

I’ve tried running the Pixy2 program without removing other devices and it works fine, but once I add the program about the ESP8266 grabbing data, it doesn’t work

Hello,
Do you have the source code to the ESP8266 code? If so, you might try commenting out certain parts to narrow down the specific code that causes the issue.

Edward

I’m sorry, I’ve tried many times, but I still haven’t found what caused the error, so I have to post my code. Please help me find out the error. Thank you. Here is my code (some private information about ThingSpeak has been removed by me).

#include “SPI.h”
#include “WiFiEsp.h”
#include “ThingSpeak.h”
#include “SoftwareSerial.h”
#include “ArduinoJson.h”
#include “Wire.h”
#include “Pixy2.h”

//*-- IoT Information
char ssid[] = “”; // your network SSID (name)
char pass[] = “”; // your network password
WiFiEspClient client;
SoftwareSerial Serial1(4,3); // RX, TX

float deadZone = 0.15;
float dis; // 距離

// Channel details
unsigned long myChannelNumber = ; //your public channel number
const char * myReadAPIKey = “”; //read API
//the field you want to monitor
unsigned int FieldToMonitor1 = 1;
unsigned int FieldToMonitor2 = 2;
unsigned int FieldToMonitor3 = 3;
unsigned int FieldToMonitor4 = 4;
long count1,count2,count3,count4;
Pixy2 pixy;
//pixy2cam start work

//L298N
#define MotorA_I1 6 //定義 I1 接腳 (灰)
#define MotorA_I2 7 //定義 I2 接腳 (紫)
#define MotorB_I3 8 //定義 I3 接腳 (藍)
#define MotorB_I4 9 //定義 I4 接腳 (綠)
#define MotorA_PWNA 5 //定義 ENA (PWM調速) 接腳 (白)
#define MotorB_PWNB 10//定義 ENB (PWM調速) 接腳 (黃)

int cont = 0;
int signature, x, y, width, height;
float cx, cy, area;

void setup(void)
{
pinMode (MotorA_I1, OUTPUT);
pinMode (MotorA_I2, OUTPUT);
pinMode (MotorB_I3, OUTPUT);
pinMode (MotorB_I4, OUTPUT);
pinMode (MotorA_PWNA, OUTPUT);
pinMode (MotorB_PWNB, OUTPUT);

Serial.begin(115200);
pixy.init() ;
Serial1.begin(19200);
Serial.print(F(“ESP8266 is Ready!”));
WiFi.init(&Serial1);
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println(F(“ESP8266 not present”));
// don’t continue
while (true);
}
Serial.println(“found it!”);
ThingSpeak.begin(client); // Initialize ThingSpeak

}

void goahead(float b)
{
//直走
Serial.println(“Go ahead…”);
analogWrite(MotorA_PWNA,800); //設定直流馬達轉速
analogWrite(MotorB_PWNB,800); //B是右輪
digitalWrite(MotorA_I1,LOW); //直流馬達(A)逆時針轉動
digitalWrite(MotorA_I2,HIGH);
digitalWrite(MotorB_I3,LOW); //直流馬達(B)順時針轉動
digitalWrite(MotorB_I4,HIGH);
delay(b*1000/40);
}

void goback()
{
//後退
Serial.println(“Go back…”);
analogWrite(MotorA_PWNA,2000); //設定直流馬達轉速
analogWrite(MotorB_PWNB,2000);
digitalWrite(MotorA_I1,HIGH); //直流馬達(A)順時針轉動
digitalWrite(MotorA_I2,LOW);
digitalWrite(MotorB_I3,HIGH); //直流馬達(B)逆時針轉動
digitalWrite(MotorB_I4,LOW);
delay(2000);
}

void goleft(float c)
{
//左轉
Serial.println(“Go left…”);
analogWrite(MotorA_PWNA,0); //設定直流馬達轉速
analogWrite(MotorB_PWNB,450);
digitalWrite(MotorA_I1,HIGH); //直流馬達(A)順時針轉動
digitalWrite(MotorA_I2,LOW);
digitalWrite(MotorB_I3,LOW); //直流馬達(B)順時針轉動
digitalWrite(MotorB_I4,HIGH);
delay(c3.21000/360);
}

void goright(float d)
{
//右轉
Serial.println(“Go right…”);
analogWrite(MotorA_PWNA,450); //設定直流馬達轉速
analogWrite(MotorB_PWNB,0);
digitalWrite(MotorA_I1,LOW); //馬達(A)逆時針轉動
digitalWrite(MotorA_I2,HIGH);
digitalWrite(MotorB_I3,HIGH); //馬達(B)逆時針轉動
digitalWrite(MotorB_I4,LOW);
delay(d3.21000/360);
}

void gostop()
{
//停止
Serial.println(“Go stop…”);
analogWrite(MotorA_PWNA,0); //設定直流馬達轉速
analogWrite(MotorB_PWNB,0);
digitalWrite(MotorA_I1,HIGH); //馬達(A)停止轉動
digitalWrite(MotorA_I2,HIGH);
digitalWrite(MotorB_I3,HIGH); //馬達(B)停止轉動
digitalWrite(MotorB_I4,HIGH);
delay(5000);
}

void camahead(float b)
{
//直走
Serial.println(“Go ahead…”);
analogWrite(MotorA_PWNA,3000); //設定直流馬達轉速
analogWrite(MotorB_PWNB,3000); //B是右輪
digitalWrite(MotorA_I1,LOW); //直流馬達(A)逆時針轉動
digitalWrite(MotorA_I2,HIGH);
digitalWrite(MotorB_I3,LOW); //直流馬達(B)順時針轉動
digitalWrite(MotorB_I4,HIGH);
delay(b1000/22);
}
void camback()
{
//後退
Serial.println(“Go back(cam)…”);
analogWrite(MotorA_PWNA,200); //設定直流馬達轉速
analogWrite(MotorB_PWNB,200);
digitalWrite(MotorA_I1,HIGH); //直流馬達(A)順時針轉動
digitalWrite(MotorA_I2,LOW);
digitalWrite(MotorB_I3,HIGH); //直流馬達(B)逆時針轉動
digitalWrite(MotorB_I4,LOW);
delay(2000);
}
void camleft(float c)
{
//左轉
Serial.println(“Go left(cam)…”);
analogWrite(MotorA_PWNA,0); //設定直流馬達轉速
analogWrite(MotorB_PWNB,57);
digitalWrite(MotorA_I1,HIGH); //直流馬達(A)順時針轉動
digitalWrite(MotorA_I2,LOW);
digitalWrite(MotorB_I3,LOW); //直流馬達(B)順時針轉動
digitalWrite(MotorB_I4,HIGH);
delay(c
1.21000/360);
}
void camright(float d)
{
//右轉
Serial.println(“Go right(cam)…”);
analogWrite(MotorA_PWNA,57); //設定直流馬達轉速
analogWrite(MotorB_PWNB,0);
digitalWrite(MotorA_I1,LOW); //馬達(A)逆時針轉動
digitalWrite(MotorA_I2,HIGH);
digitalWrite(MotorB_I3,HIGH); //馬達(B)逆時針轉動
digitalWrite(MotorB_I4,LOW);
delay(d
1.2*1000/360);
}
void camstop()
{
//停止
Serial.println(“Go stop(cam)…”);
analogWrite(MotorA_PWNA,0); //設定直流馬達轉速
analogWrite(MotorB_PWNB,0);
digitalWrite(MotorA_I1,HIGH); //馬達(A)停止轉動
digitalWrite(MotorA_I2,HIGH);
digitalWrite(MotorB_I3,HIGH); //馬達(B)停止轉動
digitalWrite(MotorB_I4,HIGH);
delay(5000);
}

void loop()
{
camera();
}

float mapfloat(long x, long in_min, long in_max, long out_min, long out_max)
{
return (float)(x - in_min) * (out_max - out_min) / (float)(in_max - in_min) + out_min;
}
float pixyCheck()
{
static int i = 0;
int j;
uint16_t blocks;
char buf[32];
// grab blocks!
blocks = pixy.ccc.getBlocks();

// If there are detect blocks, print them!
if (blocks)
{
signature = pixy.ccc.blocks[0].m_signature;
height = pixy.ccc.blocks[0].m_height;
width = pixy.ccc.blocks[0].m_width;
x = pixy.ccc.blocks[0].m_x;
y = pixy.ccc.blocks[0].m_y;
cx = (x + (width / 2));
cy = (y + (height / 2));
cx = mapfloat(cx, 0, 320, -1, 1);
cy = mapfloat(cy, 0, 200, 1, -1);
area = width * height;
}
else
{
cont += 1;
if (cont == 100)
{
cont = 0;
cx = 0;
}
}
return cx;
}
void camera()
{
if (WiFi.status() != WL_CONNECTED)
{
Serial.print(F("Attempting to connect to SSID: "));
Serial.println(ssid);

WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
  Serial.print(".");
  delay(4000);
}
Serial.println(F("\nConnected"));

}
delay(4000);
// Check the status of the read operation to see if it was successful
int statusCode = 0;
statusCode = ThingSpeak.getLastReadStatus();
if (statusCode == 200) //read from channel
{
delay(1000);
count1 = ThingSpeak.readIntField(myChannelNumber, FieldToMonitor1, myReadAPIKey);
delay(1000);
count2 = ThingSpeak.readIntField(myChannelNumber, FieldToMonitor2, myReadAPIKey);
delay(1000);
count3 = ThingSpeak.readIntField(myChannelNumber, FieldToMonitor3, myReadAPIKey);
delay(1000);
count4 = ThingSpeak.readIntField(myChannelNumber, FieldToMonitor4, myReadAPIKey);
delay(1000);
Serial.println("Read: " + String(count1));
delay(1000);
Serial.println("Read: " + String(count2));
delay(1000);
Serial.println("Read: " + String(count3));
delay(1000);
Serial.println("Read: " + String(count4));

if(count2>0)
{
  goright(count2);
}
else
{
  float A=fabs(count2);
  goleft(A);
}
if(count1!=0&&count2!=0)
{
  dis=sqrt(sq(count1)+sq(count2));
  Serial.println(dis);
  if(dis>0)
  {
    goahead(dis);
    gostop();
    
  }
} 
pixy.init();

}
delay(4000);
// No need to read the counter too often.
pixy.init() ;
float turn = pixyCheck();

if (pixy.ccc.numBlocks)
{
if (turn > -deadZone && turn < deadZone)
{
turn = 0;
}
if (turn < 0)
{
camleft(1);
delay(1000);
}
else if (turn > 0)
{
camright(1);
delay(1000);
}
else
{
camahead(10);
camstop();
exit(0);
}

}
camright(1);
}

Sorry, I can’t find the problem. As I suggested, you might try commenting out certain sections of the code and see if that helps you determine which part of the code is causing the problem.

Edward