Files
mraa/examples/python/spi.py
Thomas Ingleby 170bdd104f spdx: add spdx tags to most files
Large change that removes the duplicated MIT notice withe a spdx tag

Signed-off-by: Thomas Ingleby <thomas.ingleby@intel.com>
2019-05-23 10:09:12 -07:00

29 lines
519 B
Python

#!/usr/bin/env python
# Author: Henry Bruce <henry.bruce@intel.com>
# Copyright (c) 2016 Intel Corporation.
#
# SPDX-License-Identifier: MIT
# Example Usage: Read from MCP3004 ADC pin 0 in single ended mode
import mraa
import time
# initialise SPI
dev = mraa.Spi(0)
# prepare data to send
txbuf = bytearray(3)
txbuf[0] = 0x01
txbuf[1] = 0x80
txbuf[2] = 0x00
while True:
# send data through SPI
rxbuf = dev.write(txbuf)
value = ((rxbuf[1] & 0x03) << 8) | rxbuf[2]
print(value)
time.sleep(0.5)