### Controller Configuration and Wiring

We started with a wiring diagram of how we were going to connect the TS-7680 with the three T775M controllers. Only two wires were necessary from each unit. The ground wires were all connected together and hooked up to the bottom screw terminal (Pin 1). The VDC output wires were connected to AN0, AN1 and AN2 analog inputs of the same screw terminal connector (Pin 2, 3 and 4, respectively).

In order to output the current temperature data from MOD2, we had to configure it as follows:

• `TYPE = 2-10 V`

• `SENSOR = Sensor A`

• `SETPOINT = 100`

• `THROTTLING RANGE = 40`

• `INTEGRAL = 0` (Requires power cycle!)

• `HEAT/COOL = HEAT`

The throttling range brackets the setpoint, giving us a temperature range of 80°F to 120°F. When we read 10 VDC from MOD2, it represents 80°F. Similarly, 2 VDC represents 120°F and in between, 6 VDC represents 100°F. If this seems backward to you, it's because we are in the heating mode. The controller is designed to control a valve in order to heat or cool the pool when it reaches our threshold. We're sort of cheating here to get a linear temperature model. Plugging our x (temperature) and y (voltage in mV) values it into a slope intercept form (y = mx + b), so we end up with the formula y = -200x + 26000. Solving for our temperature (x), we get x = (y - 26000) / -200, which is the same formula you'll find in the source code. With our work on setting up the controllers complete, it's time to move on to the software side of things.

### Fetch ADC Input Data and Prototype

After downloading the given mx28adcctl sample code from Technologic Systems onto our TS-7680 board, we started modifying the `main()` function to accept a single argument of which analog input pin to read from. For example, to read the voltage on AN0, we simply run ./getadc 0, and we'll have a return value in mV. For prototyping, AN0 and AN2 were hooked up to constant 3.3 VDC, while AN1 was hooked up to a variable trimpot (0–3.3 VDC).

Pro Tip: In order to call this function as a non-root user, you'll need to run `chown root:root getadc` and `chmod 4755 getadc` to make root the owner of the binary and turn on the SUID permissions bit. The included Makefile does this for you.

Although unnecessary, we wanted to see at least some status indicator for when the temperatures were being read, so we could see if the unit is active. The TS-7680 enclosure has a yellow LED marked "Activity", tied to GPIO #58, so we took advantage of that in our `getadc` program. When the program fetches data, the activity LED will flash. Again, example code for dealing with GPIO using the sysfs interface provided by Technologic Systems made quick work of this. For more information about using the sysfs interface, take a look at our article "Robust C Library and Utility for GPIO sysfs Interface in Linux".

______________________