C.08 QR Code Prints

This is an extension of the previous post C.07 QR Code Generation, with the same aim to replace the input (key presses) with QR code detection through the webcam.

To begin with, I opened vendtest (the processing sketch that set up communication with the arduino) and copied the code over to the QR sketch I had created previously.

Screen Shot 2017-03-10 at 01.51.43

I edited the if statements copied over from keyPressed to use the decoded message in the condition. They didn’t work initially, and after some time scratching my head, it dawned on me that I may have made a similar mistake to the one I made last week (using = instead of  ==). A quick search on processing.org reveals that when comparing two strings, the function equals() should be used.

Screen Shot 2017-03-10 at 09.47.05

I replaced it as shown, almost forgetting to put my strings in inverted commas.

C.o6 Troubleshooting and Structure

Errors fixed

Untitled2

I took my code to get debugged by Spencer, and he identified my problems. Firstly, the condition inside the if statement (sensor = 1) needs to be (sensor ==1 ) since that indicates the difference between an assignment, telling the program that sensor now equals 1, and a comparison, asking the computer to check if sensor equals 1.

Secondly, the assignment of analogRead to the sensor variable needs to be repeated with each step, since new readings are being taken all of the time.

Thirdly, he noticed that i’ve been writing analogRead(A0); as this is what was used in the Arduino example. Instead, he recommended that i just write analogRead(0); since there is another use for A0 elsewhere in the program.

Now with the code fixed, the motor responds to the light sensor. When I hold my finger over the sensor, the motor turns in the opposite direction.

2017-03-08 18_19_02

The bigger structure

Processing must receive data from the QR code telling it which motor to activate, this data is then sent to the Arduino. Below is the code required to set up communication between the two programs

To assist, here is a diagram in plain english that shows a breakdown of the Arduino code (left) and how it interacts with the Processing code (right).

Bookscan

 

QR Codes

In the setup above, processing sends a value (1,2 or 3) to Arduino based on whether key 1, 2 or 3 is pressed. All that is left to do now is tack the QR code reader onto the end of this structure. Processing has a QR code reader library available, it was published by Daniel Shiffman. Here is a [link] to the library with some instructions on how to use to decoder.

The entire base sketch, including the decoder function, I obtained from [here].

[This] webpage also shows how to use ZXing to analyse QR Codes in realtime, should I need it.

A Minor Setback

I’ve had my time to sulk so now let’s continue as normal.

So after my blog got deleted and I lost the content from my Macbook too, I was reluctant to begin all over again. Yet after some time away I came to the decision that I needed a blog, especially to document my final year and the way my work is supposed to link between modules this year.

I also was really starting to miss my Things I Like series. I’ve had my time to sulk so now let’s continue as normal.

And to you, the genius who deleted everything. Nice try, but life is about more than just photos and documents.