How to Use the Pixy2 Library with Arduino?
- Alright, let’s get started with the Pixy2 library and Arduino! First off, make sure you’ve got the Arduino library installed on your PC from earlier sessions, and don’t forget to include the Pixy2 library so you can use it.
- You’ll be controlling it using an object called Pixy2, just type in ‘Pixy2’ followed by your chosen variable name.
- The main command you’ll use is ‘getBlocks,’ which pulls up all the info on the recognized objects.
- This information gets stored in an array, including how many objects were recognized.
- If that number is zero, you can skip to the next step because there’s nothing to see here! Each block comes with details like the ‘M’ signature which tells you the mode, plus recognized objects are indexed from zero up to nine.
- You’ll also have coordinates like ‘mX’ and ‘mY’ showing the central points of recognized objects, along with their width and height dimensions that range from 1 to 316 and 1 to 208, respectively..
What are Pixy CCC Blocks and Their Functions?
- Let’s dive into the Pixy CCC blocks! First up, we have the M underbar angle , which tells you how a recognized color code is oriented—even if it’s tilted or upside down.
- The ‘m’ index is pretty handy too; it shows the current index of the learned object along with how many frames it’s been detected.
- This info is crucial for figuring out how well the object’s been recognized.
- You can also find commands like ‘jump print’ that spit out information about the object.
- Plus, commands like ‘set servers’, ‘set brightness’, and ‘set led’ let you control servo motors, adjust brightness, and even change RGB LED colors.
- On top of that, there’s a super simple example program called CCC_hello_world that kicks off the Pixy2 library and sets up serial communication—it even shows ‘Starting’ on the serial monitor!.
How to Use PC Libraries for Object Recognition?
- In the loop function, we kick things off by declaring the PC_CCC_I variable.
- This nifty variable works with pcc.getBlocks() to grab all the info about recognized objects.
- If there are no blocks, it simply skips the for loop, but if we’ve got more than one object, it’s time to show off their indexes! The system does a great job of counting and displaying how many objects it sees with the PCC blocks.
- Oh, and if you’re working with a penitent servo motor kit, you’ll want to use the Pixy2 library along with an integrated P library to control that servo motor easily while keeping the PID loop setup nice and straightforward.
- We set the baud rate at 115200 with Serial.begin , then fire up the system with Pixy.init() and effortlessly switch modes using pixy.changePlug ..
What is Servo Motor Control About?
- So, let’s dive into how servo motor control works! First off, the code kicks things off by setting up some key variables, including a 64-byte buffer and offsets for pan and tilt—these are super important for managing our servo.
- Once it grabs data using the command pc.cccc.dogetBlocks, the program checks for any objects it can recognize.
- If there’s nothing, it simply skips the rest of the processing—a time-saver for sure! But if it finds objects, it sets up the PID settings and gradually tweaks the variable ‘I’ based on certain conditions related to 60 units.
- To figure out how the motor should move, it calculates direction using the frame dimensions and coordinates of those recognized objects—this helps it adjust the servo accurately.
- And in the end, with all configurations set, the PID calculations come into play, allowing for super precise control over that servo motor..
How can we use Pixy2 with Arduino and Raspberry Pi?
- Let’s talk about using Pixy2! First off, when we say set service , we’re getting into using ef0 and ndf.
- These are macro functions that, by default, don’t show any output.
- But if you switch ef0 to one, you’ll actually be able to see how those calculations go down and how the values are figured out.
- Plus, you can totally control the Pixy tool with the Arduino API, which is what we covered today.
- Stay tuned for our next video where we’ll dive into the Raspberry Pi API for Pixy2!.