Silicon Chip4-Input Temperature Sensor PCB For The Raspberry Pi - May 2016 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: The visual spectacle of thunderstorms and auroras
  4. Feature: Atmospheric Electricity: Nature’s Spectacular Fireworks by Dr. David Maddison
  5. Feature: How To Convert Analog Video Tapes To Digital Format by Greg Swain
  6. Project: Budget Senator 2-Way Loudspeaker System by Allan Linton-Smith
  7. PartShop
  8. Review: USB Cameras: Use Them With Your Smartphone by Leo Simpson
  9. Serviceman's Log: Re-keyboarding a Yamaha electric piano by Dave Thompson
  10. Project: 230/115VAC, 50/60Hz Precision Turntable Driver by John Clarke
  11. Project: 4-Input Temperature Sensor PCB For The Raspberry Pi by Nicholas Vinen & Greg Swain
  12. Project: Arduino-Based Multifunction Measuring Meter, Pt.2 by Jim Rowe
  13. Product Showcase
  14. Vintage Radio: The 1948 AWA model 517M mantel radio by Associate Professor Graham Parslow
  15. Subscriptions
  16. PartShop
  17. Market Centre
  18. Notes & Errata: Automatic Starter Circuit for Cars, Circuit Notebook, April 2016

This is only a preview of the May 2016 issue of Silicon Chip.

You can view 42 of the 104 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Items relevant to "Budget Senator 2-Way Loudspeaker System":
  • 2-Way Passive Crossover PCB [01205141] (AUD $20.00)
  • Acrylic pieces to make two inductor bobbins (Component, AUD $7.50)
  • 2-Way Passive Loudspeaker Crossover PCB pattern (PDF download) [01205141] (Free)
Articles in this series:
  • Budget Senator 2-Way Loudspeaker System (May 2016)
  • Budget Senator 2-Way Loudspeaker System (May 2016)
  • Budget Senator 2-Way Loudspeaker System, Pt.2 (June 2016)
  • Budget Senator 2-Way Loudspeaker System, Pt.2 (June 2016)
Items relevant to "230/115VAC, 50/60Hz Precision Turntable Driver":
  • 230/115VAC, 50/60Hz Precision Turntable Motor Driver PCB [04104161] (AUD $15.00)
  • PIC16F88-I/P programmed for the 230/115VAC, 50/60Hz Precision Turntable Motor Driver [0410416A.HEX] (Programmed Microcontroller, AUD $15.00)
  • Firmware (ASM and HEX) files for the 230/115VAC, 50/60Hz Precision Turntable Motor Driver [0410416A.HEX] (Software, Free)
  • 230/115VAC, 50/60Hz Precision Turntable Motor Driver PCB pattern (PDF download) [04104161] (Free)
  • 230/115VAC, 50/60Hz Precision Turntable Motor Driver lid panel artwork (PDF download) (Free)
Items relevant to "4-Input Temperature Sensor PCB For The Raspberry Pi":
  • 4-input Temperature Sensor PCB for the Raspberry Pi [24104161] (AUD $5.00)
  • Two BSO150N03 dual SMD Mosfets plus a 4.7kΩ M3216/1206 resistor (Component, AUD $5.00)
  • Scripts and configuration file for Raspberry Pi 4-input Temperature Sensor (Software, Free)
  • 4-input Temperature Sensor PCB pattern for the Raspberry Pi (PDF download) [24104161] (Free)
Items relevant to "Arduino-Based Multifunction Measuring Meter, Pt.2":
  • Arduino Multifunction Meter (MFM) PCBs [04116011/2] (AUD $15.00)
  • SMD resistors, capacitors and diodes for Arduino Multifunction Meter (MFM) (Component, AUD $25.00)
  • Arduino sketch, Windows installer & source code for the Arduino Multifunction Meter (MFM) (Software, Free)
  • Arduino Multifunction Meter (MFM) PCB patterns (PDF download) [04116011/2] (Free)
  • Arduino Multifunction Meter (MFM) cutting details and panel label artwork (PDF download) (Panel Artwork, Free)
Articles in this series:
  • Arduino Multifunction 24-Bit Measuring Shield (April 2016)
  • Arduino Multifunction 24-Bit Measuring Shield (April 2016)
  • Arduino-Based Multifunction Measuring Meter, Pt.2 (May 2016)
  • Arduino-Based Multifunction Measuring Meter, Pt.2 (May 2016)

Purchase a printed copy of this issue for $10.00.

