Simple test¶
Ensure your device works with this simple test.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
"""
Read Signature Test - All this does is read the signature from the chip to
check connectivity!
"""
import board
import busio
import pwmio
import adafruit_avrprog
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
avrprog = adafruit_avrprog.AVRprog()
avrprog.init(spi, board.D5)
# pylint: disable-msg=no-member
# we can generate an 6 MHz clock for driving bare chips too!
clock_pwm = pwmio.PWMOut(board.D9, frequency=6000000, duty_cycle=65536 // 2)
# pylint: enable-msg=no-member
avrprog.begin()
print("Signature bytes: ", [hex(i) for i in avrprog.read_signature()])
avrprog.end()
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
"""
Trinket/Gemma (ATtiny85) programming example, be sure you have the '85 wired up so:
Trinket Ground to CircuitPython GND
Trinket USB to CircuitPythong USB or make sure the Trinket is powered by USB
Pin 2 -> CircuitPython SCK
Pin 1 -> CircuitPython MISO
Pin 0 -> CircuitPython MOSI
RESET -> CircuitPython D5 (or change the init() below to change it!)
Drag "trinket_boot.hex" onto the CircuitPython disk drive, then open REPL!
"""
import board
import busio
import adafruit_avrprog
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
avrprog = adafruit_avrprog.AVRprog()
avrprog.init(spi, board.D5)
# Each chip has to have a definition so the script knows how to find it
attiny85 = avrprog.Boards.ATtiny85
def error(err):
""" Helper to print out errors for us and then halt """
print("ERROR: " + err)
avrprog.end()
while True:
pass
while input("Ready to GO, type 'G' here to start> ") != "G":
pass
if not avrprog.verify_sig(attiny85, verbose=True):
error("Signature read failure")
print("Found", attiny85["name"])
avrprog.write_fuses(attiny85, low=0xF1, high=0xD5, ext=0x06, lock=0x3F)
if not avrprog.verify_fuses(attiny85, low=0xF1, high=0xD5, ext=0x06, lock=0x3F):
error("Failure verifying fuses!")
print("Programming flash from file")
avrprog.program_file(attiny85, "trinket_boot.hex", verbose=True, verify=True)
print("Done!")
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
"""
UNO Optiboot programming example, be sure you have the UNO wired up so:
UNO Ground to CircuitPython GND
UNO 5V to CircuitPython USB or make sure the UNO is powered by USB
UNO Pin 13 -> CircuitPython SCK
UNO Pin 12 -> CircuitPython MISO
UNO Pin 11 -> CircuitPython MOSI
UNO RESET -> CircuitPython D5 (or change the init() below to change it!)
Drag "optiboot_atmega328.hex" onto the CircuitPython disk drive, then open REPL!
"""
import board
import busio
import pwmio
import adafruit_avrprog
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
avrprog = adafruit_avrprog.AVRprog()
avrprog.init(spi, board.D5)
# pylint: disable-msg=no-member
# we can generate an 6 MHz clock for driving bare chips too!
clock_pwm = pwmio.PWMOut(board.D9, frequency=6000000, duty_cycle=65536 // 2)
# pylint: enable-msg=no-member
# Each chip has to have a definition so the script knows how to find it
atmega328p = avrprog.Boards.ATmega328p
def error(err):
""" Helper to print out errors for us and then halt """
print("ERROR: " + err)
avrprog.end()
while True:
pass
while input("Ready to GO, type 'G' here to start> ") != "G":
pass
if not avrprog.verify_sig(atmega328p, verbose=True):
error("Signature read failure")
print("Found", atmega328p["name"])
# Since we are unsetting the lock fuse, an erase is required!
avrprog.erase_chip()
avrprog.write_fuses(atmega328p, low=0xFF, high=0xDE, ext=0x05, lock=0x3F)
if not avrprog.verify_fuses(atmega328p, low=0xFF, high=0xDE, ext=0x05, lock=0x3F):
error(
"Failure programming fuses: "
+ str([hex(i) for i in avrprog.read_fuses(atmega328p)])
)
print("Programming flash from file")
avrprog.program_file(atmega328p, "optiboot_atmega328.hex", verbose=True, verify=True)
avrprog.write_fuses(atmega328p, lock=0x0F)
if not avrprog.verify_fuses(atmega328p, lock=0x0F):
error("Failure verifying fuses!")
print("Done!")
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
"""
Arduino Mega 2560 programming example, be sure you have the Mega/2560 wired up so:
Mega Ground to CircuitPython GND
Mega 5V to CircuitPython USB or make sure the Trinket is powered by USB
Pin 52 -> CircuitPython SCK
Pin 50 -> CircuitPython MISO - Note this is backwards from what you expect
Pin 51 -> CircuitPython MOSI - Note this is backwards from what you expect
RESET -> CircuitPython D5 (or change the init() below to change it)
Drag "stk500boot_v2_mega2560.hex" onto the CircuitPython disk drive, then open REPL
"""
import board
import busio
import adafruit_avrprog
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
avrprog = adafruit_avrprog.AVRprog()
avrprog.init(spi, board.D5)
# To program a chip, you'll need to find out the signature, size of the flash,
# flash-page size and fuse mask. You can find this in the datasheet or in
# avrdude.conf located at:
# http://svn.savannah.nongnu.org/viewvc/*checkout*/avrdude/trunk/avrdude/avrdude.conf.in
# You can also use the predefined values in AVRprog.Boards
atmega2560 = {
"name": "ATmega2560",
"sig": [0x1E, 0x98, 0x01],
"flash_size": 262144,
"page_size": 256,
"fuse_mask": (0xFF, 0xFF, 0x07, 0x3F),
}
def error(err):
""" Helper to print out errors for us and then halt """
print("ERROR: " + err)
avrprog.end()
while True:
pass
while input("Ready to GO, type 'G' here to start> ") != "G":
pass
if not avrprog.verify_sig(atmega2560, verbose=True):
error("Signature read failure")
print("Found", atmega2560["name"])
# Since we are unsetting the lock fuse, an erase is required!
avrprog.erase_chip()
avrprog.write_fuses(atmega2560, low=0xFF, high=0xD8, ext=0x05, lock=0x3F)
if not avrprog.verify_fuses(atmega2560, low=0xFF, high=0xD8, ext=0x05, lock=0x3F):
error(
"Failure programming fuses: "
+ str([hex(i) for i in avrprog.read_fuses(atmega2560)])
)
print("Programming flash from file")
avrprog.program_file(
atmega2560, "stk500boot_v2_mega2560.hex", verbose=True, verify=True
)
avrprog.write_fuses(atmega2560, lock=0x0F)
if not avrprog.verify_fuses(atmega2560, lock=0x0F):
error("Failure verifying fuses!")
print("Done!")
|