<< return to Pixycam.com

How to get Barcode label from Pixy2 with Arduino?

I want to trigger an event with my arduino code when Pixy2 detect a certain barcode and keep the event going for as long as the barcode is in sight.

if barcode 14 is detected then trigger event
while barcode 14 is being detected > loop

How do I do this?

My code:

#include <Pixy2.h>
Pixy2 pixy;
void setup()
{
Serial.begin(115200);
Serial.print(“Starting…\n”);
pixy.init();

  pixy.changeProg("line");

}
void loop()
{
int8_t i;
char buf[128];
pixy.line.getAllFeatures();
if (pixy.line.barcodes)
pixy.line.barcodes->print();
}

The serial monitor gives me: Barcode: (75 41), val: 14 flags: 2

It’s unbelievable that none of the pixy example code comes with a simple blink example, it’s all I need. Receive input from Pixy, let the LED on the Arduino blink if a certain object is recognized…

Hello,
If you want to get barcodes continuously, you should check out getAllFeatures(), which will return all features regardless of whether they’ve been detected before.

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

Hope this helps.

Edward