Programming a serial number

Go To Last Post
22 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi fellow freaks,
Looking to see if anyone has done this, before jumping into the project.
We need to record a board serial number either into the flash or eeprom so it can be read and displayed via a serial data stream sent out the usart.
One idea is to place a bar code label on the board and then scan it and send the serial number via a serial connection to the atmega and record this to the eeprom, but not all systems have a serial data in available on the board, but all have an isp connection.
We normally use atmega48/88/168/328's and program them in production using dos batch files, and the stk500 command line programming using avrisp mkii's.
Any ideas are welcome.

TIA
Jim

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You could write some desktop app to modify *.hex before each programming. Connect it with a bar-code scanner and call dude with modified hex.

No RSTDISBL, no fun!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

You could write some desktop app to modify *.hex before each programming. Connect it with a bar-code scanner and call dude with modified hex.


I have one series of apps where RF addressing was set with a PC program, similar to what Brutte proposed. It was a bit different--I modified the .EEP (CodeVision), searching for the addressing record. Then that was output. The PC program was connected to the unit, and command-line STK500.EXE was called. A real pain to capture and interpret the results...

Anyway, another alternative is to have the initial unit programming have an "erased" serial number area, all 0xff. Then, you can construct a new .EEP (HEX file with the serial number information, and program EEPROM "right over the top" (no erase first) of the designated area.

Try to hunt out past discussions.

https://www.avrfreaks.net/index.p...
https://www.avrfreaks.net/index.p...
https://www.avrfreaks.net/index.p...
https://www.avrfreaks.net/index.p...
...

Note that there are discussions of alternate approaches:
-- Build for each serial number by generating/modifying a source file
-- Send the serial number to the unit ala bootloader command

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the links, they were helpful. Writing a Windose pc app though is out of my league. I need to look at the scanner and see what interface it uses, if it's serial, I may be able to use a sniffer app on an arduino to capture the data and then write to the isp on the target to program the bytes of eeprom space needed to hold the serial number.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I need to look at the scanner and see what interface it uses

It is usually USB HID by default. At least that is what my Symbol LS4208 does.
Quote:
and then write to the isp on the target

Seems over-engineered. What about saving on HDD the already programmed boards' numbers, the error management etc?

No RSTDISBL, no fun!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you do not need the bar code, the real issue is how you produce a sequence of hex files.

Your dos file:

awk -f increment.awk sn.txt > sn2.txt
remove sn.txt
rename sn2.txt sn.txt
awk -f hex.awk sn.txt > sn.eep
stk500 ...

sn.txt is a one line file containing a serial number.
increment.awk is an awk script for incrementing the integer on a line.
hex.awk is an awk script for converting a one-line integer into a hex file.
sn.eep is a hex file for the serial number in sn.txt

"Demons after money.
Whatever happened to the still beating heart of a virgin?
No one has any standards anymore." -- Giles

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Seems over-engineered.

IMO/IME -- It depends. As always. ;)

If the volumes are modest, and there is a reliable/experienced work force, then it might well be cost effective to have the experienced person do a set of steps "manually". E.g. read the bar code, perhaps log into spreadsheet or whatever, and use a mechanism (such as rebuilding from source) to get it into the AVR unit.

But there will be a critical point somewhere (probably dependent on volume) where the "manual" method might become onerous or expensive or error-prone and building a tool might be better.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
clawson@ws-czc1138h0b:/windows$ uuidgen > foo.txt
clawson@ws-czc1138h0b:/windows$ avr-objcopy -I binary foo.txt -O ihex foo.hex
clawson@ws-czc1138h0b:/windows$ cat foo.hex
:1000000066353433373564372D366664642D34668F
:1000100038362D613366662D303735656333396187
:05002000616431630A78
:00000001FF
clawson@ws-czc1138h0b:/windows$ uuidgen > foo.txt
clawson@ws-czc1138h0b:/windows$ avr-objcopy -I binary foo.txt -O ihex foo.hex
clawson@ws-czc1138h0b:/windows$ cat foo.hex
:1000000032346632626262322D323734652D3431D9
:1000100035342D623366332D3332336434623838ED
:05002000383735360AF7
:00000001FF

A different (guaranteed!) winner every time.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

A different (guaranteed!) winner every time.

You lost me -- uuigen is a random number?

What does that have to do with embedding the serial number from a bar-code sticker into the AVR?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

uuigen is a random number?

UUIDs are guaranteed unique numbers:

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

Quote:
In other words, only after generating 1 billion UUIDs every second for the next 100 years, the probability of creating just one duplicate would be about 50%. The probability of one duplicate would be about 50% if every person on earth owns 600 million UUIDs.

So if you want to give something a unique personality so it can be uniquely identified then a UUID is one way to do that.

For example Windows and Linux now do this so they can identify the hard drives in your system. Each has a unique UUID:

clawson@ws-czc1138h0b:/windows$ blkid
/dev/sdb1: UUID="3b1ca4ef-2e6f-443e-a7a9-ff93939800f0" TYPE="swap" 
/dev/sdh1: LABEL="IOMEGA-EXT" UUID="ac150ac3-989a-4b41-9dec-146b99ef0a79" SEC_TYPE="ext2" TYPE="ext3" 
/dev/sdh2: LABEL="IOMEGA-NTFS" UUID="484409054408F808" TYPE="ntfs" 

