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.07 QR Code Generation

Today, I did some experiments with QR codes to extend upon the structure I already had which sent 1’s 2’s and 3’s from processing to Arduino depending on key presses.

Goal: To replace the input (key presses) with QR code detection through the webcam.

One thing I know about this process is that the QR code detector will return the key code for the letter 1 rather than a number value 1. So this needs to be rectified.

Process

Using the QR code generator that was recommended by the links in C.06 Troubleshooting and Structure and saved them as usable qr codes like so:

Before printing and testing the qrcodes on the webcam, I decided to upload them in processing to make sure they could be decoded properly (see line 72). This threw out an error ‘No QR code image found’. I tested this against a file path that was deliberately wrong and that threw a different error, so there must be something wrong with the QR code image.

Screen Shot 2017-03-09 at 22.16.09

I suspected that this was because I tried to use the phone number section of the qr code generator and only used one digit. Running the jpeg through an online QR code decoder, produce the correct result however.

Screen Shot 2017-03-09 at 22.24.16

My options from here on are: a) To try again with text instead of a number, b) To find a site that will let me download the jpg for free c) use preexisting QR codes with an if statement that uses that data as a condition for returning 1’s 2’s and 3’s.

A. Try again using a text string

Screen Shot 2017-03-09 at 22.35.05

I repeated the process with the text string, 1 2 and 3. This time skipping the step where I sharpen the image on photoshop (to save time) and exporting them as png files (to match the example).

Again the same error came up.

Screen Shot 2017-03-09 at 22.51.47

 

c) Use pre-existing QR codes

Just to see if the decoder works with other qr codes, I have downloaded one from the internet. Running it through the online decoder reveals that is contains the string ‘12345678’.

Screen Shot 2017-03-09 at 23.00.35

Interestingly, this gives a different kind of error, I thought maybe the image itself was too large. The sample image was 216 x 216 pixels so I resized the tester qr code.

Screen Shot 2017-03-09 at 23.08.08

This worked and the string was returned. When I tested it out on the original 1,2 and 3 (digit, not string) QR codes, it also worked! However the data returned was TEL:3 rather than just 3. So I will use the 1,2 and 3 (string) QR codes instead.

Screen Shot 2017-03-09 at 23.18.24

I don’t think this would have been much of a problem when printed out but I am glad I was able to fix this issue, regardless.

Screen Shot 2017-03-09 at 23.30.17

 

D.03 Token Design (Further)

Action: Sketches and experiments to establish how the tokens will be used

In response to feedback received in Token Design.

Two Sided Disks (Thaumatrope)


Pictured above are spinning disks by Joel Henriques, I want my tokens to have a similar effect as mentioned in the previous post. Today I began planning how the token would be suspended in the middle of the card.

[]

Using the 45 mm as a ballpark figure on diameter, I discovered that the edges would be very thin if placed inside a regular business card.

http://technabob.com/blog/2011/11/21/analog-animated-gif-player-old-school-gets-even-older/

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.

C.05 Light Sensor

Goal: To incorporate the light sensor into the circuit so that the motor turns one way when the light is detected and another way when no light is detected.

Wiring

I wired the light sensor to the Analog port using this diagram to help me. One side of the LED connects to live and the other side connects, to analogue but through a resistor that is grounded.

fritzing1

This is the main loop of code. It makes use of two functions fwd() and rev() that I wrote in an earlier session. The variable ‘sensor’ takes a reading from the analog port.

Untitled

The last line of this loop prints the value of sensor to the serial monitor, I added this in because I wanted to see the values that shining a torch on the light sensor would throw out. What I found here was unusual…

Untitled2

The serial monitor displayed lines of 1’s regardless of whether I exposed the light sensor to any light and, as a result the motor only rotated forward.

motormoving

I looked online for other examples of serial monitor prints from light sensor. They were returning numbers up to 3 digits long, often in the 700 – 900 range. Something is going wrong somewhere.

screen-shot-2017-02-24-at-11-39-10

C.04 Motor Wiring Guesswork

Goal: To make the stepper motor rotate by sending pings from the Arduino in the correct order.