4-Input Temperature Sensor PCB For The Raspberry Pi By Nicholas Vinen & Greg Swain This simple PCB plugs directly into your Raspberry Pi’s GPIO port and makes it easy to connect up to four Dallas DS18B20 1-Wire digital temperature sensors in parallel. As a bonus, it features four matching outputs that can either be toggled or momentarily activated in response to temperature; you just enter the trigger values into the software. (1) INSTALL JP1 AS SHOWN TO SWITCH 5V RELAYS (2) OMIT JPI & CONNECT EXTERNAL 12V SUPPLY BETWEEN CENTRE PIN & GROUND FOR 12V RELAYS (3) CONNECT JP1 BETWEEN CENTRE PIN & GROUND TO ACTIVATE REMOTE CONTROL BUTTONS (SEE TEXT) CON6 1 CON7 1 I JP1 +5V CON8 1 CON9 1 2 2 2 2 OUTPUT 1 OUTPUT 2 OUTPUT 3 OUTPUT 4 Q1b Q1a Q2b Q2a 1 +3.3V CON2 1 CON3 1 CON4 1 CON5 1 2 2 2 2 3 3 3 3 TO TS1 TO TS2 TO TS3 TO TS4 4.7k DATA CON1 2 3 4 5 6 7 8 9 10 TO RASPBERRY PI GPIO HEADER Q1,Q2 = BSO150N03 OR IRF8313 Fig.1: the circuit connects temperature sensors TS1-TS4 in parallel via CON2-CON5, while Q1a, Q1b, Q2a & Q2b switch outputs 1-4 in response to the temperature readings. 74  Silicon Chip N THE March 2016 issue, we described how to connect a Dallas DS­18B20 digital temperature sensor to a Raspberry Pi (RPi) computer and showed how the readings could be accessed over the internet. Connecting a single device is easy; just wire its three leads to 1-way header sockets and plug these into the relevant pins on the RPi’s GPIO port. It’s then just a matter of connecting a 4.7kΩ pull-up resistor between the data line and the +3.3V supply and firing up the software to retrieve the readings. Each DS18B20 has a unique 64-bit serial identification code. The software presented in March 2016 scans the /sys/bus/w1/devices folder to detect the sensor(s) and adds each device it finds to an array. It then interrogates the sensors and lists the readings. In addition, the software allows you to assign a useful name to each sensor, such as “indoor1” or “outdoor” etc, so that the temperature reading from each sensor is displayed after its name. The fact that each device has a unique identification code also allows multiple DS18B20s to function on the same 1-Wire bus. If you want siliconchip.com.au 3 2 1 D CON3 (TS2) 3 2 1 D CON4 (TS3) 3 2 1 D CON5 (TS4) 3 2 1 D 24104161 RPi DS18B20 + 1 4.7k + SILICON CHIP GND Q1 2 1 2 1 2 1 2 1 CON8 (OUT3) CON9 (OUT4) Q2 CON7 (OUT2) +5V CON1 (UNDER) CON6 (OUT1) + JP1 CON2 (TS1) + Fig.2: follow this parts layout diagram and photos to build the unit. Make sure that Q1 & Q2 are orientated correctly and note that CON1 is mounted on the underside of the PCB. The circuit and text describe the linking options for JP1. to use multiple sensors, it’s just a matter of connecting them in parallel, with a single 4.7kΩ pull-up resistor shared between them (no need to add extra resistors). Connecting multiple sensors Connecting one DS18B20 to the RPi might be easy but it gets rather fiddly if you want to connect two or more devices. That’s where this little PCB comes in; it plugs into one end of the RPi’s GPIO and lets you connect up to four DS18B20 sensors simply by plugging them into 3-way polarised headers. All you have to do is connect each sensor to a matching header socket as shown in an accompanying photo and the rest is easy. Mosfet ouputs As well as making it simple to connect multiple sensors, the PCB also includes two dual-Mosfet IC packages, to provide four switched outputs. Each output can be momentarily toggled or latched on or off when the temperature readings from any sensor or combination of sensors reaches preset trigger levels. Circuit details Fig.1 shows the circuit details. Pol­arised pin headers CON2-CON5 accept the connections from the DS­18B20 sensors. In each case, pin 1 goes to the +3.3V rail (derived from the RPi’s GPIO port), pin 2 is for data and pin 3 is connected to ground (pin 9 on CON1). The 4.7kΩ pull-up resistor is connected between the commoned data pins and the +3.3V rail. CON1 plugs into pins 1-10 of the RPi’s GPIO port. As shown, the data line goes to pin 7 of CON1 and this in turn connects to pin 7 (GPIO4) on the RPi. N-channel Mosfets Q1a, Q1b, Q2a & Q2b provide the optional output switching. Q1a is controlled by GPIO2 on the RPi, Q1b by GPIO3, Q2a by GPIO15 and Q2b by GPIO14. Each Mosfet turns on when its corresponding GPIO pin goes high under software control (see below). By installing link JP1 as shown, the outputs can be used to switch 5V relays. Alternatively, by deleting JP1 and feeding 12V from an external supply between the middle pin of the JP1 header and ground, the Mosfets can switch 12V relays. Note that, at boot, GPIO2 & GPIO3 are high by default, while GPIO15 & GPIO14 are low. This means that, by siliconchip.com.au default, Q1a & Q1b (output #1 & output #2) are on, while Q2a & Q2b (output #3 & output #4) are off. Yet another option is to use Q2a and Q2b to switch two buttons on a remote control. In this case, jumper JP1 is installed between the middle pin and ground. The remote control buttons are then connected to output #3 and/or output #4, making sure that the ground side of each button goes to ground (now pin 1 on CON8 & CON9) on the PCB. Building the PCB The circuit is built on a small PCB coded 24104161 and measuring 31 x 33.5mm. Fig.2 shows the assembly details. Begin by installing the 4.7kΩ surface mount resistor. That’s done by applying a small amount of solder to one of its pads, then remelting the solder while you slide the device into position using tweezers. The other end is then soldered, after which you can go back and refresh the original joint. The Parts Required 1 double-sided PCB, code 24104161, 31 x 33.5mm 2 BSO150N03 dual N-channel Mosfets, or use IRF8313 1 4.7kΩ resistor (1%, SMD 2012/0805) Connectors & spacer 1 2 x 5-way PCB-mount female header (or cut down a 2 x 10-way header [eg, Altronics P5383] or use two 5 x 1 pin headers) 4 3-way, right-angle PCB-mount, polarised male pin headers, Altronics P5513 or Jaycar HM3423 4 3-way polarised female pin headers, Jaycar HM3403 4 2-way, right-angle PCB-mount, polarised male pin headers, Altronics P5512 or Jaycar 4 2-way polarised female pin headers, Jaycar HM3402 1 M3 x 6mm Nylon screw 1 M3 x 10mm tapped Nylon spacer 1 M3 Nylon washer Where To Buy Parts The PCB is available from the SILICON CHIP Online Shop. The dual Mosfets and 4.7kΩ SMD resistor are also available together as a short-form kit. May 2016  75 The temperature sensor PCB plugs directly into pins 1-10 of the RPi’s GPIO port. Be sure to wire the DS18B20 temperature sensors to the header sockets as shown. The two Mosfet chips go in next, taking care to ensure they are correctly orientated (pin 1 dot at top right). In each case, solder one of the end pins first, then check that the device is correctly aligned with its pads before soldering the remaining pins. Don’t worry if you bridge two adjacent pins with solder; the excess solder can easily be removed using solder wick. Next, install a link between +5V and the centre pad of JP1 if controlling 5V relays or leave this link out if you intend using an external supply to power 12V relays. Alternatively, install a link between the centre pin of JP1 and ground if using outputs #3 and #4 to switch buttons on a remote control. In that case, you also need to configure the software so that the outputs only go low momentarily (see notes in Fig.3 below). If you later find that the Mosfets fail to activate the buttons, move the link back to the +5V position and use outputs #3 and #4 to activate the buttons via 5V reed relays or conventional 5V relays. Connectors CON1-CON9 can now all go in. Note that CON1 is mounted on the underside of the PCB (see photo). Finally, fit an M3 x 10mm tapped Nylon spacer plus a Nylon washer to the underside of the PCB and secure these in place using an M3 x 6mm Nylon screw. This spacer keeps the PCB stable when it is fitted to the RPI’s GPIO header. Getting it going Once the assembly is complete, the PCB can be installed by plugging its CON1 header into pins 1-10 Fig.3: Some Notes On Config.py (a) You can base the status of an output on more than one sensor. For example: def output3(temps): if (temps['indoor'] < 20 or temps['indoor'] > 35) and temps['outdoor'] > 30: return 'HIGH' else: return 'LOW' or even: def output3(temps): if temps['indoor'] > temps['outdoor'] + 3.5: return 'HIGH' else: return 'LOW' (b) Rather than have an output switch high or low as long as given condition exists, you can have it briefly pulse high or low for a number of milliseconds or seconds. Simply do something like: def output3(temps): if temps['indoor'] > 35: return 'HIGH:500ms' else return 'LOW' You can use a suffix of either ‘ms’ or ‘s’ (for milliseconds and seconds, respectively). 76  Silicon Chip siliconchip.com.au of the RPi’s GPIO port. After that, it’s just a matter of connecting one or more Dallas DS18B20 temperature sensors to female 3-way polarised headers and plugging them into the input connectors on the PCB. Make sure that the sensor’s red wire goes to the “+” pin, the yellow or blue wire to the centre pin and the black wire to the “-” pin (see photo). Note: if you previously fitted a 4.7kΩ pull-up resistor to the RPI’s GPIO port, then this should be removed. Setting up the software STEP 1: connect a monitor , keyboard and mouse to your RPI (or log in using VNC – see January 2016). STEP 2: update and upgrade the system (note: this step in most important, otherwise there’s a chance the RPi will won’t boot after you complete Step 8): sudo apt-get update sudo apt-get upgrade sudo reboot Note that this may be a lengthy process if it hasn’t been done for some time. STEP 3: launch the RPi’s web browser, go to www. siliconchip.com.au, click Shop, select Software from the drop-list and left-click RPiTempMon.zip The file will immediately download to the /pi/Downloads folder. Navigate to this folder in the file manager, then right-click the zip file to extract these four files: dtblob.dts, index.py, config.py and tempmon.py STEP 4: move the three .py files to /var/www/html as follows (note: overwrite any existing index.py file): sudo mv /Downloads/index.py /var/www/html sudo mv /Downloads/config.py /var/www/html sudo mv /Downloads/tempmon.py /var/www/html STEP 5: change ownership of the index.py file to www-data, as follows: sudo chown www-data /var/www/html/index.py STEP 6: set up the RPi to read the DS18B20 sensors and send temperature readings to a web-server as described in the March 2016 issue of SILICON CHIP (see the February 2016 issue for the web-server set-up details). Note that you have to add each DS18B20’s ID to the sensor_ names = line in the index.py file in /var/www/html; eg: sensor_names = {"0115812a9fff": "indoor1", "011581aefaff": "indoor2"} If you only need temperature readings and you don’t need to switch the outputs, then that’s all you need to do and you can go straight to Step 12 (ie, reboot the system). Alternatively, if you want to trigger any of the outputs in reponse to temperature measurements, the following additional steps are necessary. STEP 7: install Device Tree Compiler (DTC) on the RPi using the following command: sudo apt-get install device-tree-compiler siliconchip.com.au Output States At Boot At boot, Q1b & Q1a (outputs #1 and #2) are on by default and outputs Q2b & Q2a (outputs #3 and #4) are off. So use outputs #1 and/or #2 for tasks where you normally want the load to be switched on (or don’t care) initially and #3 and/or #4 when the load should be off by default. You can edit the .dts file to turn outputs #1 and #2 off initially. However, there may be a brief period where they are switched on immediately after power is applied, so it’s safer to use outputs #3 and #4. The config.py file should be consistent with this convention (see our examples). For further information on setting up the RPi’s I/O pin states at boot, refer to: https://www.raspberrypi.org/documentation/configuration/pin-configuration.md In addition, the following link explains how to set the I/O pin states from Python: http://raspi.tv/2014/rpi-gpio-quick-reference-updatedfor-raspberry-pi-b STEP 8: go to the /home/pi/Downloads folder and install dt-blob.dts using the following command: sudo dtc -I dts -O dtb -o /boot/dt-blob.bin dt-blob.dts This installs a file called dt-blob.bin in the /boot folder and sets up the GPIOs we’re using as outputs at boot time – see the above panel. Note: delete this file, or change its name, if the system fails to reboot later on. STEP 9: Edit config.py to customise it for your requirements. For example: def output1(temps): return 'HIGH' def output2(temps): return 'HIGH' def output3(temps): if temps['indoor1'] < 20 or temps['indoor1'] > 27: return 'HIGH' else: return 'LOW' def output4(temps): return 'LOW' This example sets up output #3 (initially off at boot time) to switch on if the temperature of the “indoor1” sensor is below 20°C or above 27°C. Fig.3 on the facing page shows two more examples and also shows how to switch the outputs momentarily high or low (rather than have the outputs toggle) STEP 10: run python /var/www/html/tempmon.py and check that it prints the temperature readings once per second. Check that the outputs switch on and off as the temperature varies, as expected. Press CTRL+C to terminate. STEP11: edit /etc/rc.local and add the following line to the end, before the “exit 0” line: python /var/www/html/tempmon.py > /dev/null & STEP 12: reboot. SC May 2016  77