Introduction: Using a Raspberry Pi to Control a WF32 With LabVIEW (Fan Control)
This Instructable takes a project from my last Instructable ( Thermistor - Fan control using LabVIEW) and adds in the use of a Raspberry pi 3 for wireless control of the WF32. This means that you can now set up the fans and servo with your WF32 in your entertainment center and then control them over WiFi. In this Instructable I go over how to set up the Raspberry Pi but if you run into any trouble please refer to the Getting Started With the Raspberry Pi 2 (LabVIEW) Instructable.
Step 1: Materials
1) Temperature sensor [TMP36] (250 mV output at 25°C)
2) Two Slide switches
3) three 240Ω resistors
4) 100 uF electrolytic capacitor
5) Tactile button switch
6) Breadboard(I use a MyProto Protoboard and a 270 tie breadboard)
7) Two PWM controlled fans(I use two different sizes in my demo)
8) Small servo motor
9) ChipKIT WF32
10) Raspberry Pi 2 (I use the Raspberry Pi 3, but the process is the same)
11) Wifi dongle (Wi-Pi USB WiFi Module is a good choice)
12) microSD with adaptor(8GB or larger)
Everything but the fans, LabVIEW, Raspberry Pi, Wifi dongle, and WF32 is included in the LabVIEW Interaction Parts Kit
Step 2: Connecting WF32 to WiFi
- Launch the LINX Firmware Wizard
- Choose the chipKIT WF32
- Go to Device Manager
- Click on "Ports(COM & LPT)" to find the WF32's COM port
- Select that COM port
- Configure the network settings:
- SSID is the name of your network
- Assign the chipKIT WF32 an available IP Address. You will need to specify this IP address again later as an input to the LINXInit VI.
- Select the Port to use, unless you have reason to use another you should select 44300
- You will need to specify this IP address again later as an input to the LINX Init VI.
- Specify the Wifi security type and passphrase.
- Note: It is recommended that you disable network security to start and then re-enable it after you confirm the LINX connection is working.
- Click Launch Example
A video going over these instructions can be found here
Step 3: Raspberry Pi Setup
- Download a Raspbian image here
- LINX was developed using Raspbian Jessie.
- Click the Download ZIP button under the RASPBIAN JESSIE image
- Unzip the Raspbian image.
- Google win32diskimager and click on the top link or click here
- Download Win32 Disk Imager.
- Open it from your downloads folder
- complete the installation but unclick the View and launch boxes after completing the setup wizard
- Open File explorer and go to This PC
- Select Program Files(x86)
- Select ImageWriter
- Then Select Win32DiskImager
- Click on the Folder next to the image file dialog box and then select your raspbian jessie disk image
- Insert the SD card into your computer and set the device dropdown so your SD card is selected and click Write
Connect ethernet to the Raspberry Pi and power on your Raspberry Pi. Launch LabVIEW and open the Target Configuration Wizard from Tools»MakerHub» LINX»Target Configuration.
- Enter the Raspberry Pi's Hostname or IP and a username and password with root privileges and click connect. (Eventually you will want your Raspberry Pi connected to WiFi, click here if you need help)
- Default Hostname is 'raspberrypi'.
- Default Username is 'pi' Default Password is 'raspberry'
- Click the Install Software tab and click Install and then review any warnings and complete the installation.
A video going over these instructions can be found here
Step 4: Circuit Setup Part 1 - WF32
Connect power and ground to both sides of the breadboard. Next, insert male headers into the 3 or 4 female sockets on the servo motor and the fans(see figure above for fan pin instructions). For the servo connect the orange wire to power, and the brown wire to ground. Place a 100uF electrolytic capacitor across power and ground to smooth out any irregularities in voltage. Connect the servo's data wire(yellow wire) to pin three on your WF32(important to use a pin that supports PWM). Repeat this procedure for each of the two fans connecting the data wire of one to pin 2 and the other to pin 4. Place the TMP36 on the breadboard (the order of the pins is important) connect the left pin of the flat facing side to power, and the right pin to ground. Connect the center pin to Analog pin 1(A1) of the WF32.
Step 5: Circuit Setup Part 2 - Raspberry Pi
Connect power and ground to both sides of the breadboard. Next, Place the pushbutton on the breadboard and connect one end to the 5V. On the other side of the switch, connect to ground through a 240Ω resistor. Connect this junction to digital pin 11 on the WF32. Next step is to attach a slide switch, First place the three pin switch on the breadboard. Next run a wire from one of the outer pins to power and then place a 240Ω resistor between the opposite sides pin and ground. Finally run a wire from the center pin to digital pin seven on the WF32. Repeat this step with the next slide switch except connect the center pin to 13.
Step 6: Raspberry Pi - Deploying a Startup Executable
- Open my LabVIEW project "Raspberrypi-WF32_Fan_Control" attached below and then select File-> New
- Select "Empty Project" in the "Project" folder
- A pop-up will ask you if you want to add the open VI to the new project, select Add
- Right click "Project: Untitled Project 1" and select "New"» "Target and Devices"
- Select "Raspberry Pi 2 B" in the LINX folder and then click OK
- Right click "Raspberry Pi 2 B" and select Properties
- Under the "General" category enter the IP address for your Raspberry Pi(should be the one you set in a previous step)
- Next step is to open up a pinout diagram for the Raspberry Pi 2 for later use. From the front panel select Help»MakerHub»LINX»"Pinout - Raspberry Pi B"
- Next, enter the correct values for the TCP settings, RPI settings, and the WF32 settings.
- To make sure these values don't change, click Edit»"Make Current Values Default"
- Pull the "Raspberrypi-WF32_Fan_Control" into the Raspberry Pi 2 section and right click Build Specifications then choose New»Real-Time Application.
- Rename the build specification.
- Click the Source Files category on the left side of the dialog.
- Under Project, Files select the top level VI ("Raspberrypi-WF32_Fan_Control") and click the right arrow to add it to Startup VIs. Click OK.
- Right click the new build specification and choose Build.
- Click Done.
- Right click the new build specification and choose Run as Startup.
- Click Yes to reboot the target.
The VI will now run whenever the target is powered on. A video going over these instructions can be found here
Step 7: Labview Code
From the thermistors sensors datasheet, I found that every 10 millivolts of change from the sensor is equivalent to 1 degree Celsius. If you take the voltage, subtract 0.5, and multiply it by 100, you get the accurate temperature in degrees Celsius.
You can download my LabVIEW code by clicking on the "Raspberrypi-WF32_Fan_Control.vi" file below. If you followed my instruction above, then the default channel values are already set but if you used different channels you will have to change them. Also, if you are using a different servo, you will want to play around with the pulse width values for both positions. Otherwise, just follow the instructions given on the front panel and feel free to comment with any questions you may have.
We have a be nice policy.
Please be positive and constructive.