QR code reader with processing and arduino

hi i’m yoshua, i’m new in processing
my project is robot arm that can read 2 qr code (i.e : object A and object B) and send the data to arduino, so arduino will receive qr data, if arduino read object A then arm robot move to position A, and if arduino read object B then arm robot move to position B

i’m using qr code processing code from shiffman, my question is how the qr code data send to arduino ?

can anyone can help me please with the code ? i’m so stuck that i can’t find answers in google
thank you

I can’t help with code, but I think you should split your task into separate, individual problems:

  1. Read QR code with Processing;
  2. Convert your data to a format you can send to Adruino in Processing;
  3. Send data from Processing to Adruino;
  4. Have Adruino receive it and process it;
  5. Have Adruino move the robot arm.

Are you good with Adruinos? Can you make your Adruino move the arm by itself with code? What steps can you do right now?

I suggest you to solve each of these problems independently, and only then connect the solutions. And if you can’t, solve steps that you can independently of others, and then tell us which steps you are stuck on.

i have make arduino code to move arm by itself with string in arduino
i’m stuck in point 2, 3, and 4, i don’t know how to convert qr code data to something that arduino can read, any ideas ?

but is it possible right to take qr data on processing (i.e convert qr data to variable) ?

Processing is pretty much Java, so it must be possible.
I don’t know much about Adruinos, because I don’t have any, so I can’t help you in that part, but I think I can help you with the step 2 - then, you can find information on communicating between Processing and Adruino yourself - Google seems to return plenty of information on that topic.
In which format do you get the QR code data? Is it a String? An image?
Where can I find the processing code for QR you mentioned in your first message?

here you are http://makezine.com/2011/03/02/codebox-use-qr-codes-in-processing/

when i run the code, new window appear with what webcam capture, and when i put qr code, the data show up in yhat window

// IMPORT THE ZXING4PROCESSING LIBRARY AND DECLARE A ZXING4P OBJECT
import com.cage.zxing4p3.*;
ZXING4P zxing4p;

// PROCESSING VIDEO LIBRARY
import processing.video.*;
Capture video;

// PIMAGE WITH THE BARCODES TO DETECT
PImage scanArea;

// TEXT THAT WAS FOUND
String decodedText;
String latestDecodedText = “”;

// FORMAT OF THE LATEST FOUND BARCODE
String barcodeFormat = “”;

int txtWidth;

// FOR THE VIEW FINDER AND SCAN AREA
int frameWidth = 240;
int frameHeight = 260;
int lineSize = 40;

// CORNERS OF THE VIEW FINDER
PVector ul, ur, ll, lr;

// LIST WITH BARCODE TYPES TO LOOK FOR
ArrayList barcodeTypes = new ArrayList();

/*****************************************************************************
*

  • SETUP

*****************************************************************************/
void setup() {
size(640, 480);

// LAYOUT
textAlign(CENTER);
textSize(30);

// CREATE CAPTURE
video = new Capture(this, width, height);

// START CAPTURING
video.start();

// CREATE A NEW EN-/DECODER INSTANCE
zxing4p = new ZXING4P();

// DISPLAY VERSION INFORMATION
zxing4p.version();

// UPPER LEFT CORNER OF THE VIEW FINDER
ul = new PVector((width - frameWidth) >> 1, (height - frameHeight) >> 1);
// UPPER RIGHT CORNER OF THE VIEW FINDER
ur = new PVector(ul.x + frameWidth, ul.y);
// LOWER LEFT CORNER OF THE VIEW FINDER
ll = new PVector(ul.x, ul.y + frameHeight);
// LOWER RIGHT CORNER OF THE VIEW FINDER
lr = new PVector(ur.x, ur.y + frameHeight);

// AREA TO SCAN
scanArea = createImage(frameWidth, frameHeight, RGB);

// BARCODE TYPES THAT WILL BE SCANNED FOR
// SUPPORTED BARCODE TYPES:
// AZTEC
// CODABAR
// CODE_128
// CODE_39
// CODE_93
// DATA_MATRIX
// EAN_13
// EAN_8
// ITF
// MAXICODE
// PDF_417
// QR_CODE
// RSS_14
// RSS_EXPANDED
// UPC_A
// UPC_E
// UPC_EAN_EXTENSION
barcodeTypes.add(“EAN_8”);
barcodeTypes.add(“EAN_13”);
barcodeTypes.add(“DATA_MATRIX”);
barcodeTypes.add(“QR_CODE”);
} // setup()

