Running the code

The following are the steps to be performed:

  1. Download and install the latest version of MaixPy IDE for your operating system from http://dl.sipeed.com/MAIX/MaixPy/ide/.
  2. Connect the Maix K210 microcontroller to a USB port on your computer.
  3. Click on the Connect button at the bottom left of the screen (it resembles a chain). 
  4. Select the port the Maix K210 is connected to and click on the OK button, as shown in the following screenshot:

  1. Click on the New File button in the top-left to create a new file and name it qr-test.py.
  2. Select all of the pre-generated code in the main text area and delete it.
  3. Copy and paste the following code in its place:
import sensor
import image

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QVGA)
sensor.set_vflip(1)

while True:
img = sensor.snapshot()
res = img.find_qrcodes()

if len(res) > 0:
img.draw_string(2,2,res[0].payload(),
color=(255,255,255),scale=1.5)
  1. Change the Histogram to Grayscale Color Space by selecting it from the drop-down arrow on the right, as shown in the following screenshot:

  1. Print out onto paper, or load into a phone or tablet, a QR code. You may use the following QR:

  1. Run the program by clicking on the Start button (the button below the Connect button).
  2. Place the QR code over the camera using Frame Buffer as a reference, as shown in the following screenshot:

  1. Verify that you see the text or URL that the QR code represents on the screen.

As you can see, it takes very little code to read a QR code using MicroPython. We could use this code to open a door, for example. It's easy to imagine a hotel chain using regenerated QR codes for room access instead of plastic cards.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.48.181