{"id":1602,"date":"2019-12-28T12:47:35","date_gmt":"2019-12-28T12:47:35","guid":{"rendered":"https:\/\/ofalcao.pt\/blog\/?p=1602"},"modified":"2020-01-19T19:40:23","modified_gmt":"2020-01-19T19:40:23","slug":"ev3-barcode-scanner","status":"publish","type":"post","link":"https:\/\/ofalcao.pt\/blog\/2019\/ev3-barcode-scanner","title":{"rendered":"EV3 barcode scanner"},"content":{"rendered":"<div class=\"seriesmeta\">This post is part 1 of 3 of \u00a0<a href=\"https:\/\/ofalcao.pt\/blog\/series\/barcode\" class=\"series-357\" title=\"barcode\">barcode<\/a><\/div>\n<p>Should be finishing my EV3 Alexa program&#8230; but not in the mood.<\/p>\n\n\n\n<p>So I got a USB barcode scanner in front of me&#8230; hmm, I wonder&#8230;?<\/p>\n\n\n\n<p>My Ubuntu linux laptop recognizes. HID device, a keyboard. Great, plug and play!<\/p>\n\n\n\n<p>So does my EV3 running ev3dev:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[  538.808906] usb 1-1.2: new full-speed USB device number 6 using ohci-da8xx\n[  538.972308] usb 1-1.2: New USB device found, idVendor=04b4, idProduct=0100\n[  538.972383] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0\n[  538.972425] usb 1-1.2: Product: USB Virtual PS2 Port    \n[  538.972462] usb 1-1.2: Manufacturer: Future            \n[  539.040788] input: Future             USB Virtual PS2 Port     as \/devices\/platform\/soc@1c00000\/ohci-da8xx\/usb1\/1-1\/1-1.2\/1-1.2:1.0\/0003:04B4:0100.0001\/input\/input2\n[  539.128526] hid-generic 0003:04B4:0100.0001: input,hidraw0: USB HID v1.00 Keyboard [Future             USB Virtual PS2 Port    ] on usb-ohci-da8xx-1.2\/input0<\/pre>\n\n\n\n<p>So if this is a keyboard I can read it with input functions:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#! \/usr\/bin\/env python3\n\n# if you are running from ssh session invoke this script with 'brickrun'\nfrom ev3dev2 .sound import Sound\n\nsound = Sound()\n\nwhile True:\n    ucc = input('Scan a UCC: ')\n    ucc = ucc.lower().strip().replace('\\t','').replace('\\n','')\n    sound.speak(ucc)<\/code><\/pre>\n\n\n\n<p>Yes, it works. Just need to disable Brickman interface (first time I ran it the &#8216;keys&#8217; read from from the scanner disabled my Wi-Fi connection). I can use print but the since the LCD is so small I prefer to use &#8216;speak&#8217;.<\/p>\n\n\n\n<p>Now&#8230; what can I do with it?<\/p>\n\n\n\n<p>Of course&#8230; identify LEGO sets!<\/p>\n\n\n\n<p>So I found out that there are online databases of barcodes and some even offer  webservices API. I asked a free trial key at &#8220;https:\/\/www.barcodelookup.com\/api&#8221; and copy&amp;pasted their python demo code&#8230; and it just works.<\/p>\n\n\n\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"LEGO barcode scanner\" width=\"840\" height=\"473\" src=\"https:\/\/www.youtube.com\/embed\/orTTAOvWtzE?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>Code: https:\/\/github.com\/JorgePe\/ev3-barcode\/blob\/master\/barcode02.py<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"seriesmeta\">This post is part 1  of 3 of \u00a0<a href=\"https:\/\/ofalcao.pt\/blog\/series\/barcode\" class=\"series-357\" title=\"barcode\">barcode<\/a><\/div><p>Should be finishing my EV3 Alexa program&#8230; but not in the mood. So I got a USB barcode scanner in front of me&#8230; hmm, I wonder&#8230;? My Ubuntu linux laptop recognizes. HID device, a keyboard. Great, plug and play! So does my EV3 running ev3dev: [ 538.808906] usb 1-1.2: new full-speed USB device number 6 &hellip; <a href=\"https:\/\/ofalcao.pt\/blog\/2019\/ev3-barcode-scanner\" class=\"more-link\">Continuar a ler<span class=\"screen-reader-text\"> &#8220;EV3 barcode scanner&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[1],"tags":[],"series":[357],"class_list":["post-1602","post","type-post","status-publish","format-standard","hentry","category-sem-categoria","series-barcode"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2Mhyv-pQ","_links":{"self":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/1602","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/comments?post=1602"}],"version-history":[{"count":0,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/1602\/revisions"}],"wp:attachment":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/media?parent=1602"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/categories?post=1602"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/tags?post=1602"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/series?post=1602"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}