/ examples / avrprog_program_tiny13a.py
avrprog_program_tiny13a.py
 1  """
 2  ATtiny13a programming example, be sure you have the '13a wired up so:
 3    ATtiny13a GND to CircuitPython GND
 4    ATtiny13a VCC to CircuitPython USB
 5    Pin 2 -> CircuitPython SCK
 6    Pin 1 -> CircuitPython MISO
 7    Pin 0 -> CircuitPython MOSI
 8    RESET  -> CircuitPython D5 (or change the init() below to change it!)
 9  Drag "attiny13a_blink.hex" onto the CircuitPython disk drive, then open REPL!
10  """
11  
12  import board
13  import busio
14  import adafruit_avrprog
15  
16  spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
17  avrprog = adafruit_avrprog.AVRprog()
18  avrprog.init(spi, board.D5)
19  
20  # Each chip has to have a definition so the script knows how to find it
21  attiny13 = avrprog.Boards.ATtiny13a
22  
23  
24  def error(err):
25      """ Helper to print out errors for us and then halt """
26      print("ERROR: " + err)
27      avrprog.end()
28      while True:
29          pass
30  
31  
32  while input("Ready to GO, type 'G' here to start> ") != "G":
33      pass
34  
35  if not avrprog.verify_sig(attiny13, verbose=True):
36      error("Signature read failure")
37  print("Found", attiny13["name"])
38  
39  avrprog.write_fuses(attiny13, low=0x7A, high=0xFF)
40  if not avrprog.verify_fuses(attiny13, low=0x7A, high=0xFF):
41      error("Failure verifying fuses!")
42  
43  print("Programming flash from file")
44  avrprog.program_file(attiny13, "attiny13a_blink.hex", verbose=True, verify=True)
45  
46  print("Done!")