Page 1 of 1

Read 2 or more pins as binary bits

Posted: Mon Jun 04, 2018 5:29 am
by devnull
Is there a simple was to combine 2 or more pins together as a virtual port and read as binary bits ?

I am using a PIC micro to do some things outside of micropython and one of the things it will do is to output a 2 bit value (0 to 3) which I would like to read in micropython.

Re: Read 2 or more pins as binary bits

Posted: Mon Jun 04, 2018 7:15 am
by OutoftheBOTS_
I would assume that you would do something like this

Code: Select all

two_bits = pin1.value() <<1 | pin2.value()

Re: Read 2 or more pins as binary bits

Posted: Mon Jun 04, 2018 10:55 am
by pythoncoder
That would be my approach.

If speed is vital it is possible to access multi-bit I/O but it isn't for the faint-hearted; it certainly needs a study of the chip datasheet. An example may be found here in the file TFT_io.py.