Import C++ program (ZBar) to Arduino

First a small intro: I am building a barcode scanner and have finished on the hardware part but now I am stuck on the software part. I have attached a laser scan engine and feeding its output to a digital pin (A2) that I have set as input. So far so good and my pin reads as such val = digitalRead(A2); // read PIN A2 and gives me a stream of raw binary data. What I wanna do now is take this binary data and use a decoding library (ZBar / ZXing are the most popular ones) to translate it to an actual string.

ZBar is already written in C++ so that's good. I believe the most important files for me are decode.c/decode.h/scanner.c/code128.c/code128.h/zbar.h. So where do I go from here? The problem is that if I try for example to create a sketch with decode.c I am having many problems with header files dependencies. If I use the import library function and then include them, they still include their own header files, which cannot be found and I get a fatal error.

I know it's not a very straightforward question, but does anyone here have experience of importing programs to Arduino? Can anyone help?

How big is the ZBar program? If it was written to run on a PC it may be far too large to fit on an Arduino.

It is also very likely to use Operating-System related PC libraries that are not available on an Arduino.

Have you asked Google if there is an Arduino bar-code library?

...R

Hi, thanks for your answer. It's not a huge program but in the end of the day it's only the decoder library that I need because I already have my data. It is actually using some standard libraries (stdio, stdlib, stream etc) so I was wondering how I can get around that.... I have heard that Atmel Studio+visual micro can help in this case? Google does not give me any arduino barcode decoding library.... Any page that refers to arduinos and barcodes assumes that the scanner has already processed the barcode and sends the string to the arduino via serial/usb/ps2 or whatever... I have found nothing about microcontrollers decoding raw binary data this is why I have come to this forum.

Thank you in advance.

Sorry, I can't help with implementing the existing code into an Arduino - I don't know enough about C/C++.

Do you know how to convert the pulses into codes? Maybe you could write an Arduino program that does the same thing as the ZBar library - especially if you have the source code for it.

...R

What do you see if you print the raw data received on A2 if you scan a barcode which consists of a known set of characters ?

Post the serial output and the barcode details here and you may get more help.

If it were me, I'd write my own from scratch, since the zbar you refer to seems to have too many dependencies.

The barcode data format is discussed here:

http://en.wikipedia.org/wiki/Universal_Product_Code

Cheers for the answers. I am attaching the serial monitor code I’m getting if I run at 115200 for about 5 secs.

I am actually thinking of making this from scratch since no other solution is out there, however it may get quite tricky because, you know due to distance, a bar near the scanner is 1 but far away becomes 11 or 111 so this might complicate things.

The barcode I am trying to process is type Code128.

PS: anyone has any experience of Arduino CMake? Maybe that would help me port the code? GitHub - queezythegreat/arduino-cmake: Arduino CMake Build system

115200.txt (247 KB)

AfouToPatisa: however it may get quite tricky because, you know due to distance, a bar near the scanner is 1 but far away becomes 11 or 111 so this might complicate things.

I imagine this is a "standard" problem with a standard solution.

...R

Yes that's what I thought... Hopefully ZXing solves such a problem

AfouToPatisa: Yes that's what I thought... Hopefully ZXing solves such a problem

Why do you want to build a barcode scanner of your own while there are ready-to-use barcode scanners available and you seem to be absolute clueless about barcodes and the PC program you want to convert (or small parts of it) to fit into an Arduino sketch?

Especially reading CODE128 can become very tricky, depending on your application, as CODE128 is indeed three different barcodes: CODE128 A CODE128 B CODE128 C And special applications need special versions of CODE128.

Why don't you use a ready-to-use barcode scanner with a common interface that would be easy to read with Arduino, such as a RS232 interface: Connect the barcode scanner and an RS232-TTL Serial Adapter to the Arduino and the hardware is ready, and Serial.read() function will read the barcode in your Arduino sketch.

jurs:
Why do you want to build a barcode scanner of your own while there are ready-to-use barcode scanners available and you seem to be absolute clueless about barcodes and the PC program you want to convert (or small parts of it) to fit into an Arduino sketch?

Especially reading CODE128 can become very tricky, depending on your application, as CODE128 is indeed three different barcodes:
CODE128 A
CODE128 B
CODE128 C
And special applications need special versions of CODE128.

Why don’t you use a ready-to-use barcode scanner with a common interface that would be easy to read with Arduino, such as a RS232 interface: Connect the barcode scanner and an RS232-TTL Serial Adapter to the Arduino and the hardware is ready, and Serial.read() function will read the barcode in your Arduino sketch.

This is a very sensible question you are asking. I am doing this because I want to explore how small of a barcode scanner I can possibly build, while having all the Arduino platform advantages.
Because the ready-to-use barcode scanners already have a built-in microcontroller so I want to replace its functionality with the Arduino’s one.