Hello, I have a barcode scanner setup with Arduino. It is used in a model train layout to individually ID Locomotives and Carriages, and will eventually have around 100 components to keep track of.
I downloaded/uploaded code and modified to suit my needs, here is code
const int d = 200;
const int ledPin = 13;
const int pin12 = 12;
const int pin11 = 11;
const int pin10 = 10;
const int pin9 = 9;
SoftwareSerial softSerial(2, 3); //RX, TX: Connect Arduino pin 2 to scanner TX pin. Connect Arduino pin 3 to scanner RX pin.
#include "SparkFun_DE2120_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_DE2120
#define BUFFER_LEN 40
Serial.println("DE2120 Scanner Example 1 working");
if (scanner.begin(softSerial) == false)
Serial.println("Scanner did not respond. Please check wiring. Did you scan the POR232 barcode? Freezing...");
if (scanner.readBarcode(scanBuffer, BUFFER_LEN))
Serial.print("Code found: ");
for (int i = 0; i < strlen(scanBuffer); i++)
Serial.print("\t Locomotive: ");
if (scanBuffer == ('0') && scanBuffer == ('0') && scanBuffer == ('1'))
Serial.print("V 80 007");
if (scanBuffer == ('0') && scanBuffer == ('0') && scanBuffer == ('2'))
Serial.print("V 100 2263");
if (scanBuffer == ('0') && scanBuffer == ('0') && scanBuffer == ('3'))
Serial.print("BR 94 713");
if (scanBuffer == ('0') && scanBuffer == ('0') && scanBuffer == ('4'))
Serial.print("BR 196 178-0");
Can anyone help with improving the if(scanBuffer == …) portion, I have been trying many things. Thought I could use a for loop to run through the array and give me a single number such as 001 to the use in the if statement but I can’t make it work (I am only self taught). The example shown seems to be the only way I can do this reliably, but I’m sure it could be improved/ condensed and with 100 components or more this method takes lots of time/space.
Hmmm, this method would be rather cumbersome for large amounts of data, you will eventually run out of space on your Arduino to store these entries. Personally, if I was doing this project I would actually create a Microsoft Excel spreadsheet and have python on a computer access this file. You could then have the scanner linked via a serial connection to your computer so when you scan a barcode on one of your locomotives/carriages is scanned it is passed back to the computer where python pulls up the line with all of the information about it from the excel spreadsheet. The useful part about this is that you can manually modify/add/remove different items from this list in excel without having to worry about formatting code.
Here is a handy link on how to program python to work with excel spreadsheets:
I love this idea, have been thinking I may be starting to ask to much from Arduino! My experience in programming is very small, would like to know more and learning python already sounded interesting.
Before I dive in can I do this with raspberry pi instead of a computer? If not I’m using a MacBook Pro does that change anything ?
The Pi is essentially a computer, it usually runs a distro of Linux and is a tiny ARM device with all of the onboard parts required to operate independently. As for programming an Arduino from a OSx device such as a MacBook, yes, there shouldn’t be any problems with installing the IDE for Mac and flashing the board that way. Otherwise, I’d take a look at this tutorial on Arduino, should answer all of your questions about using the Pi to control an Arduino and program it. Have a Merry Christmas!
Ok, sorry to be a simpleton I have been programming Arduino from MacBook and my thoughts were to replace it with Pi so to leave it permanently installed in the system. I know nothing about Pi and will start reading.
The Raspberry Pi is its own computer with the capability to program and run python onboard. You will need to plug it into a monitor and keyboard, or use a program such as VNC or Putty (or similar for OSx) to interact with it. If you’re new to using Raspberry Pi I’d take a look at our workshop, it’s completely free and should answer lots of questions regarding the applications of the Pi, and the link that @Bryce put up should cover how to use it to program your Arduino if you’re running and scripts on it. Please let us know if there’s anything else that you need, have a great day!
No worries, make sure to let us know if you have any further questions, and feel free to send through your project to the site if you’d like (There’s a store credit reward if it goes online) Have a Merry Christmas!
Im extremely interested in your project, Can I copy what you are doing I was thinking about a similar project and your experience and know how would help me a lot.
Could you tell me what parts I would need to copy your barcode scanner setup with Arduino?
Thanks for your time I am interested in how you got to where you are so far. so to speak, What would I need to catch up? I thinking because I haven’t seen a image of your hardware you have set up. I think you have a 2D Barcode Scanner Module - DE2120 and you have programed it with
You have a laptop and programed the DE2120 from it?
Where do you get the barcodes from and how do you program them?
Can you tell me what to buy to catch up to your project please?
I see this https://www.sparkfun.com/products/16441
Maybe this is what I need to start with?
I will be using openpyxl because as Mitchell said how easy it is to ad additional products in your case could be unlimited train carriages with different products.
I will be reading up on the above suggestions people have submitted.
I would be trying to use the scanner with objects in motion YES
Jason’s original setup was a DE2120 Scanner connected to an Arduino via serial.
Now I believe Jason is connecting the Arduino to a computer to pass on the barcode number to an excel spreadsheet which will have a data entry containing all the information about that part corresponding to the barcode number. This will be done using a python script.
Potentially it could be a google sheet, but I would reccomend starting out with excel as that way it is on a local machine and you don’t have to access the internet. as for an RFID reader here is a super neat one that is usb: https://core-electronics.com.au/rfid-usb-reader.html
That video was a good example explanation of the RFID USB Reader.
I need a programmable RFID tag and the waterproof could be an advantage.
I really want and need a long range scan that could scan from a metre or so if possible.
I really want to copy Jason’s project and incorporate RFID as well as the barcode scan.
Like buying an item from a store. You scan the barcode and it shows the product. You buy the product and the customer walks past the RFID scanner and the RFID tag gets scanned and shows the customer left the store from ( RFID scanner ID NUMBER door 3)
Do you have the parts I need for this project?
I will send through some info after Christmas with pics ( no time now) and I’m also incorporating a rfid scanner in the system.
As for the barcodes I print my own with a label printer that has barcode capabilities, you can choose different types of codes, size, laminated(waterproof), and of course write whatever you need.
I’m waiting for the rfid scanner arrive, I chose the ID 3-LA for the range I’m looking for and also so I can make a custom antenna.