The process shown in the video below is as follows

  1. I firstly set out to find documentation online that would tell me the order required to wire up the magnets inside the stepper motor
  2. Failing to find the right order, I elected to wire them randomly and guess the order through trial and error. This was safe since I already knew to ground the white and black wires.
  3. I did not have any stiff wires so I had to twist the loose ends, stick them into the Arduino ports and hope for the best.
  4. I wrote the code according to the instructions I had received.
  5. The first attempt to upload to the board failed because it was connected to the wrong port.
  6. Finally, when I did upload the code to the board, nothing happened…

Afterthoughts

I know that this is either an error with the code or the connection because even with the wires in the wrong order, the motor should still jolt and jump around. Its possible the code is wrong but I believe it to be the way the wires connect to the ports. I will need some stiffer connecting wires to wrap these ones around.


Corrections

Later in the day I asked Spencer for more wires and got given a handful of them, along with a bread board, a resistor and a light sensor.

screen-shot-2017-02-24-at-11-50-19

I was then assigned a new task to make the motor turn according to the presence of light detected by the sensor.

I was also introduced to this thing:

img_2933

Which can be used as a switch when I later introduce more motors and a higher power supply.

C.03 Components and Enabled Theft

Today wanted to start designing a net for the casing of my vending machine, however I soon realised that it was more logical to start with the core system and then build the casing around it.


To Print or Not to Print…

Printing the result is actually not a necessary step in this system. I may just relay the data from processing straight to the vending machine. Now that I have discovered that the medals are costly to produce I need to consider the best way to arrange this system.

Reasons Not to Print
– Relaying the data straight to the vending machine will stop people vending more than one medal each, this will help prevent waste.
– The system is more automatic (and impressive?) and doesn’t rely on the user

Reasons To Print
– Its more fun and adds an element of interactivity
– The print out becomes the end goal and the medal is an add-on. That way, if I do run out of medals, the user still gets an outcome. (I should print a personal analysis as well as a QR code for the medal)

Verdict: Continue with plans to print, but move the output of the personal analysis from on-screen to paper output.


Printers

I started by looking for projects similar to my own, to give me an idea as to what components would be necessary. There were plenty of Arduino printer projects online, some were build from scratch, others utilised small Arduino compatible printers.

I won’t be building a printer from scratch, so I will probably be best off with a small thermal printer. These are the types of printers found in cash registers and pin machines and work by exposing heat to rolls of thermal paper, meaning that they don’t require any ink. Thermal printers are very common, cost effective and can come in small sizes, which fits my vision for this system. After some time, the print will wear off the paper. In my experience, receipts I have kept seem to fade after a few months. This life span far exceeds what I need for this project as the print out is only useful until the medal has been dispensed. The medal itself is what the user will bring home and this has a much longer lifespan.

Pipsta is a beautiful thermal printer that is Arduino and Raspberry Pi compatible. But it is over £80 and I know for a fact that there are morse affordable (and uglier) printers on the market.

pipsta_3

I also know that my printer doesn’t necessarily need to be Arduino compatible. It just needs to work with AppleScript. So my course of action will be to buy a more affordable printer, make it work, then make it pretty.


Motors

Earlier, Spencer suggested I look for a 5V or 9V motor. I found a few online, but I don’t know whether I will need to buy a slow (30 rpm) motor or slow down an normal one. To narrow down my search, I looked for projects similar to mine, and found the following.

  1. There are ‘arduino compatible’ motors available (here) although i’m sure a regular motor can be used with an arduino… so maybe it is just set up differently.
  2. I learned that most motors can run off the voltage supplied by an arduino, but this is lower than the usual voltage supply so the motor will run with less power (not sure if slower, or with less torque or both…)
  3. A motor can be powered externally from a cell and switched on and off by an arduino

screen-shot-2017-02-16-at-10-50-43

Before setting off to buy the Arduino compatible motors, I talked to Jay to see if i could scrounge one off someone in the university to practice with. He let me steal one from Spencer’s desk, which will do for now.

Untitled


Arduino

Later in the day, I visited Spencer with my new stepper motor, and he ran me through the basics of how they work. Essentially it is comprised of four corner magnets which need to be switched on and off in the right order to spin the magnetised core. This is ideal for my project as I can completely control the speed rotation of the motor.

FullSizeRender
My notes

I was then assigned the task to go away and try to make the stepper motor work using the information I had learned today.

img_2924
Thursday’s haul of free stuff