Last active
June 17, 2018 10:09
-
-
Save boochow/1ee1edfc5087eec5c051b3c98d647288 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MCP3204: | |
def __init__(self, spi, cs): | |
self.spi = spi | |
self.cs = cs | |
def read(self, ch): | |
cmd = 6 | (ch >> 2) | |
par = (ch << 6) & 0xff | |
send = bytearray([cmd, par, 0]) | |
recv = bytearray(3) | |
self.cs.value(0) | |
self.spi.write_readinto(send, recv) | |
self.cs.value(1) | |
return int.from_bytes(recv, 'big') | |
from machine import SPI, Pin | |
from time import sleep | |
spi=SPI(0) | |
cs=Pin(22, Pin.OUT) | |
adc=MCP3204(spi,cs) | |
while(True): | |
print(adc.read(0)) | |
sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment