[vc_row][vc_column][vc_column_text]
pcDuino can connect to Internet by Ethernet, WiFi, GPRS and 3G. In this project, we will use a TMP36 temperature sensor to sense the office temperature and push to yeelink server, and check the temperature anytime anywhere through the Internet.
[/vc_column_text][vc_tour][vc_tab title=”Parts List” tab_id=”1395715768-1-21″][vc_column_text]
- 1 x [bigcommerce link=”/pcduino-v2-an-minipc-with-arduino-headers-ubuntu-android-google/” target=”_blank”]pcDuino V2[/bigcommerce]
- 1 x TMP36 sensor
- 1 x Breadboard
- 1 x 3.3k ohm resistor
- Several jumper wires
[/vc_column_text][/vc_tab][vc_tab title=”Connect the TMP36 to pcDuino” tab_id=”1395715768-2-98″][vc_column_text]
The above figure is the bottom view of TMP36. The corresponding pins from the left to right are VCC, VOUT and GND.
We connect TMP36 to pcDuino in the following way:
- VCC of TMP36 -> 3.3V of pcDuino
- VOUT of TMP36 -> A5 of pcDuino
- GND of TMP36 -> GND of pcDuino
- Add a shunt resistor between VCC and GND of TMP36 to prevent damage of components.
Final Setup:
[/vc_column_text][/vc_tab][vc_tab title=”Sample Code” tab_id=”1395715979576-2-4″][vc_column_text]
#include <core.h> #define aref_voltage 3 const int tmpPin = A2; char buffer[50]; int tmpReading; void setup(){ } void loop(){ tmpReading = analogRead(tmpPin); printf ("tmpReading = %dn",tmpReading); float voltage = tmpReading * aref_voltage; voltage /= 4096; float tmpC = (voltage - 0.5) * 100; sprintf (buffer, "{"value":%4.2f}n", tmpC); FILE* fp = fopen ("/home/ubuntu/datafile.txt","w+"); fwrite (buffer, sizeof(char), strlen(buffer), fp); fclose (fp); exit (0); }
[/vc_column_text][/vc_tab][vc_tab title=”Compile the code” tab_id=”1395715980432-3-1″][vc_column_text]Refer to book to check how to run Arduino style code in command line.
Create a file named tmp_yeelink.c. You can download the code from tmp36_yeelink.
Put the tmp_yeelink.c file to the sample directory under the c_environment which you just obtained from githun .
$ cp ***/tmp36_yeelink.c ***/c_environment/sample
***is the file you save the
c_enviroment and the path of tmp_yeelink.c
Then modify the Makefile:
$ vi Makefile
Add the tmp36_yeelink after
OBJS+= ***
OBJS+=tmp36_yeelink
Save and quit, input make and start to compile.
$ make
Then we will translate the analog value from the sensor to actual value of temperature, and save into a file named ‘data_file.txt’ in JSON format.[/vc_column_text][/vc_tab][vc_tab title=”Send data to yeelink” tab_id=”1395716242226-4-5″][vc_column_text]Curl is an open source communication tool which uses the URL approach in command line.
Create a script file named the yeelink.sh, then write the following code to the file. (Modify the corresponding APIKEY and URL according to your own condition, and as well as the path to the file named tmp36_yeelink)
$sudo /home/ubuntu/c_enviroment/output/test/tmp36_yeelink $curl --request POST --data-binary @"/home/ubuntu/datafile.txt" --header "U-Apikey:537ef1cef1b8726b39347abb8c0c809a" http://api.yeelink.net/v1.0/device/8466/sensor/13387/datapoints
Add the execution right for the script after you save and exit the file.
$ chmod +x yeelink.sh
–request <command> specify use command –data-binary in binary POST data @”…” cooperatively use with last command, to POST the content behind the @ to the server. –header The custom header information is passed to the server
[/vc_column_text][/vc_tab][vc_tab title=”Periodically Push Data to Yeelink server” tab_id=”1395765966232-6-0″][vc_column_text]We will use a task called crontab to periodically push data to yeelink server.
Launch crontab editor by using:
$crontab -e
Add the script name as shown below:
Note: You should use yeelink.sh instead.
[/vc_column_text][/vc_tab][vc_tab title=”Result” tab_id=”1395727101827-5-2″][vc_column_text]First measure the temperature of the office using a thermometer:
Then view the monitor state in the yeelink website:
[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]
October 12, 2014 at 2:00 am
A2 and ADC5? please explain