I’m using a MaxBotix EV4 to measure distance, and it has a very simple three pin system of +ve, GND and Tx. I’ve configured the Imp to use Uart12 connecting Pin2 (Rx) to the Maxbotix Tx (actually, there an inverter in between). However, I’m desperate for I/O pins and wondered if I could also configure Pin1 as a DIGITAL_IN as I have no need to Tx to anything. Is it possible to only use half a UART ?
You can either configure the whole UART, then reconfigure something over the top of it (as jwehr suggests), or you can configure just half-a-UART in the first place: http://electricimp.com/docs/api/hardware/uart/configure/ (NO_TX or NO_RX flags). Both ways are perfectly valid, but I suppose the second makes your code a bit clearer.
I’ve also wondered about reconfiguring pins during program execution…back and forth. I haven’t needed to do that yet, and I suppose it would be on a case by case basis, but the Imp wouldn’t have any issues with say, flipping back and forth between spi257, and uart57 would it?
Peter, thanks for reference. I like the idea of specifying NO_TX following by another configure () on Pin2 for DIGITAL_IN which as you suggested, will make the code clearer. Thanks to all. Will have a go over the weekend.
The result. It Works.
`DistanceSensor <- hardware.uart12; // Only need RX (Pin2)
MatrixDisplay <- hardware.uart57;
DoorController <- hardware.pin1;