Sunday, July 24, 2016

Open Source Reef Controller Update #1

I decided to begin this project some time ago, but shelved the idea until recently. Why? The time, effort, and cost of developing a system with the capabilities I wanted were prohibitive. I wanted more than just an aquarium data logger; I wanted a controller capable of handling lighting, dosing, and a number of additional safety measures. As time wore on, I decided to simplify things by completing one section at a time. First up, temperature data logging!

Temperature Data Logging

Hardware Setup

A Raspberry Pi 1 B+ is the foundation of the controller. I've added a wifi dongle to connect it to my home network and allow for easy access through SSH. Temperature measurement will be handled by a waterproof DS18B20 sensor. This sensor can be run at 3.3v and communicates with the Pi using the one-wire interface. The digital interface is a must, since the Pi does not have an analog to digital converter. A 4.7k pull up resistor is needed on the data line.

Software Setup

Luckily, the heavy lifting on the software side was already complete. On my Pi 1 B+ running Raspbian, I installed the w1thermsensor Python module. This can be done with the below commands or by downloading the source from the link.

sudo apt-get install python-w1thermsensor
python --command-packages=stdeb.command bdist_deb
Before the sensor can be queried, onewire must be enabled in the device tree overlay. This is done by modifying the boot config file.

To modfiy the boot config file:
sudo nano /boot/config.txt 

Add the line dtoverlay=w1-gpio to the bottom of the file and save. This enables onewire on pin 4 of the pi. On my setup, I'm using pin 6 which requires dtoverlay=w1-gpio,gpiopin=6. The chosen pin is generally arbitrary.

With the hardware and software installed, it's simple to query the sensor by running the example script in the w1thermsensor documentation. From a python terminal:

from w1thermsensor import W1ThermSensor 
sensor = W1ThermSensor()
temperature_in_celsius = sensor.get_temperature() 


In lieu of a functional GUI, I decided to create the controller as an IoT device. As such, recorded data and alerts will be pushed to the cloud service ThingSpeak. ThingSpeak is a free service with a number of graphing and data analysis tools that's great for this kind of project. My controller will log data here for viewing. As features are added, additional charts and alerts can be appended to the site.

I created a simple python script to measure the temperature with the sensor and push the result to ThingSpeak every 15 minutes by executing the below as a crontab job.
# Developed by cmarzano
# 5/26/2016

import httplib, urllib
from w1thermsensor import W1ThermSensor

sensor = W1ThermSensor()
temp = sensor.get_temperature(W1ThermSensor.DEGREES_F)

# Input your thingspeak channel API key below
apikey = 'yourkeygoeshere'

params = urllib.urlencode({'field1': temp, 'key':apikey})
headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"}
conn = httplib.HTTPConnection("")
conn.request("POST", "/update", params, headers)
response = conn.getresponse()
print response.status, response.reason
data =

To run the script every 15 minutes in crontab, you'll need to add the below line to your crontab list after entering crontab -e with the path correctly filled in.

*/15 * * * * /usr/bin/python /absolute/path/to/ 

Some additional tweaking on the ThingSpeak side completes the temperature logger. Embedded below is the LIVE data from my tank. I have the temperature sensor slightly downstream of the heater, which causes some observable fluctuations when the heater activates. As I make hardware and software changes to the setup, automatic updates may periodically stop.

Sunday, July 17, 2016

3D Printing Redux

It's been quite some time since my last post! Shortly after my last 3D printer update, I completed the machine and began testing and tweaking. The machine worked, but overall performance wasn't up to my standards. I spent some time revisiting the design, and ultimately decided to tear it down and begin anew with higher quality components.

I designed a new printer, also a cubic foot H-bot, using OpenBuild's V-slot aluminum extrusion. The extrusion and accessories are fairly low cost, easy to work with, and high performing. Additionally, I decided to complete an overhaul of the electronics. I switched out the Printrboard for a Duet 0.8.5. This controller provides significantly more features than the Printrboard, such as native dual nozzle support, network control (similar to OctoPrint), and 24v power. Also, the DC powered 12" silicone heater was replaced with an AC version and a heatsinked solid state relay.

Additional electronic changes included use of the E3D PT100 temp sensor+board for the hotend, and the differential IR sensor for auto bed leveling. There were some hardships in getting the PT100 sensor functioning, since the E3D amplifier boards were designed for 5v electronics. To make things even more difficult, the Duet 0.8.5 did not have any software support for PT100 sensors (DC42 has since added some functionality).

At the time of writing this post, I completed the project about 9 months previously. There's still some work to be done on the printer for getting the second nozzle operating and watercooling the hotend. For now, enjoy some pictures of the build process!

Frame nearly finished at this stage. The black panels are a textured 1/4" HDPE called StarBoard. Cheap and robust!

Solid state relay and matching heatsink. Absolutely critical for keeping the relay functioning.

Electronics are in a compartment underneath the print area. Includes SSR and 24v power supply on the left with the Duet and 12v+5v power supply on the right.

The first powered test with all critical to function pieces wired. It works!

A 1/4" polycarbonate shell forms covers all sides but the front to limit temperature fluctuations in the build area. Eventually the enclosure will seal to prevent warping; but the hotend will need to be watercooled.

I printed a calibration cube before this to check basic functionality, then threw the iconic octopus on it. Finished it like a champ!