So even if the same mechanism mounts as /dev/sdc one day and /dev/sde the next because I added a hard drive then the mechanism that boots Linux can still find it as ac150ac3-989a-4b41-9dec-146b99ef0a79.

Meanwhile Windows is stuffed full of the things too. Almost everything in the registry is accessed via UUID, for example:

clawson@ws-czc1138h0b:/windows$ cat foo.reg
��Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers\Notepad++]
@="{00F3C2EC-A6EE-11DE-A03A-EF8F55D89593}"

So if you want to give something a unique identity give it a UUID.

Of course the downside is that they are "big" numbers. One identity above would use 36 bytes of EEPROM if just encoded in the ASCII: "7694ef75-f5ea-4352-8151-348b9d11107f". It'd still be 32 bytes if you removed the customary hyphens but could be 16 bytes (128 bits) if you just used the core binary number.

If EEPROM space wasn't an issue I doubt it would matter.

BTW I've just been learning to use Git and reading the "bible" and found this tasty morsel about SHA1 hashes which I guess are kind of similar to UUIDs:

http://git-scm.com/book/en/Git-T...

I especially loved:

Quote:
A higher probability exists that every member of your programming team will be attacked and killed by wolves in unrelated incidents on the same night.

Last Edited: Tue. Jul 9, 2013 - 04:56 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

UUIDs are guaranteed unique numbers:

Cool. But again:
Quote:

What does that have to do with embedding the serial number from a bar-code sticker into the AVR?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I was simply responding to Michael's post about creating unique identities with a possibly easier to implement mechanism.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It seems the key to clawson's technique is the avr-objcopy program. If you use the barcode scanner to make the foo.txt, then it would get the serial number from the barcode scanner. Perhaps "copy con:..."

The largest known prime number: 282589933-1

It's easy to stop breaking the 10th commandment! Break the 8th instead. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Could one make the barcode/serial number from the uuid?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A UUID is useful for creating unique numbers in multiple locations without centralized control. If you have full control of production it would be more useful to create a numbering scheme that contains useful information. Consider the following basic system:

4-digit product number
2-digit year
2-digit week of year
n-digit serial number for the week

Encode this as BCD or binary in the device. You can come up with something more elaborate with check digits or additional fields but the idea is to encode information that could be useful when the device comes back for service without needing access to the production database. A UUID won't do that for you.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
I was simply responding to Michael's post about creating unique identities with a possibly easier to implement mechanism.
If clawson's method is adequate, that is what should be used.
It is more completely specified, requires less intellectual effort and obviously does what is claimed.
The three are related.

I was focused on the serial part of the question.
If I read the original post correctly, bar codes are not part of the specification,
they are a speculated part of the solution.
If, for whatever reason, long arbitrary numbers are inadequate, OP will need a way to generate the sequence.
I picked awk because it comes with winAVR.
That said, OP should skip my second awk. Use objcopy to convert text to hex.

"Demons after money.
Whatever happened to the still beating heart of a virgin?
No one has any standards anymore." -- Giles

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jccordill wrote:
... Writing a Windose pc app though is out of my league.

Writing a windows pc app doesn't have to be "out of my league".

You could use Pelles C (a free download) and write a 'Console' app which eliminates the complexity of the GUI interface.

This would give you the versatility of reading the scanner (looks like keyboard input), reading and writing to the serial port, and invoking other PC programs such as avrdude.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok. Tomorrow's project: Read this thread carefully and figure out how either CLawson's or Skeeve's idea works as I want to do something similar myself.

The largest known prime number: 282589933-1

It's easy to stop breaking the 10th commandment! Break the 8th instead. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would go with the barcode sticker
scan that
write the bar code to eeprom
if you have no other information in your eeprom or that information is always the same you should be able to do it through the ISP connection.
you could also add a small piece of code to your main program that if the location for the serial number is empty then you have SPI (same connections as ISP on most devices) enabled and then use a second controler to write data to it. then restart and have SPI disabled to be sure that the serial number is not overwritten

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I would go with the barcode sticker

We've actually done this in production but the "other way round". Digital TV systems, as part of their security, have a unique ID number in the core silicon of each device so in production we had a process that read that number from the chip and then printed a bar-code sticker (several copies in fact) with the number encoded that was used both on the cabinet of the unit and also on the outside of the carriage box.

I know that Xmega and UC3 have unique serial numbers generated by Atmel as part of the fabrication process. Sadly I don't think tiny/mega have this though.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks guys, kevinpt is close to what we want to do, only the barcode gen s/w provides yymmxxxxxx encoding the year,month and serial number to be recorded. Chuck99, I'll look into making a console program, sounds like something I can do. If I can work it out, I'll post an update and perhaps a project with the details of how I did it. Thanks for the help.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I need 40 bits of "ID." Maybe I should just make a hash code of the xMega's serial number info.

"You'll make a perfect hash of things!"

The largest known prime number: 282589933-1

It's easy to stop breaking the 10th commandment! Break the 8th instead.