Because the EZ1 has an RS-232 connection, it’s actually possible to connect it directly to the Redpark cable without using the Arduino board at all. The Redpark Serial Cable is wired in a standard fashion, terminating with a male DB-9 connector; the pin out for this connector is shown in Figure 4-11 and described in Table 4-1.
Table 4-1. The Redpark Serial Cable DB-9 (male) Connector Pin Out
Pin Number | Function | I/O | Description |
---|---|---|---|
1 | DCD | I | Data carrier detect |
2 | RX | I | Receive |
3 | TX | O | Transmit |
4 | DTR | O | Data terminal ready |
5 | GND | - | Ground |
6 | DSR | I | Data set ready |
7 | RTS | O | Request to send |
8 | CTS | I | Clear to send |
9 | RI | I | Ring indicator |
Comparing Figure 4-1 and Figure 4-11, we’ll need to wire up only 3 of the 9 available pins: GND, RX, and TX. Taking a female DB-9 connector, you should therefore wire it as in Figure 4-12. Comparing Figure 4-11 and Figure 4-12, you should notice that in the female connector, we wire pin 2 to TX and pin 3 to RX. This means that TX from the EZ1 is connected to RX on the cable, and vice versa.
After wiring this cable, go ahead and solder a header block onto the EZ1 sensor board (see Figure 4-13).
When wiring the EZ1 sensor, you should be careful not to obstruct the sensor head itself; doing so means that you’ll get inaccurate measurements when you power it on. Depending on your application, you may want to attach the header pins to the rear of the board or use a right angle header block so that there is no chance of obstructing the sensor.
Once you’ve soldered the header block to the sensor board, you should find an appropriate 3.3 V or 5 V power supply. I’m using 2 × 1.5 V batteries to provide a 3 V supply, which should be sufficient to test the sensor. We then need to gather our ground connections and power the sensor. The easiest way to do this is probably to use a breadboard (see Figure 4-14).
Now that the hardware is complete, let’s look and see what we need to do on the software side. Looking at the datasheet, we see that the output from the sensors is an ASCII capital “R”, followed by three ASCII character digits representing the range in inches (up to a maximum of 255), followed by a carriage return (ASCII character 13), for a message length of 5 bytes in total.
We’ve already written some software that will handle that sort of output just fine, our SerialConsole application from Chapter 2. Connect your Redpark cable to the female DB9 connector and to your iPhone and run the SerialConsole application. You should see something like Figure 4-15.
You’ll see that the datasheet isn’t strictly accurate; a copyright notice is displayed the first time the sensor is powered on. Good thing we checked. If you type something in the text entry widget and tap on send, you’ll see another reading appears in the console view (see Figure 4-16).
From here, it’s a relatively simple job to modify our existing
readBytesAvailable:
method to look for
a string of the form matching the distance readings from the EZ1’s RS-232
interface.
Get iOS Sensor Apps with Arduino now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.