Need help for an Arduino project

Bluetooth or WiFi come to mind as easy solutions.

If you go for WiFi look into the WeMOS and NodeMCU boards (based on the ESP8266 processor with built-in WiFi).

sungjung:
Hi !
In fact, we changed our minds. Apparently, the Arduino is very bad to recognize images, so what we will do is to analyse the QR codes with a mobile app and then send the information to the Arduino card. It will be much more easier for us ! Now we just have to search how to send the information to the Arduino...

Anyway, thanks a lot for all your precise and great anwsers, much appreciated !

It would have been an interesting project and you would have learned a lot doing it. I did think it might have been a bit of a challenge though depending on what your skills and timescales are.

So, we changed our minds AGAIN because you said some good arguments :slight_smile: The code looks very hard but not impossible. Let's try this !

It is not a particularly easy project, but it should be possible if you can make the image recognition as simple as possible.
As well as saying you will use Version 1 codes it would be a good idea to further restrict things by specifying the data type and the mask.

It would help you gave some background about yourselves;

  1. how many of you are there?
  2. How many PCs/laptops do you have access to?
  3. What relevant skills do you have; programming, knowledge of image file formats, English (there is a French section on this website)?
  4. Is this an assignment and, if so, what is the deadline for completion?
  5. Can you set the objectives of the project so that you set targets that you can achieve e.g. the type of QR codes you will read, their orientation, how they will be photographed?

In post #12 I included a QR code as a boolean array in some C++ code. On a PC try to add your own code to decode the array (I may have made errors in initialising the array so check it matches the image). If you think you can tackle that then you can probably manage the other two aspects of the project - a lot depends on timescales.

P.S. although I put the QR code in a boolean array to make it obvious it was a 21 x 21 array of binary values it is possible it might be easier to manipulate in another data type

As i though storing the QR code in a bool array is probably not going to be the easiest way to process it. This is because the booleans, although binary values, are actually going to be stored in 8 bits.

