关键词:camera,摄像头
如何用开发板实现camera功能
简介
Air724UG支持一路摄像头接口。可以用于扫码,拍照应用。
功能开发指南
特点如下:
- 只支持SPI接口
- 最高像素30W像素@15fps
- 支持数据格式YUV422, Y420, RAW8, RAW10
- 集成GC0310驱动
本文介绍如何用Air724开发板,和PC端搭建一个camera功能演示。
材料准备
- EVB_Air724UG_A13开发板一套,包括天线SIM卡,USB线。
- PC电脑,摄像头(集成GC0310驱动)
3.TFT_LCD显示屏st7735 ,像素128X160 - luat开发环境:环境搭建方法
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-HTSayMYr-1624852338193)(http://openluat-luatcommunity.oss-cn-hangzhou.aliyuncs.com/images/20210416203840123_微信图片_20210416203804.jpg “undefined”)]
步骤
本文以demo\camera这个DEMO为例做演示。
1.获取显示屏长和宽,并定义一个扫码结果回调函数
local WIDTH,HEIGHT = disp.getlcdinfo()
local DEFAULT_WIDTH,DEFAULT_HEIGHT = 320,240
-- 扫码结果回调函数
-- @bool result,true或者false,true表示扫码成功,false表示超时失败
-- @string[opt=nil] codeType,result为true时,表示扫码类型;result为false时,为nil;支持QR-Code和CODE-128两种类型
-- @string[opt=nil] codeStr,result为true时,表示扫码结果的字符串;result为false时,为nil
local function scanCodeCb(result,codeType,codeStr)
--关闭摄像头预览
disp.camerapreviewclose()
--关闭摄像头
disp.cameraclose()
--允许系统休眠
pm.sleep("testScanCode")
--500毫秒后处理扫描结果
sys.timerStart(function()
--如果有LCD,显示扫描结果
if WIDTH~=0 and HEIGHT~=0 then
disp.clear()
if result then
disp.puttext(common.utf8ToGb2312("扫描成功"),0,5)
disp.puttext(common.utf8ToGb2312("类型: ")..codeType,0,35)
log.info("scanCodeCb",codeStr:toHex())
disp.puttext(common.utf8ToGb2312("结果: ")..codeStr,0,65)
else
disp.puttext(common.utf8ToGb2312("扫描失败"),0,5)
end
disp.update()
end
end,500)
sys.timerStart(scan,1000)
end
2.初始化4种摄像头寄存器
--bf302A_sd
--gc0310_sdr
--gc0310_ddr
--gc6153
local bf302A_sdr =
{
zbar_scan = 1,
i2c_addr = 0x6e,
sensor_width = 240,
sensor_height = 320,
id_reg = 0xfd,
id_value = 0x02,
spi_mode = disp.CAMERA_SPI_MODE_LINE1,
spi_speed = disp.CAMERA_SPEED_SDR,
spi_yuv_out = disp.CAMERA_SPI_OUT_Y1_V0_Y0_U0,
init_cmd =
{
0xcf,0xb0,--//POWER UP
0x12,0x40,--//MTK:20 ZX:10 RDA:40
0x15,0x00,
0x6b,0x71,
0x00,0x40,
0x04,0x00,
0x06,0x26,
0x08,0x07,
0x1c,0x12,
0x20,0x20,
0x21,0x20,
0x34,0x02,
0x35,0x02,
0x36,0x21,
0x37,0x13,
0xca,0xf3,
0xcb,0x22,
0xcc,0x89,
0xcd,0x4c,
0xce,0x6b,
0xa0,0x8e,
0x01,0x1b,
0x02,0x1d,
0x13,0x08,
0x87,0x13,
0x8b,0x08,
0x70,0x1f,
0x71,0x43,
0x72,0x0a,
0x73,0x62,
0x74,0xa2,
0x75,0xbf,
0x76,0x02,
0x77,0xcc,
0x40,0x32,
0x41,0x28,
0x42,0x26,
0x43,0x1d,
0x44,0x1a,
0x45,0x14,
0x46,0x11,
0x47,0x0f,
0x48,0x0e,
0x49,0x0d,
0x4B,0x0c,
0x4C,0x0b,
0x4E,0x0a,
0x4F,0x09,
0x50,0x09,
0x24,0x50,
0x25,0x36,
0x80,0x00,
0x81,0x20,
0x82,0x40,
0x83,0x30,
0x84,0x50,
0x85,0x30,
0x86,0xd8,
0x89,0x45,
0x8a,0x33,
0x8f,0x81,
0x91,0xff,
0x92,0x08,
0x94,0x82,
0x95,0xfd,
0x9a,0x20,
0x9e,0xbc,
0xf0,0x8f,
0x51,0x06,
0x52,0x25,
0x53,0x2b,
0x54,0x0f,
0x57,0x2a,
0x58,0x22,
0x59,0x2c,
0x23,0x33,
0xa1,0x93,
0xa2,0x0f,
0xa3,0x2a,
0xa4,0x08,
0xa5,0x26,
0xa7,0x80,
0xa8,0x80,
0xa9,0x1e,
0xaa,0x19,
0xab,0x18,
0xae,0x50,
0xaf,0x04,
0xc8,0x10,
0xc9,0x15,
0xd3,0x0c,
0xd4,0x16,
0xee,0x06,
0xef,0x04,
0x55,0x34,
0x56,0x9c,
0xb1,0x98,
0xb2,0x98,
0xb3,0xc4,
0xb4,0x0c,
0xa0,0x8f,
0x13,0x07,
}
}
local gc6153 =
{
zbar_scan = 1, --是否支持扫码
i2c_addr = 0x40, --/* 摄像头i2c访问地址 */
sensor_width = 240, --/* 摄像头的宽 */
sensor_height = 320, --/* 摄像头的高 */
id_reg = 0xf1, -- /* 摄像头ID寄存器 */
id_value = 0x53, -- /* 摄像头ID值 */
-- /* 摄像头SPI是几线输出 */
--disp.CAMERA_SPI_MODE_LINE1 1线
--disp.CAMERA_SPI_MODE_LINE2 2线
--disp.CAMERA_SPI_MODE_LINE4 4线
spi_mode = disp.CAMERA_SPI_MODE_LINE1, -- /* 摄像头SPI是几线输出 */
-- /* 摄像头采集速率 */
--disp.CAMERA_SPEED_SDR 单片采集
--disp.CAMERA_SPEED_DDR 双边采集
spi_speed = disp.CAMERA_SPEED_SDR, -- /* 摄像头采集速率 */
--disp.CAMERA_SPI_OUT_Y0_U0_Y1_V0
--disp.CAMERA_SPI_OUT_Y0_V0_Y1_U0
--disp.CAMERA_SPI_OUT_U0_Y0_V0_Y1
--disp.CAMERA_SPI_OUT_U0_Y1_V0_Y0
--disp.CAMERA_SPI_OUT_V0_Y0_U0_Y1
--disp.CAMERA_SPI_OUT_Y1_V0_Y0_U0
--disp.CAMERA_SPI_OUT_Y1_U0_Y0_V0
spi_yuv_out = disp.CAMERA_SPI_OUT_U0_Y1_V0_Y0, -- /* 摄像头输出YUV的格式 */
init_cmd = --/*摄像头初始化寄存器*/
{
--addr value
0xfe, 0xa0 ,
0xfe, 0xa0 ,
0xfe, 0xa0 ,
0xf6, 0x00 ,
0xfa, 0x11 ,
0xfc, 0x12 ,
0xfe, 0x00 ,
0xfe, 0x00 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00 ,
0x10,0x00 ,
0x15,0x00 ,
0x17,0x00 ,
0x04,0x10 ,
0x05,0x00 ,
0x40,0x00 ,
0x52,0xa0 ,
0x53,0x24 ,
0x54,0x20 ,
0x55,0x20 ,
0x5a,0x00 ,
0x51,0x03 ,
0x64,0x06 ,
0xfe,0x00 ,
},
}
local gc0310_sdr =
{
zbar_scan = 1,
i2c_addr = 0x21,
sensor_width = 320,
sensor_height = 240,
id_reg = 0xf1,
id_value = 0x10,
spi_mode = disp.CAMERA_SPI_MODE_LINE2,
spi_speed = disp.CAMERA_SPEED_SDR,
spi_yuv_out = disp.CAMERA_SPI_OUT_Y1_V0_Y0_U0,
init_cmd =
{
0xfe,0xf0 ,
0xfe,0xf0 ,
0xfe,0x00 ,
0xfc,0x16 , --4e
0xfc,0x16 , --4e -- [0]apwd [6]regf_clk_gate
0xf2,0x07 , --sync output
0xf3,0x83 , --ff--1f--01 data output
0xf5,0x07 , --sck_dely
0xf7,0x88 , --f8/ 88
0xf8,0x00 , -- 00
0xf9,0x4f , --0f--01 4d
0xfa,0x32 , --32
0xfc,0xce ,
0xfd,0x00 ,
------------------------------------------------/
----------------/ CISCTL reg ----------------/
------------------------------------------------/
0x00,0x2f ,
0x01,0x0f ,
0x02,0x04 ,
0x03,0x02 ,
0x04,0x12 ,
0x09,0x00 ,
0x0a,0x00 ,
0x0b,0x00 ,
0x0c,0x02 ,--04
0x0d,0x01 ,
0x0e,0xec ,--e8
0x0f,0x02 ,
0x10,0x88 ,
0x16,0x00 ,
0x17,0x14 , --mirror
0x18,0x6a ,--1a
0x19,0x14 ,
0x1b,0x48 ,
0x1c,0x1c ,
0x1e,0x6b ,
0x1f,0x28 ,
0x20,0x8b ,--0x89 travis20140801
0x21,0x49 ,
0x22,0xb0 ,
0x23,0x04 ,
0x24,0xff ,
0x34,0x20 ,
------------------------------------------------/
-------------------- BLK --------------------
------------------------------------------------/
0x26,0x23 ,
0x28,0xff ,
0x29,0x00 ,
0x32,0x00 ,
0x33,0x10 ,
0x37,0x20 ,
0x38,0x10 ,
0x47,0x80 ,
0x4e,0x0f ,--66
0xa8,0x02 ,
0xa9,0x80 ,
------------------------------------------------/
------------------ ISP reg ------------------/
------------------------------------------------/
0x40,0xff ,
0x41,0x21 ,
0x42,0xcf ,
0x44,0x02 ,
0x45,0xa8 ,
0x46,0x02 , --sync
0x4a,0x11 ,
0x4b,0x01 ,
0x4c,0x20 ,
0x4d,0x05 ,
0x4f,0x01 ,
0x50,0x01 ,
0x55,0x00 ,
0x56,0xf0 ,
0x57,0x01 ,
0x58,0x40 ,
------------------------------------------------/
------------------/ GAIN --------------------
------------------------------------------------/
0x70,0x70 ,
0x5a,0x84 ,
0x5b,0xc9 ,
0x5c,0xed ,
0x77,0x74 ,
0x78,0x40 ,
0x79,0x5f ,
------------------------------------------------/
------------------/ DNDD --------------------/
------------------------------------------------/
0x82,0x08 ,--0x14
0x83,0x0b ,
0x89,0xf0 ,
------------------------------------------------/
------------------ EEINTP --------------------
------------------------------------------------/
0x8f,0xaa ,
0x90,0x8c ,
0x91,0x90 ,
0x92,0x03 ,
0x93,0x03 ,
0x94,0x05 ,
0x95,0x43 , --0x65
0x96,0xf0 ,
------------------------------------------------/
--------------------/ ASDE --------------------
------------------------------------------------/
0xfe,0x00 ,
0x9a,0x20 ,
0x9b,0x80 ,
0x9c,0x40 ,
0x9d,0x80 ,
0xa1,0x30 ,
0xa2,0x32 ,
0xa4,0x30 ,
0xa5,0x30 ,
0xaa,0x10 ,
0xac,0x22 ,
------------------------------------------------/
------------------/ GAMMA ------------------/
------------------------------------------------/
0xfe,0x00 ,--default
0xbf,0x08 ,
0xc0,0x16 ,
0xc1,0x28 ,
0xc2,0x41 ,
0xc3,0x5a ,
0xc4,0x6c ,
0xc5,0x7a ,
0xc6,0x96 ,
0xc7,0xac ,
0xc8,0xbc ,
0xc9,0xc9 ,
0xca,0xd3 ,
0xcb,0xdd ,
0xcc,0xe5 ,
0xcd,0xf1 ,
0xce,0xfa ,
0xcf,0xff ,
------------------------------------------------/
------------------/ YCP ----------------------
------------------------------------------------/
0xd0,0x40 ,
0xd1,0x38 , --0x34
0xd2,0x38 , --0x34
0xd3,0x50 ,--0x40
0xd6,0xf2 ,
0xd7,0x1b ,
0xd8,0x18 ,
0xdd,0x03 ,
------------------------------------------------/
-------------------- AEC --------------------
------------------------------------------------/
0xfe,0x01 ,
0x05,0x30 ,
0x06,0x75 ,
0x07,0x40 ,
0x08,0xb0 ,
0x0a,0xc5 ,
0x0b,0x11 ,
0x0c,0x00 ,
0x12,0x52 ,
0x13,0x38 ,
0x18,0x95 ,
0x19,0x96 ,
0x1f,0x20 ,
0x20,0xc0 ,
0x3e,0x40 ,
0x3f,0x57 ,
0x40,0x7d ,
0x03,0x60 ,
0x44,0x02 ,
------------------------------------------------/
-------------------- AWB --------------------
------------------------------------------------/
0xfe,0x01 ,
0x1c,0x91 ,
0x21,0x15 ,
0x50,0x80 ,
0x56,0x04 ,
0x59,0x08 ,
0x5b,0x02 ,
0x61,0x8d ,
0x62,0xa7 ,
0x63,0xd0 ,
0x65,0x06 ,
0x66,0x06 ,
0x67,0x84 ,
0x69,0x08 ,
0x6a,0x25 ,
0x6b,0x01 ,
0x6c,0x00 ,
0x6d,0x02 ,
0x6e,0xf0 ,
0x6f,0x80 ,
0x76,0x80 ,
0x78,0xaf ,
0x79,0x75 ,
0x7a,0x40 ,
0x7b,0x50 ,
0x7c,0x0c ,
0x90,0xc9 ,--stable AWB
0x91,0xbe ,
0x92,0xe2 ,
0x93,0xc9 ,
0x95,0x1b ,
0x96,0xe2 ,
0x97,0x49 ,
0x98,0x1b ,
0x9a,0x49 ,
0x9b,0x1b ,
0x9c,0xc3 ,
0x9d,0x49 ,
0x9f,0xc7 ,
0xa0,0xc8 ,
0xa1,0x00 ,
0xa2,0x00 ,
0x86,0x00 ,
0x87,0x00 ,
0x88,0x00 ,
0x89,0x00 ,
0xa4,0xb9 ,
0xa5,0xa0 ,
0xa6,0xba ,
0xa7,0x92 ,
0xa9,0xba ,
0xaa,0x80 ,
0xab,0x9d ,
0xac,0x7f ,
0xae,0xbb ,
0xaf,0x9d ,
0xb0,0xc8 ,
0xb1,0x97 ,
0xb3,0xb7 ,
0xb4,0x7f ,
0xb5,0x00 ,
0xb6,0x00 ,
0x8b,0x00 ,
0x8c,0x00 ,
0x8d,0x00 ,
0x8e,0x00 ,
0x94,0x55 ,
0x99,0xa6 ,
0x9e,0xaa ,
0xa3,0x0a ,
0x8a,0x00 ,
0xa8,0x55 ,
0xad,0x55 ,
0xb2,0x55 ,
0xb7,0x05 ,
0x8f,0x00 ,
0xb8,0xcb ,
0xb9,0x9b ,
------------------------------------------------/
-------------------- CC ------------------------
------------------------------------------------/
0xfe,0x01 ,
0xd0,0x38 ,--skin red
0xd1,0x00 ,
0xd2,0x02 ,
0xd3,0x04 ,
0xd4,0x38 ,
0xd5,0x12 ,
0xd6,0x30 ,
0xd7,0x00 ,
0xd8,0x0a ,
0xd9,0x16 ,
0xda,0x39 ,
0xdb,0xf8 ,
------------------------------------------------/
-------------------- LSC --------------------
------------------------------------------------/
0xfe,0x01 ,
0xc1,0x3c ,
0xc2,0x50 ,
0xc3,0x00 ,
0xc4,0x40 ,
0xc5,0x30 ,
0xc6,0x30 ,
0xc7,0x10 ,
0xc8,0x00 ,
0xc9,0x00 ,
0xdc,0x20 ,
0xdd,0x10 ,
0xdf,0x00 ,
0xde,0x00 ,
------------------------------------------------/
------------------/ Histogram ----------------/
------------------------------------------------/
0x01,0x10 ,
0x0b,0x31 ,
0x0e,0x50 ,
0x0f,0x0f ,
0x10,0x6e ,
0x12,0xa0 ,
0x15,0x60 ,
0x16,0x60 ,
0x17,0xe0 ,
------------------------------------------------/
-------------- Measure Window --------------/
------------------------------------------------/
0xcc,0x0c ,
0xcd,0x10 ,
0xce,0xa0 ,
0xcf,0xe6 ,
------------------------------------------------/
----------------/ dark sun ------------------
------------------------------------------------/
0x45,0xf7 ,
0x46,0xff ,
0x47,0x15 ,
0x48,0x03 ,
0x4f,0x60 ,
------------------------------------------------/
------------------/ banding ------------------/
------------------------------------------------/
0xfe,0x00 ,
0x05,0x01 ,
0x06,0x12 , --HB
0x07,0x00 ,
0x08,0x1c , --VB
0xfe,0x01 ,
0x25,0x00 , --step
0x26,0x1f ,
0x27,0x01 , --6fps
0x28,0xf0 ,
0x29,0x01 , --6fps
0x2a,0xf0 ,
0x2b,0x01 , --6fps
0x2c,0xf0 ,
0x2d,0x03 , --3.3fps
0x2e,0xe0 ,
0x3c,0x20 ,
--------------------/ SPI --------------------
------------------------------------------------/
0xfe,0x03 ,
0x01,0x00 ,
0x02,0x00 ,
0x10,0x00 ,
0x15,0x00 ,
0x17,0x00 , --01--03
0x04,0x10 ,--fifo full level
0x40,0x00 ,
0x52,0x82 , --zwb 02改成da
0x53,0x24 , --24
0x54,0x20 ,
0x55,0x20 , --QQ--01
0x5a,0x00 , --00 --yuv
0x5b,0x40 ,
0x5c,0x01 ,
0x5d,0xf0 ,
0x5e,0x00 ,
0x51,0x03 ,
0xfe,0x00 ,
}
}
2.1 初始化lcd
--[[
函数名:init
功能 :初始化LCD参数
参数 :无
返回值:无
]]
local function init()
local para =
{
width = 128, --分辨率宽度,128像素;用户根据屏的参数自行修改
height = 160, --分辨率高度,160像素;用户根据屏的参数自行修改
bpp = 16, --位深度,彩屏仅支持16位
bus = disp.BUS_SPI4LINE, --LCD专用SPI引脚接口,不可修改
xoffset = 2, --X轴偏移
yoffset = 1, --Y轴偏移
freq = 13000000, --spi时钟频率,支持110K到13M(即110000到13000000)之间的整数(包含110000和13000000)
pinrst = pio.P0_6, --reset,复位引脚
pinrs = pio.P0_1, --rs,命令/数据选择引脚
--camera_preview_no_update_screen = 1, --0表示摄像头预览刷屏;1表示摄像头预览不刷屏
--初始化命令
--前两个字节表示类型:0001表示延时,0000或者0002表示命令,0003表示数据
--延时类型:后两个字节表示延时时间(单位毫秒)
--命令类型:后两个字节命令的值
--数据类型:后两个字节数据的值
initcmd =
{
0x00020011,
0x00010078,
--0x00020021, -- 反显
0x000200B1,
0x00030002,
0x00030035,
0x00030036,
0x000200B2,
0x00030002,
0x00030035,
0x00030036,
0x000200B3,
0x00030002,
0x00030035,
0x00030036,
0x00030002,
0x00030035,
0x00030036,
0x000200B4,
0x00030007,
0x000200C0,
0x000300A2,
0x00030002,
0x00030084,
0x000200C1,
0x000300C5,
0x000200C2,
0x0003000A,
0x00030000,
0x000200C3,
0x0003008A,
0x0003002A,
0x000200C4,
0x0003008A,
0x000300EE,
0x000200C5,
0x0003000E,
0x00020036,
0x00030000, --0x000300C0 --mirror
0x000200E0,
0x00030012,
0x0003001C,
0x00030010,
0x00030018,
0x00030033,
0x0003002C,
0x00030025,
0x00030028,
0x00030028,
0x00030027,
0x0003002F,
0x0003003C,
0x00030000,
0x00030003,
0x00030003,
0x00030010,
0x000200E1,
0x00030012,
0x0003001C,
0x00030010,
0x00030018,
0x0003002D,
0x00030028,
0x00030023,
0x00030028,
0x00030028,
0x00030026,
0x0003002F,
0x0003003B,
0x00030000,
0x00030003,
0x00030003,
0x00030010,
0x0002003A,
0x00030005,
0x00020029,
},
--休眠命令
sleepcmd = {
0x00020010,
},
--唤醒命令
wakecmd = {
0x00020011,
}
}
disp.init(para)
disp.clear()
disp.update()
end
--控制SPI引脚的电压域
pmd.ldoset(15,pmd.LDO_VLCD)
init()
3.定义一个扫码函数
function scan()
--唤醒系统
pm.wake("testScanCode")
local ret = 0
--设置扫码回调函数,默认10秒超时
scanCode.request(scanCodeCb)
--打开摄像头
--ret = disp.cameraopen(1,1) -- 内部配置的gc0310 camera
--ret = disp.cameraopen_ext(gc6153) -- 外部配置gc6153 camera SDR
ret = disp.cameraopen_ext(gc0310_sdr) -- 外部配置gc0310 camera SDR
--ret = disp.cameraopen_ext(gc0310_ddr) -- 外部配置gc0310 camera DDR
--ret = disp.cameraopen_ext(bf302A_sdr) -- 外部配置bf302A camera SDR
log.info("testScanCode cameraopen_ext ret ", ret)
--打开摄像头预览
--zoom: 放缩设置, 正数放大负数缩小,最大4倍,0不放缩
--disp.camerapreviewzoom(zoom)
--缩小2倍
disp.camerapreviewzoom(-2)
ret = disp.camerapreview(0,0,0,0,128,160)
--rotation:反转角度设置 暂时只支持0和90度
--disp.camerapreviewrotation(90)
end
4.定义一个拍照函数
-- 拍照并显示
function takePhotoAndDisplay()
--唤醒系统
pm.wake("testTakePhoto")
--打开摄像头
disp.cameraopen(1,0,0,1)
--disp.cameraopen(1,0,0,0) --因目前core中还有问题没解决,所以不能关闭隔行隔列
--打开摄像头预览
--如果有LCD,使用LCD的宽和高
--如果无LCD,宽度设置为240像素,高度设置为320像素,240*320是Air268F支持的最大分辨率
disp.camerapreview(0,0,0,0,WIDTH or DEFAULT_WIDTH,HEIGHT or DEFAULT_HEIGHT)
--设置照片的宽和高像素并且开始拍照
--此处设置的宽和高和预览时的保持一致
--此处的第三个参数表示拍摄质量,默认50,100最好
disp.cameracapture(WIDTH or DEFAULT_WIDTH,HEIGHT or DEFAULT_HEIGHT)
--设置照片保存路径
disp.camerasavephoto("/testCamera.jpg")
log.info("testCamera.takePhotoAndDisplay fileSize",io.fileSize("/testCamera.jpg"))
--关闭摄像头预览
disp.camerapreviewclose()
--关闭摄像头
disp.cameraclose()
--允许系统休眠
pm.sleep("testTakePhoto")
--testUartSentFile.sendFile()
--显示拍照图片
if WIDTH~=0 and HEIGHT~=0 then
disp.clear()
disp.putimage("/testCamera.jpg",0,0)
disp.puttext(common.utf8ToGb2312("照片尺寸: "..io.fileSize("/testCamera.jpg")),0,5)
disp.update()
end
--sys.timerStart(takePhotoAndDisplay,1000)
end
5.开启1个循环定时器,执行拍照函数
sys.timerLoopStart(takePhotoAndDisplay,5000)
6.在了解并修改了DEMO后将demo和对应的底包下载到开发板,下载的方式这里不详细说明请参考环境搭建中的烧录章节。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-K0VrQA6U-1624852338195)(http://openluat-luatcommunity.oss-cn-hangzhou.aliyuncs.com/images/20210416210816993_微信截图_20210416210714.png “undefined”)]
7.开启1个定时器,执行扫码函数
sys.timerStart(scan,1000)
8.在了解并修改了DEMO后将demo和对应的底包下载到开发板,并对着一个二维码扫描,可以在屏上看到扫描的类型,和数据
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-m52ZZbUd-1624852338196)(http://openluat-luatcommunity.oss-cn-hangzhou.aliyuncs.com/images/20210416211520716_微信截图_20210416211409.png “undefined”)]
显示屏上的显示内容如下:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Y8cgaMex-1624852338197)(http://openluat-luatcommunity.oss-cn-hangzhou.aliyuncs.com/images/20210416211847108_微信图片_20210416211733.jpg “undefined”)]
常见问题
-
为什么显示白屏,黑屏,扫码不成功?
查看下,屏是否插好,引脚是否接对,core,是否选对。 -
为什么图像左移
看是否把预览缩小2倍
–zoom: 放缩设置, 正数放大负数缩小,最大4倍,0不放缩
disp.camerapreviewzoom(zoom)
–缩小2倍
disp.camerapreviewzoom(-2)