Skip to content

Commit 2fb42c1

Browse files
author
brentru
committed
Add updated simpletest
1 parent 7f91693 commit 2fb42c1

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

adafruit_atecc/adafruit_atecc.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,7 @@ def sha_update(self, message):
372372
into the hash operation.
373373
374374
"""
375-
if not hasattr(message, "append"):
376-
message = pack("B", message)
377375
self.wakeup()
378-
assert len(message) == 64, "Message provided to sha_update must be 64 bytes"
379376
self._send_command(OP_SHA, 0x01, 64, message)
380377
time.sleep(EXEC_TIME[OP_SHA]/1000)
381378
status = bytearray(1)

examples/atecc_simpletest.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,34 @@
1-
# testing adafruit atecc module
2-
import board
3-
import adafruit_atecc
4-
import busio
5-
6-
7-
_WAKE_CLK_FREQ = 100000 # slower clock speed
8-
i2c = busio.I2C(board.SCL, board.SDA, frequency=_WAKE_CLK_FREQ)
9-
10-
adafruit_atecc.ATECCx08A(i2c)
1+
import board
2+
import busio
3+
import time
4+
import adafruit_ssd1306
5+
from adafruit_atecc.adafruit_atecc import ATECC, _WAKE_CLK_FREQ
6+
7+
# Initialize the i2c bus
8+
i2c = busio.I2C(board.SCL, board.SDA,
9+
frequency=_WAKE_CLK_FREQ)
10+
11+
# Initialize a new atecc object
12+
atecc = ATECC(i2c)
13+
14+
print("ATECC Serial: ", atecc.serial_number)
15+
16+
# Generate a random number with a maximum value of 1024
17+
print("Random Value: ", atecc.random(rnd_max=1024))
18+
19+
# Print out the value from one of the ATECC's counters
20+
# You should see this counter increase on every time the code.py runs.
21+
print("ATECC Counter #1 Value: ", atecc.counter(1, increment_counter=True))
22+
23+
# Initialize the SHA256 calculation engine
24+
atecc.sha_start()
25+
26+
# Append bytes to the SHA digest
27+
print("Appending to the digest...")
28+
atecc.sha_update(b"Nobody inspects")
29+
print("Appending to the digest...")
30+
atecc.sha_update(b" the spammish repetition")
31+
32+
# Return the digest of the data passed to sha_update
33+
message = atecc.sha_digest()
34+
print("SHA Digest: ", message)

0 commit comments

Comments
 (0)