/*****************************************************************************
*

  • DRAW

*****************************************************************************/
void draw() {
background(0);

// UPDATE CAPTURE
if (video.available()) video.read();

// DISPLAY VIDEO CAPTURE
set(0, 0, video);

if (frameCount % 50 == 0) {
// COPY THE VIEW FINDER AREA TO THE SCAN AREA
scanArea.copy(video, (int)ul.x, (int)ul.y, frameWidth, frameHeight, 0, 0, frameWidth, frameHeight);
}

// DISPLAY VIEW FINDER
pushStyle();
noFill();
strokeWeight(4);
stroke(255, 0, 0);
line(ul.x, ul.y, ul.x + lineSize, ul.y);
line(ul.x, ul.y, ul.x, ul.y + lineSize);
line(ur.x - lineSize, ur.y, ur.x, ur.y);
line(ur.x, ur.y, ur.x, ur.y + lineSize);
line(ll.x, ll.y, ll.x + lineSize, ll.y);
line(ll.x, ll.y - lineSize, ll.x, ll.y);
line(lr.x - lineSize, lr.y, lr.x, lr.y);
line(lr.x, lr.y - lineSize, lr.x, lr.y);
popStyle();

// DISPLAY LATEST DECODED TEXT AND FORMAT
if (!latestDecodedText.equals("")) {
pushStyle();
txtWidth = int(textWidth(latestDecodedText + " (" + barcodeFormat + “)”));
fill(0, 150);
rect((width>>1) - (txtWidth>>1) - 5, 15, txtWidth + 10, 36);
fill(255, 255, 0);
text(latestDecodedText + " (" + barcodeFormat + “)”, width>>1, 43);
popStyle();
} // if (!latestDecodedText.equals(""))

// TRY TO DETECT AND DECODE A QRCODE IN THE VIDEO CAPTURE
// multiFormatReader(PImage img, boolean tryHarder)
// multiFormatReader(PImage img, boolean tryHarder, ArrayList barcodeTypes)
// img: image to scan for barcodes
// tryHarder: false => fast detection (less accurate)
// true => best detection (little slower)
// barcodeTypes: barcode types to scan for
try {
// SCAN FOR ALL AVAILABLE BARCODE TYPES
//decodedText = zxing4p.barcodeReader(scanArea, false);

// SCAN FOR SPECIFIC BARCODE TYPES
decodedText   = zxing4p.barcodeReader(scanArea, false, barcodeTypes);

// GET THE TYPE OF THE LAST SCANNED BARCODE
barcodeFormat = zxing4p.getBarcodeFormat();

}
catch (Exception e) {
// NOT FOUND
decodedText = “”;
} // try

if (!decodedText.equals("")) {
// FOUND A BARCODE!
if (latestDecodedText.equals("") || (!latestDecodedText.equals(decodedText))) {
println(“Zxing4processing detected: " + decodedText + " (” + barcodeFormat + “)”);
}
latestDecodedText = decodedText;
} // if (!decodedText.equals(""))
} // draw()

/*****************************************************************************
*

  • KEYBOARD HANDLER

*****************************************************************************/
void keyPressed() {
switch(key) {
case ’ ':
// RESET
decodedText = “”;
latestDecodedText = “”;
break;
} // switch
} // keyPressed()

Quick suggestion, please use the little </> button in the text box when sending or editing a message to make it look like this and make code more readable.

Anyways, looking through the code, I see this:

if (!decodedText.equals("")) {
  // FOUND A BARCODE!
  if (latestDecodedText.equals("") || (!latestDecodedText.equals(decodedText))) {
    println(“Zxing4processing detected: " + decodedText + " (” + barcodeFormat + “)”);
    latestDecodedText = decodedText;
  } // if (!decodedText.equals(""))
} // draw()

From the obvious comment, I guess that this is where you can put an if statement and send a message to Adruino. Something like this:

if (!decodedText.equals("")) {
  // FOUND A BARCODE!
  if (latestDecodedText.equals("") || (!latestDecodedText.equals(decodedText))) {
    println(“Zxing4processing detected: " + decodedText + " (” + barcodeFormat + “)”);
    latestDecodedText = decodedText;
    if(latestDecodedText.equals("Your text for doing something")){
      tellAdruino("please do something");
    } else if(latestDecodedText.equals("Your other text for doing something else")){
      tellAdruino("please do something else");
    } else {
      //tellAdruino("I don't know what this text is but please do anything");
    }
  } // if (!decodedText.equals(""))
} // draw()

The tellAdruino(... function is not real. Replace the tellAdruino( function with whatever function that sends Adruino a message. I don’t know what it is.
Again, Google has plenty instructions on Processing and Adruino connections. I suggest you to make a completely separate sketch that sends some text to Adruino by clicking anywhere, to make sure you can even send anything to your Adruino, and then combine the code you get as a result with this, replacing the tellAdruino(.

Good luck!

thank you so much, i’ll give a try and if something happen i’ll replay again

hi i’m again, thank you fou your suggestion before, now my arduino can receive qr data and move the arm :smiley:
before, the qr code position is fixed to the camera (camera is attached to arm)
but now i’ve got another problem, can camera detect object that non fixed ? so i can randomly put the qr code in range of camera, so then camera can move closer to qr code and then read it ? thank you again

can someone help me ? :frowning:

Hi Yoshua, I’m interested with your project, and i’ve a project that need some methods like your project. what i want to ask is, how the arduino can connect to the camera? and what camera do you use?