Go Down

Topic: Interface barcode scanner with arduino yun (Read 10479 times) previous topic - next topic

sridevi

Getting error while installing kmod-input-core.

root@Arduino:/# opkg install /mnt/sda1/kmod-input-core_3.3.8-1_ar71xx.ipk

=====================

Installing kmod-input-core (3.3.8-1) to root...
Collected errors:
 * satisfy_dependencies_for: Cannot satisfy the following dependencies for kmod-input-core:
 *    kernel (= 3.3.8-1-bd655b187e04910d9917973d44f685fb) *
 * opkg_install_cmd: Cannot install package kmod-input-core.

========================

I upgraded arduino yun to the latest image.

Below is my kernel details.

========================
root@Arduino:/#  opkg list | grep ^kernel
kernel - 3.3.8-1-openwrtyun1
========================

How to solve this kernel error? 


sonnyyu



sridevi

Thanks for the details Mr.Sonnyyu. 

Finally I installed the files from my SD card and now I connected one USB mouse with yun.  It is detected and shown at event 1 as mentioned by you .

Now I want to detect the mouse click.  This means if I click the right mouse button, right button clicked message should be displayed in terminal.  How can I do this. 

In your sample, you showed a C program.  Pls let me know the compiler and editor details.

sridevi

I'm little confused.  C or Phython which is better to write these programs.  Should I have to install any compiler softwares in linux processor?

ShapeShifter

C or Python? Both will get the job done. Which are you more comfortable with?

I've been doing C for MANY years, so that would be my first choice. However, C needs a lot more development environment support. It's difficult to get the compiler environment running on the Yun, so that probably means cross-compiling it on another computer, then copying it to the Yun for running/testing. That can also be a big job if you don't have that environment already set up. While it's more work to set up, the advantage is that you get fast compiled code. But it's more work to maintain.

For Python, the necessary environment is already well supported by the Yun. It's an interpreted language, so there is no need to compile it: just edit your code, then run it. The downside is that being interpreted, it won't be as fast as a compiled language. But on the other hand, there is already support for a lot of the Yun features, including interacting with the Bridge library.

I'm an old C coder, but in spite of that, I'm using the Yun as an excuse to learn Python. To me, at least, it seems the way to go.

sonnyyu


sridevi

Dear Mr.Sonnyyu,

I ran the command,  ./evdev.py '/dev/input/event1'     and got the expected result.


Please clarify where I have to insert the below code.  Should I insert it in evdev.py program or somewhere else?

#!/usr/bin/python
import sys 
sys.path.insert(0, '/usr/lib/python2.7/bridge/')
from bridgeclient import BridgeClient as bridgeclient
bc = bridgeclient()                         
bc.put('to_arduino',keyboard_code)



And How can I interface this bridgeclient with arduino program.  I wish to get the resulted keyboard_code in serial terminal of arduino software.

Kindly help.




ShapeShifter

And How can I interface this bridgeclient with arduino program.  I wish to get the resulted keyboard_code in serial terminal of arduino software.
The Python code is using "put" to write a value to the key "to_arduino"

On the Arduino side, you need to use the bridge library to "get" the value from that same key. You could do something like this (I've not tried running it yet, so there may be issues with the code):

Code: [Select]
#include <Bridge.h>

#define BUFF_LEN 20

void setup() {
  Bridge.begin();
  Serial.begin(9600);
  while (!Serial); // wait for serial port to connect.
}

void loop() {
  char keyboard_code[BUFF_LEN];
  int code_len;
  
  // Get the string that was last "put" by the Python code
  code_len = Bridge.get("to_arduino", keyboard_code, BUFF_LEN);

  // Print out the length of the code and the string.
  Serial.print("keyboard_code is ");
  Serial.print(code_len);
  Serial.print("chars long: ");
  Serial.println(keyboard_code);  
}


You will no doubt want something more sophisticated. This will try to read values from the "to_arduino" key and print it as fast as possible, whether or not the Python code has actually changed it. You will want to add some sort of handshaking between the Arduino code and the Python code so that the Python code can let the Arduino side know that there is new data:

  • Have the Arduino side look for a changed value before printing it. The downside to this is you wouldn't be able to pass the same code twice
  • Have the Arduino side clear out the "to_arduino" key by using "put" to set a blank value. Then, if the "get" value is not blank, print it then clear it again
  • Have the Python side "put" another value in a key like "ready" to indicate new data, which gets set after updating the "to_arduino" key. The Arduino side uses "get" to read this value, and if it signals ready it reads the "to_arduino" key then clears the ready value.
  • Have the Python side increment a value and store it in a "ready" key after it stores a new value in the "to_arduino" key. If the "Arduino" side sees a different value than before in the "ready" key, it can then read the "to_arduino" key.

sridevi

I want to get this keyboard_code value in vb.net program.  Is it possible to send any variable to visual studio program which is in my PC.  PC and Arduino yun are in same network connection via ethernet.  Connection establishment is ok.  How to send and receive data in both sides?  Any ideas?

Angelo9999

Pyhon provides some libraries to create TCP/IP connections.

Take a look here https://wiki.python.org/moin/TcpCommunication

sridevi

Thanks.  I made it.  I used yunServer, yunClient in Arduino side and webRequest, webResponse in VB.Net side.

ShapeShifter

#27
Dec 13, 2014, 07:56 pm Last Edit: Dec 13, 2014, 07:57 pm by ShapeShifter
I'm starting a new project, and a quick search immediately turned up this post. I had forgotten about this thread. Thank you sir, this worked like a charm with my old Symbol scanners! I am once again indebted to you.  :D


Code: [Select]
opkg update
opkg install kmod-hid
opkg install kmod-input-evdev
opkg install kmod-input-core
opkg install kmod-usb-hid


The barcode scanner is at

Code: [Select]
/dev/input/event1

Now we need compile c program "barcode"

ShapeShifter

What bar code scanner resource did you use?
I use a pair of Symbol LS2104 handheld USB scanners that I bought used off of eBay a couple years ago: two for $20.


These act like USB keyboards, so whatever is scanned is "typed" into whatever application is running. They Python code I wrote accesses the underlying HID device directly, captures events, and converts them to strings that are sent to the sketch.

Quote
Now I only have a .net barcode scanner library
Wow, that is an expensive package!  :o

I'm a bit confused... is that a package that takes an image (like from a camera) and then decodes the barcode? If so, I have no experience with such a package. I've only worked with scanner hardware that handles all of the decoding internally. (The only exception is the time I wrote a routine to take the light/dark output from a pen style scanner, and extracted the timing and wide/narrow pulse data and decoded that. It worked OK with a clean crisp code, but it was not very robust of tolerant of poor print quality.)

Go Up