-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdot212-pixy2-SPI.ino
121 lines (73 loc) · 3.38 KB
/
dot212-pixy2-SPI.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
// b-pixy2-SPI.ino
-------------------------------------------------------------------------
Best to use the Portenta Pro Community solutions arduino library
and load the menu accessoies--> sensors --> dot212-pixy2-SPI sketch.
The above has all of the several include files needed by the Pixy2 camera
---------------------------------------------------------------------------
Pixy library easy install zipped file at
https://github.com/charmedlabs/pixy2/raw/master/releases/arduino/arduino_pixy2-1.0.3.zip
weird extra where you have to delete the last 4 zumo files in he library
checkout the last part of these installation documents
https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:hooking_up_pixy_to_a_microcontroller_-28like_an_arduino-29
Read about it here
https://pixycam.com/pixy2
// By Jeremy Ellis
// MIT License
// SPI pins on the photon
// See connection images on github at
// https://github.com/hpssjellis/particle.io-photon-high-school-robotics/tree/master/a15-serial-SPI
// VIN = Portenta +3V3
// GND = Portenta GND
// MISO = Portenta D10 (PC_2) different on XIAO D9
// SCK = Portenta D9 (PI_1) different on XIAO D8
// MOSI = Portenta D8 (PC_3) different on XIAO D10
// 6 prong cable using the red wire at top to the left
// 3V3, D10
// D8, D9
// GND, NC (not connected)
if using platform.io you need this library in the platformio.ini file
lib_deps = arduino12/pixy2@^1.0.4
*/
#include <Arduino.h> // Only needed by https://platformio.org/
int wow = 2; // just seems to need an integer
#include "Pixy2.h"
#include "TPixy2.h"
Pixy2 pixy; // Create our pixy object
// Setup - Runs Once @ Startup
void setup() {
Serial.begin(115200);
pixy.init(); // Initalize the pixy object
}
// Loop - Runs over and over
void loop(){
// uint16_t blocks; // Create an unsigned int to hold the number of found blocks
char buf[50]; // Create a buffer for printing over serial
int myPixyInt;
pixy.ccc.getBlocks(); // Do the pixy stuff. Grab the numbers of blocks the pixy finds
// If we have some blocks increment the frame counter (i) and if enough frames have passed print out data about the found blocks to the serial port
if (pixy.ccc.numBlocks) {
myPixyInt = pixy.ccc.blocks[0].m_x; // x location of the main object 0 - 320
// myPixyInt = pixy.blocks[0].y;
// myPixyInt = pixy.blocks[0].width;
// myPixyInt = pixy.blocks[0].height;
if (myPixyInt <= 10) { //object really far left
Serial.println("Pixy Object far left");
}
if (myPixyInt > 10 && myPixyInt <= 100) { // Object on the far left, blink really fast
Serial.println("Pixy Object on left");
}
if (myPixyInt > 100 && myPixyInt <= 200) { // Object on near middle, blink slow
Serial.println("Pixy Object In the middle");
}
if (myPixyInt > 200 && myPixyInt <= 300) { // Object on Right, blink really slow
Serial.println("Pixy Object on Right");
}
if (myPixyInt > 300 ) { // Object on far right, leave LED on
Serial.println("Pixy Object Far Right");
}
} else { // no blocks seen by camera
Serial.println("Pixy No Object");
}
delay(1000); // just for the heck of it slow things down a bit
}