How I Made a Pantry Inventory with a Barcode Scanner and Google Sheets
Like usual,
My My dream is to write technical blogs the way food bloggers share recipes. This is more of a adventure than a practical learning experience (like LinkedIn!)
prepare for yapping (but sometimes its funny!)
I pick up a lot of shit that I don't need. I'm like a middle-aged dad with a trunk full of 2x4s, except mine are tech parts. I just can't not do it.
Instead of the hardware store being the source for me, it's typically goodwill and used electronic stores.
This sometimes works out in my friends' favor though, as I often already have the part they're looking for.
Anyways, today's metaphorical 2x4 was a receipt printer.
Since I don't pay rent, I do a lot of problem-solving for my parents. In exchange, I'm the favorite (and only) child. (And I don't get kicked out, win-win!)
One of the most boring jobs is taking inventory of a food pantry. Nobody wants to count cans with a clipboard. so why not make it more engaging with a barcode scanner?
problem: There isn't that much great inventory software for (smaller) pantries. This closet doesn't need industrial warehouse managment software for cans. And I most definitely didn't want to write my own. (I have three days until I move to my college dorm and I've barely packed)
You know whats easy? Google Sheets.
I made a sheet. Maybe I should write a LinkedIn skills endorsment for myself after this, but for now I'll speedrun my tour
You enter barcodes scanned here. There are no cool formulas on this page
The page that shows Sums for what you've scanned. There are two cool formulas.
=IF(COUNTA(Enter!A:A)=0,
{"Barcode","Count"},
QUERY(Enter!A:A, "select A, count(A) where A is not null group by A order by count(A) desc label A 'Barcode', count(A) 'Count'", 1)
)
We query the Enter
sheet page for counts of each unique barcode. The outer IF
fixes a display quirk when the sheet is empty
=ARRAYFORMULA(IF(A2:A="",,VLOOKUP(A2:A, Lookup!A:B, 2, FALSE)))
This looks up the barcode in the third table. I love VLOOKUP
, its my second favorite function after QUERY
, but still a close second.
The third table is just key-value pair mapping barcode -> text (write what the barcode corresponds to in that text)
Lookup table! Not thrilling, but it works.
This was all way better than writing bespoke software to solve a very specific problem (again... https://github.com/cghs-hackclub/ClassCall ).
Great. now we have a inventory system that can rival exel documents with user logins and passwords.1
The only problem: My barcode scanner was pressing tab after each scan.
For those who don’t know, barcode scanners are glorified keyboards. They just type the barcode after scanning it. Pretty neat.
Of course I did what any slightly-questionable developer would do: I asked ChatGPT. It responded with an abundance of em-dashes:
You’ll need to reconfigure the scanner: Check the manual for your model (every scanner has a programming guide with special barcodes you scan to change settings).
There is no way I can represent the awe I was in when I read these words, but lets just say my jaw was on the floor.
THERE ARE SPECIAL BARCODES TO PROGRAM THE BARCODE SCANNERS
It actually makes a ton of sense intuitively. its a input tool, you program it with input. I'm just so used to using jumpers and dip switches to program stuff, So this just felt next level 2
Anyways, back to secret barcodes.
The first documentation I found was this Datalogic sheet describing F-key barcodes.
Special barcodes that did things like,
This is just neat by itself, that special barcodes to do special things.
Then I found better docs.
Scanners have prefixes and suffixes. Think prefix/base/suffix like words (if this still doesn't make sense heres a worksheet). You can set them with special barcodes.
changing prefix/suffix happens something like this
Problem: cable too short. need long cable.
You might say, "Go back to goodwill and buy one of the 30 wireless ones that they have lying around" and I would reply,
"Past stockpile me to the rescue!"
USB extension cable over Cat5. up to 150 feet!
I'm honestly suprised that it can do power over such a long distance, color me suprised.
I call my freind exitedly, after all of my cool puzzle solving with the scanner, (that includes pretty much all the stuff I discovered above) and he just says,
"Thats how coupons work. I already knew that."
Okay Cole, Fuck you. I'm glad that pickle leaked over your burger the yesterday. That shit was cool. You're just mad you didn't get to do it. 3