Need help for an Arduino project

Hi everyone !
We are young students making an electronic project, but we have very basic skills in Arduino programming.
We bought a OV7670 Camera module, and we want it to read QR code and send an information to the Arduino MEGA.

Any ideas is welcome !
Thanks in advance,
cheers.

PS : We are French, so sorry if there's mistakes.

Did u look on the internet ?
I'm sure there are plenty of arduino programs on the web

I hope u'll find ur progrm.

cheers

Thank you for the reply.
Yes, we searched, we found some programs, but they're often too complex and doens't have the same goals as ours.

Bonjour,

Have you managed to take pictures with the camera?
Are you storing them onto an SD card in the Arduino?
Did the camera come with any kind of library that recognises QR codes?

Thanks for replying.
To answer your questions : no, no and no. : :confused:

sungjung:
Thanks for replying.
To answer your questions : no, no and no. : :confused:

Ah :slight_smile:

Okay. I would start by saying that the Arduino is not ideal for processing images, and I also have not used the camera myself.

How are you going to photograph the QR codes. Are you just going to hold the camera in your hand and will there be other things in the picture as well as the QR code? Also what resolution of QR code will you be photographing (the lower the resolution the better)?

Your first step is going to have to be to connect the camera to the Arduino.
Then you are going to have to take a picture and save it, do you have an SD card?
Then you are going to have to process the image to read the QR code.

We connected the camera to the Arduino, maybe we should bring a SD, you're right :wink:

Very interesting idea u've just came out with.

I'll just suggest printing big and swole QR codes so that the camera can read them

ardly is right, u need to use a SD card to save the pictures, but u can erase them when u're done

Cheers

Arduinos are generally not suitable for image recognition. You only have 2 kB of RAM to work with so that's very small images at best.

A quick Google search returned several projects that combine an arduino with a phone and Android app, where the phone app reads the QR code, then sends the decoded data to the Arduino. I didn't see any QR decoding libraries for Arduinos.

You may be able to find QR scanners that work like traditional bar code scanners. Those are more likely compatible with Arduino, as they would output the decoded string rather than produce the image.

If you really want to do your own QR code decoding, look into the RPi or similar devices instead. They do have the horsepower and memory to do image processing.

sungjung:
We connected the camera to the Arduino, maybe we should bring a SD, you're right :wink:

You do need an SD card because of the Arduino memory limitations. This project is interesting and, if you can set some limits on the goals, practical. First though some information about you;

  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?

QR codes were developed for use on assembly lines. To ensure a successful project I would assume that my camera was mounted on an assembly line and I would have these limitations on the scope;

  1. The system will correctly decode 98% of QR code images.
  2. The QR codes will all be Version 1 (21 x 21)
  3. The QR codes will all have the same orientation
  4. The sides of the QR code will be parallel with the sides of the image
  5. The QR code will be completely within the image
  6. The QR code will be as large as possible within the image
  7. The image will be in Black & White i.e. Grayscale (if possible)
  8. The image will be at the most suitable resolution (probably the lowest resolution the camera can take)
  9. The image will be in the simplest format possible (monochrome BMP ?)
  10. The lighting will be good and the same for all images

The above limits on the project scope result in something achievable that can be done on an Arduino.
Without such limits the project could involve complex rules, maths, geometery, and even AI and neural nets and be well beyond what an Arduino can do.

This project breaks down into three sequential parts;

  1. Capture good quality images of QR codes into files on SD
  2. Read the SD file and generate the QR code in a small array in memory
  3. Extract the data from the QR code in the array

These three steps are independent and can be programmed simultaneously.
Steps 2 & 3 can be done fastest by programming them in C++ on a PC and then integrating the code on an Arduino later.

Below are a gif of a QR code what does it say?
Also below is a 21 x 21 array which (unless I have made an error) should contain the same QR code.

The outcome of step 2 in my previous post should be an array like this.
For step 3 you just need to write code to extract the data from the array.

The code can be run online here;

#include <iostream>

using namespace std;

int main()
{
    
    bool qr[21][21]=
    {
        true ,true ,true ,true ,true ,true ,true ,false,true ,false,true ,true ,true ,false,true ,true ,true ,true ,true ,true ,true ,
        true ,false,false,false,false,false,true ,false,false,false,true ,true ,false,false,true ,false,false,false,false,false,true ,
        true ,false,true ,true ,true ,false,true ,false,true ,true ,false,true ,false,false,true ,false,true ,true ,true ,false,true ,
        true ,false,true ,true ,true ,false,true ,false,true ,true ,false,false,true ,false,true ,false,true ,true ,true ,false,true ,
        true ,false,true ,true ,true ,false,true ,false,true ,false,false,true ,false,false,true ,false,true ,true ,true ,false,true ,
        true ,false,false,false,false,false,true ,false,false,true ,true ,true ,true ,false,true ,false,false,false,false,false,true ,
        true ,true ,true ,true ,true ,true ,true ,false,true ,false,true ,false,true ,false,true ,true ,true ,true ,true ,true ,true ,
        false,false,false,false,false,false,false,false,false,false,false,true ,true ,false,false,false,false,false,false,false,false,
        true ,true ,true ,true ,false,false,true ,false,true ,true ,true ,true ,true ,true ,false,false,true ,true ,true ,false,true ,
        true ,false,true ,false,true ,false,false,true ,true ,true ,true ,true ,true ,true ,true ,true ,true ,true ,true ,false,true ,
        false,false,true ,false,false,true ,true ,false,true ,false,false,true ,false,true ,false,true ,false,false,false,true ,true ,
        false,false,true ,true ,true ,true ,false,false,true ,false,false,true ,false,false,false,true ,false,true ,false,true ,false,
        true ,true ,true ,true ,false,false,true ,true ,true ,false,true ,false,true ,true ,true ,false,false,false,false,false,true ,
        false,false,false,false,false,false,false,false,true ,true ,true ,true ,false,false,true ,true ,false,false,true ,false,true ,
        true ,true ,true ,true ,true ,true ,true ,false,false,false,true ,true ,true ,true ,true ,true ,true ,false,false,false,false,
        true ,false,false,false,false,false,true ,false,false,true ,false,false,false,true ,false,true ,false,true ,true ,true ,true ,
        true ,false,true ,true ,true ,false,true ,false,false,false,true ,false,true ,false,false,false,false,true ,true ,false,false,
        true ,false,true ,true ,true ,false,true ,false,true ,false,false,false,false,false,true ,false,false,true ,true ,true ,false,
        true ,false,true ,true ,true ,false,true ,false,true ,true ,false,false,true ,false,false,true ,false,false,true ,false,false,
        true ,false,false,false,false,false,true ,false,true ,true ,false,true ,false,true ,true ,true ,true ,false,false,false,true ,
        true ,true ,true ,true ,true ,true ,true ,false,true ,false,true ,true ,false,true ,true ,true ,false,false,true ,false,false
    };
   
   // C++ arrays are stored in row-major order. Row-major order means the last subscript varies the fastest.
   for(int irow=0;irow<21;++irow)
   {
       for(int icol=0;icol<21;++icol)
       {
           if(qr[irow][icol])
           {
               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

QR_Code.GIF

sungjung:
We connected the camera to the Arduino, maybe we should bring a SD, you're right :wink:

Please describe by what you mean "connected"?
Have you got some code that works and proves you have the camera "connected"?
Thanks.. Tom.. :slight_smile:

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 !

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.