Try this code on an Arduino (I don't have one to hand);
Code: [Select]

    Serial.println(sizeof(bool));
    Serial.println(sizeof(boolean));
    Serial.println(sizeof(unsigned char));
    Serial.println(sizeof(unsigned int));
    Serial.println(sizeof(unsigned long));

I expect the output to be 1, 1, 1, 2, 4.
Since your QR codes are going to be 21 bit wide it might be best to store them in in an array of 21 longs i.e. 32 bits x 21.
That should make masking quicker and easier.

Here is the same QR code as before but stored in an unsigned long array. This saves memory, since the bool actually uses a byte. However it will also make masking and extracting groups of bits easier. Try to add code to decode the QR code. I suggest this is done on a PC as you will develop the code much faster, then port it onto an Arduino.

#include <iostream>

using namespace std;

int main()
{
    unsigned int line,bit;// instead of unsigned int use unsinged long on the Arduino (32 bits)
    
    /*
        The bits of a QR code could be stored in the array elements in various way.
        I decided to store them in the high order bits of elements because I felt it
        made converting the hex numbers into a QR image by hand easier
    */
    
    unsigned int qr[21]=
    {
        0xFEBBF800,
        0x82320800,
        0xBAD2E800,
        0xBACAE800,
        0xBA92E800,
        0x827A0800,
        0xFEABF800,
        0x00180000,
        0xF2FCE800,
        0xA9FFE800,
        0x26951800,
        0x3C915000,
        0xF3AE0800,
        0x00F32800,
        0xFE3F8000,
        0x82457800,
        0xBA286000,
        0xBA827000,
        0xBAC92000,
        0x82D78800,
        0xFEB72000
    }; // Each element stores a 21 bit row of the QR code in its highest order bits i.e. lowest 11 bits of the 32 bit elements are zero
    
    for(int irow=0;irow<21;++irow)// process each row in the QR code
    {
        line=qr[irow];// copy the row
        for(int icol=0;icol<21;++icol)// process each bit in the QR code row
        {
            bit=line&0x80000000;// get the highest order bit
            line=line<<1;// shift all the bits left by one
            
            // Display 'X' if the highest order bit was 1 and O if it was 0
            if(bit!=0)
            {
                printf("X");
            }
            else
            {
                printf("O");
            }
        }
        printf("\n");
   }
   return 0;
}

Output;

[b]$g++ -o main *.cpp[/b]
[b]$main[/b]
XXXXXXXOXOXXXOXXXXXXX
XOOOOOXOOOXXOOXOOOOOX
XOXXXOXOXXOXOOXOXXXOX
XOXXXOXOXXOOXOXOXXXOX
XOXXXOXOXOOXOOXOXXXOX
XOOOOOXOOXXXXOXOOOOOX
XXXXXXXOXOXOXOXXXXXXX
OOOOOOOOOOOXXOOOOOOOO
XXXXOOXOXXXXXXOOXXXOX
XOXOXOOXXXXXXXXXXXXOX
OOXOOXXOXOOXOXOXOOOXX
OOXXXXOOXOOXOOOXOXOXO
XXXXOOXXXOXOXXXOOOOOX
OOOOOOOOXXXXOOXXOOXOX
XXXXXXXOOOXXXXXXXOOOO
XOOOOOXOOXOOOXOXOXXXX
XOXXXOXOOOXOXOOOOXXOO
XOXXXOXOXOOOOOXOOXXXO
XOXXXOXOXXOOXOOXOOXOO
XOOOOOXOXXOXOXXXXOOOX
XXXXXXXOXOXXOXXXOOXOO

Have you had any success in capturing imaged to SD using the OV7670 ?
It has 640 x 480 resolution and supports RAW RGB which may be the way to go.

Hi, just a question :
in our project, the QR codes are useful because they allow us to associate each book with a subject. There's 6 books and 6 QR codes, so we think that we could put the 6 QR codes in the Arduino, and with the camera, compare the "basic" QR codes with the recognized QR codes. We think it would be easier to translate a QR code from nothing. How we should code this ?

Thanks again for everything you did for us, much appreciated !

Is there a specific need in the target application for QR codes?
Sure they bring flexibility and additional symbol complexity, but your project may run a lot faster, easier and simpler with simple 2D barcodes...?
And it will easily fit in a small Arduino.

sungjung:
Hi, just a question :
in our project, the QR codes are useful because they allow us to associate each book with a subject. There's 6 books and 6 QR codes, so we think that we could put the 6 QR codes in the Arduino, and with the camera, compare the "basic" QR codes with the recognized QR codes. We think it would be easier to translate a QR code from nothing. How we should code this ?

Thanks again for everything you did for us, much appreciated !

Six QR codes could be easily stored in memory in an array, just as I did with my example code in post #20.
It would then be possible to take a photograph of a QR code and compare it against the stored codes to find a match. You would need to convert the image into an array but you would not need to actually decode the QR code.

However that is a very crude way of doing things and is not scaleable. It will work for six books but not for six thousand (too slow, too much memory needed). It also means you need to know in advance every QR code that you might photograph, which seems an unrealistic situation.

Consider a library. The books will all have International Standard Book Numbers (ISBN). They will also have a classification number such as Dewey Decimal Classification (DDC). These numbers could be held in QR codes. There will be thousands of books though with new books arriving all the time. In that situation you really need to be able to read the codes.

Why don't you post images of the six QR codes you have, then have a go at writing a sketch to decode them. In this situation you really just need to get your head down and work at it. Take it a bit at a time. Write a function that reads the QR code version and when that works add a function to read the QR code mask used and so on.

I think post #22 was the first time you mentioned books and you have not answered earlier questions.
You will need to check that a Version1 QR code can store sufficient information for your application.

Thanks again for your reply, sorry if we came to you as ungrateful.
The thing is that it's the first time we work with Arduino, and we have limited knowledge about this stuff, so your explications, while useful, are still pretty complex for us. We understand what the process should be, but it's when we have to write the code that we have some problems.

sungjung:
Thanks again for your reply, sorry if we came to you as ungrateful.
The thing is that it's the first time we work with Arduino, and we have limited knowledge about this stuff, so your explications, while useful, are still pretty complex for us. We understand what the process should be, but it's when we have to write the code that we have some problems.

That is why questions were asked about how many of you there are and what your knowledge and experience is, so that answers and suggestions given were appropriate to you.

You described yourselves as "young electronics students", does that mean you are University students or School students?
Since you are studying electronics you must already know about logical bit operations such as AND, OR and XOR is that correct?

Do you have a deadline for this project?
Have you attempted to write any code ?

Copy the program given in reply #20
Go to the website;
https://www.tutorialspoint.com/compile_cpp_online.php
Execute the code

Do you understand the program and what it is doing, if not ask questions.
Then modify the program by adding a function to extract the QR code version number and display it.

If you get stuck post your code and ask questions.
People will get help if you make an effort yourself.

To answer your questions :

  • We are students in High School
  • Yes, we know those logical operations
  • The deadline is in early May, but there's not only the programming, there's a lot of things to do
  • Yes we wrote other codes to control a LCD screen, motor drivers, buzzers, etc...

So we will test your code and see how it will work. Thank you !

sungjung:
Hi !
In fact, we changed our minds. Apparently, the Arduino is very bad to recognize images, so what we will do is to analyse the QR codes with a mobile app and then send the information to the Arduino card. It will be much more easier for us ! Now we just have to search how to send the information to the Arduino...

Anyway, thanks a lot for all your precise and great anwsers, much appreciated !

Although you said "young" because you said "electronics students" I thought you might be at University.
Since you know about logic operations and have done some programming this should still be possible.
Your first post was in Jan though so you have wasted 4 weeks, unless other things have been happening.

How many of you are there?

Have you managed to take a photograph of a QR code with the Arduino meeting the restrictions in reply #10 ?

Presumably you know how to convert between binary and hexadecimal?
Each hexadecimal character respresents exactly 4 bits, as per the list below.

0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
A 1010
B 1011
C 1100
D 1101
E 1110
F 1111

From that I guess you can see how the first line of the QR code was represented in hexadecimal?

F E B B F 8 0 0
XXXX XXXO XOXX XOXX XXXX X000 0000 0000

Here are some questions you should try to answer;

What are the advantages and disadvantages of storing a version 1 QR code in arrays of each of these variable types

  • bool
  • unsigned char
  • unsigned long (32 bit)

Yes, we know how to convert binary to hexadecimal.

For us, the bool variably type is the best one, the others being unnecessary complicated for the task we have to complete.

We gonna try to take some pictures but we have to make the cabling first.

sungjung:
For us, the bool variably type is the best one, the others being unnecessary complicated for the task we have to complete.

Even being unable to figure out what you really want, I can tell you that this is 99.999% certainly a VERY bad decision.

21x21 bit QR code in bools = 441 bytes of storage. 6 of them = 2646 bytes
That's a lot of memory out of your 8096 total bytes available! Plus the complications of dealing with such 2D arrays.

The long solution: 21x4 = 84 bytes per code, or 504 bytes for six of them. Very easy to work with, as it's a 1D array and a single variable per row.

Using three separate bytes for each row (of course that's a 2D array again) could bring down the storage requirements to just 63 bytes per code, or 378 bytes total.

sungjung:
....
We gonna try to take some pictures but we have to make the cabling first.

I agree with @wvmarle's last post.
You need to think about the questions asked in post #30.

Initially I used bool so that you would be able to 'see' the the QR code within the initialised array.
To actually solve this problem I would use 32 bit variables, but it is not just about the amount of storage it is also about how you can process the variables.

You first posted about this in Jan with a deadline of May. It is now Mar and you have not taken pictures yet. Really I have to advise that as this rate you will not complete this project.

There are three main tasks;

  1. Take the pictures in a standard reproducable way - trivial
  2. Convert the picture into an array - moderate
  3. Decode the array to 'read' the QR code - moderate/difficult

Have you actually investigated picture file formats and how you would read them to produce an array containing the QR code?

Do you understand how data is encoded in a QR code and how you would extract the data from it?

Extracting data from a QR code involves a lot of bit manipulation. It should not be that difficult but it could take you a while to understand the documentation. The fact that you are considering using bools makes me believe you have not thought about how you would program the task.

You really need to get a move on if you hope to do this by May and it will involve hard work.