I am about to populate my first board and I had a box with quite a few parts waiting for me, so I had to organize them a little bit. What I usually do is to lookup every part in the web and copy the most important info (part number, description, quantity, link to datasheet) to a spreadsheet.
Part numbers are quite long and it is cumbersome to enter them in google or the provider's search form. The plastic bags usually have labels with a QR code which contains info about the part (and order). A quick check with the typical QR Reader apps on Android showed they were able to read the codes without problems. They look like this in the case of DigiKey, Mouser is similiar but less info:
[)> 06 P1276-1034-1-ND 1PCL10A105KO8NNNC K 1K74918428 10K88364026 11K1 4LCN Q50 11ZPICK 12Z3889120 13Z565853 20Z000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000 0000000000000000000
But now I needed these codes on my PC, extract the part numbers and ideally create a link to a google (or digikey/mouser) search. I came up with a very simple workflow which works quite nicely so far:
- Create a Telegram bot to receive the messages on my phone as well as on my PC (use Telegram Web)
- Use regular expressions in the bot to extract the necessary data
- print a formatted messages which includes a link to a google search with the part number
I used python to interact with the bot api. First install dependencies:
pip install python-dotenv
pip install pyTelegramBotAPI
Provide a file ".env" with your api key (that key is generated when creating the bot)
BOT_API_KEY = "your key here"
Now create a python file, say "bot.py":
import telebot
import re
import os
from dotenv import load_dotenv
load_dotenv()
BOT_API_KEY = os.getenv('BOT_API_KEY')
bot = telebot.TeleBot(BOT_API_KEY)
digikey_raw = r'\[\)> 06 P([a-zA-Z0-9-.]+)\s1P([a-zA-Z0-9-]+)'
mouser_raw = r'\[\)> 06 K([a-zA-Z0-9-]+)\s14K([a-zA-Z0-9-]+)\s1P([a-zA-Z0-9-]+)'
regex_digikey = re.compile(digikey_raw)
regex_mouser = re.compile(mouser_raw)
@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
bot.reply_to(message, "Scan a QR code and share the text with me!")
@bot.message_handler(regexp=digikey_raw)
def handle_message(message):
matches = regex_digikey.search(message.text)
text = "DigiKey Part: https://www.google.com/search?q=" + matches[2]
bot.reply_to(message, text)
@bot.message_handler(regexp=mouser_raw)
def handle_message(message):
matches = regex_mouser.search(message.text)
text = "Mouser Part: https://www.google.com/search?q=" + matches[3]
bot.reply_to(message, text)
bot.infinity_polling()
I have just guessed the regular expressions from what I have seen in the texts, maybe this needs some adjustments. Now, run the python script:
python3 bot.py
On your mobile phone, scan the QR code, and "share" the text with Telegram -> Your bot. The message is sent to the bot chat, the script "sees" the message in the corresponding message handler and prints out a link to a search in google with the part number as search text which you can use on your phone or PC to get all info for the scanned part.
Of course we can extract more information (order number, quantity etc) and the python script can be improved a lot, but this is just a quick and simple hack to get fast access to the part (and datasheet etc) by using what we all have available (a phone, Telegram and python). Maybe it is useful to someone, so I thought I'd share.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.