
This has used the mask to screen out the junk as before, and shift to the right by 2 places to get the result as a 1 or 0.Īctually there is an easier way. Bitwise AND is & NOT & which is logic AND. If you AND a bit with 0, the result will always be 0 because 1 AND 0 is 0. This is a byte of 0’s but a 1 in the position where we want to extract a single bit. Let’s say we wanted to fetch a pin from port A but we are only interested in bit 2 (3rd bit from the right). Serial.print(bitRead(inByte, b)) //now prints: 00011101 Please note that & is very different from &, as is|(OR) is different from ||.

We will look at some seldom-used tools to do that. By that, I mean you read all 8 bits at once and then have to single out the bit or pin you wanted. In this project, we are confronted with two byte-wide ports that can only be written/read in a port-wide or byte-wide manner. It’s easy to forget that they are actually 8-bit wide ports. If you have spent some time programming the Arduino, you may be very familiar with reading and writing to ports in a bit by bit manner, e.g. And the chip has three selectable address lines so we can set it up with 2 3 = 8 possible addresses, or put additional MPC23017 chips on the same I 2C line. Its wire library takes care of the communication. The MPC23017 contains two 8-bit bi-directional ports which can be connected to the Arduino with an I 2C interface. For example, a 3Gbit/s port might have a hub or expander installed and now be able to accommodate 6 devices, but at a maximum of 3Gbit/s throughput bandwidth divided by the said 6 devices, or by however many are plugged in and being used. A port expander is like the extension cord (in the non-computer world) that allows more than one device to connect to a single port on a computer.
