How to Set Up Raspberry Pi 4 for Pixy2 API?
- So, you’re diving into the world of Raspberry Pi 4 with the Pixy2 API.
- First things first, you’ll want to get Raspbian OS up and running on your Pi and make sure SSH is set up for easy remote access.
- Next, it’s time to update your package list, so just run
sudo apt-get update
to get everything refreshed. - After that, you’ll need to install some essential packages by typing in
sudo apt-get install git libusb-1.0-0-dev g++ build-essential
, which lays down the groundwork. - Then, go ahead and clone the Pixy2 source code repository with
git clone https://github.com/CharmedLabs/pixy2
. - Finally, navigate over to the Pixy2 directory, head into the scripts folder, and run
build_usb_pixy_usb2.sh
to build the USB library you’ll need..
How do you build an example API?
- Building an example API can actually be pretty straightforward and feels a lot like your past Arduino projects, where different components come together to create a working system.
- For the lock SE demo, we set up a shell script, and to get things rolling, just head over to the build folder and run ‘sudo getBlocks.cpp demo’.
- Once that’s up and running, if you put a recognizable object in front, it’ll spit out information right in the terminal, similar to what you’ve seen in prior Arduino examples.
- When you’re done with the demo, don’t forget that you can find the source files in the SRC folder, with the built example chilling in the Pixy USB 2 examples folder.
- And if you’re feeling curious, take a peek into the CPP file in the getBlocks CPP demo for a deeper dive..
What’s the deal with the main function?
- So, let’s talk about the main function.
- It’s pretty nifty because it shuts down when you hit Control-C, and it lets you see messages using printf.
- If you’re familiar with Arduino, you’ll notice it has a similar vibe, especially with libraries like libpixyusb.h for connecting to Pixy.
- There’s also a variable called pixy2, which is set up as Pixy, along with a static variable that keeps an eye on how the program’s running.
- To check that status, there’s the handleSigInterrupt function, plus a run_flag variable that indicates when it’s time to stop the program..
What is the block retrieval process all about?
- Alright, let’s break down the block retrieval process! First up, there’s the ‘get blocks’ function that’s defined in the program and waits to be called later.
- Once you get Pixy up and running, keep an eye out—if you see a negative or zero result, you’ve hit an error, but a positive means all systems go.
- The program also retrieves and displays version info, and if it messes up here, it’s game over.
- Oh, and don’t forget about the ‘change probe’ command that sets up your program on PC2 for color-connected components.
- Finally, there’s this never-ending loop that continuously calls ‘get blocks’, making sure everything runs smoothly..
How do you connect PC2 to Raspberry Pi?
- So, when you hit ‘C’, that little run flag starts to pulse, which means the program is ending and you’ll see a message saying ‘PC to get blocks demo exit.’ Now, over in ‘Gap blocks,’ you can type ‘PC cccc get blocks’ to snag some info and follow it up with ‘PC ccccc do nblocks’ to check if any objects are being recognized.
- If there are objects, you’ll get a count displayed, and you can manage the output just like you would on the Arduino side.
- During this session, we got PC2 all hooked up to the Raspberry Pi and controlled it through the API, just like what we did with the Arduino before.
- And stick around because next time, I’m diving into how to control PC2 using UART, I2C, SPI, or other cool interfaces!.