trng_read_json.py
1 # SPDX-FileCopyrightText: 2021 Carter Nelson for Adafruit Industries 2 # 3 # SPDX-License-Identifier: MIT 4 5 import json 6 import serial 7 8 # open serial port 9 ss = serial.Serial("/dev/ttyACM0") 10 11 # read string 12 _ = ss.readline() # first read may be incomplete, just toss it 13 raw_string = ss.readline().strip().decode() 14 15 # load JSON 16 json_data = json.loads(raw_string) 17 18 # print data 19 print(json_data['trng'])