Connecting our magnetic contact sensor
Now that we've got our port expander working with the Raspberry Pi, we can start connecting things to it and create the scripts that will monitor the sensors on the input pins.
Let's go back to our port expander stripboard that was built in the previous chapter and connect our magnetic sensor. But first, we need to ensure that all of our inputs are pulled low by default using 10Kohm resistors. This prevents them from being in a floating state and giving us spurious data when we read the port's data.
Note
In the following diagram, I've connected the pull-down resistors externally, but you may want to include them directly on the stripboard. Toward the end of this book, we'll have a new board layout that brings everything that we've been prototyping so far together in a single solution.
To check the port's input value, we use the i2cget
command:
$ sudo i2cget –y 1 0x20 0x12
This should return 0x00
, which means all inputs are off (binary %00000000).
Note
What...