void loop
{
char c=Serail.read();
if (c=='1') digitalWrite(13,HIGH);
if (c=='a') digitalWrite(13,LOW);
delay(1000);
}
วันพฤหัสบดีที่ 3 ตุลาคม พ.ศ. 2556
วันจันทร์ที่ 30 กันยายน พ.ศ. 2556
How to build an arduino energy monitor - measuring mains current only. :ref http://openenergymonitor.org/emon/buildingblocks/how-to-build-an-arduino-energy-monitor-measuring-current-only?page=1
How to build an arduino energy monitor - measuring mains current only.
This little guide details how to build a simple electricity energy monitor on a breadboard that you could use to measure how much electrical energy you use in your home. It measures current and takes a set value for voltage (if your in the uk 230V) to calculate apparent power all the calculations are done on an arduino, although not as accurate as when a voltage measurement is taken, it is a method commonly used in whole house energy monitors for reasons of simplicity and lower cost. Here's how to do it:
Step One – Gather Components
You will need:
1x Arduino
Current sensing electronics
1x CT sensor yhdc SCT-013-000
1x Burden resistor 18 Ohms if supply voltage is 3.3V or 33 Ohms if supply voltage is 5V.
2x 10kOhm resistors (or any equall valued resistor pair upto 470kOhm)
1x 10uF capacitor
Other
1x A breadboard and some single core wire.
Oomlout do a good arduino + breadboard bundle here £29
Step Two – Assemble the electronics
The electronics consist of the current sensor (which produce signals proportional to the current in the mains) and the sensor electronics that convert these signals into a form the Arduino is happy with.
For a circuit diagram and detailed discussion of sensors and electronics see:
Assemble the components as in the diagram above.
Step Three – Upload the Arduino Sketch
The Arduino sketch is the piece of software that runs on the Arduino. The Arduino converts the raw data from its analog input into a nice useful values and then outputs them to serial.
a) Download EmonLib from github and place in your arduino libraries folder.
Download: EmonLib
b) Upload the voltage and current example:
#include "EmonLib.h" // Include Emon Library EnergyMonitor emon1; // Create an instance void setup() { Serial.begin(9600); emon1.current(1, 111.1); // Current: input pin, calibration. } void loop() { double Irms = emon1.calcIrms(1480); // Calculate Irms only Serial.print(Irms*230.0); // Apparent power Serial.print(" "); Serial.println(Irms); // Irms }
c) Open the arduino serial window
You should now see two columns of values. Apparent power on the left and rms current on the right.
http://forum.arduino.cc/index.php/topic,12921.0.html
http://openenergymonitor.org/emon/buildingblocks/ct-sensors-interface
http://openenergymonitor.org/emon/buildingblocks/how-to-build-an-arduino-energy-monitor-measuring-current-only?page=1
วันพฤหัสบดีที่ 19 กันยายน พ.ศ. 2556
Auto reboot rPI hang By Watchdog นำมาจาก https://www.facebook.com/RaspberryPi66
Auto reboot Raspberry Pi เมื่อมัน hang ไปซะเฉยๆ ด้วย Watchdog

บางครั้งเราเปิด rPi ไว้บ้านเพื่อนทำ Home automation หรือ load bit ก็ว่ากันไปแล้วมันหยุดทำงาน ตอนเราไม่อยู่บ้าน แหมเหมือนใจมันจะขาดรอนๆ จะสั่งใครให้ reboot ให้ก็ไม่ได้
วันนี้เรามาดูวิธีติดตั้ง watchdog เพื่อให้มันเฝ้าดูการทำงานของเครืองให้เรากันครับ โดย watchdog timer นัั้นจะเป็นการทำงานด้านฝั่ง hardware เลย โดยจะนับถอยหลังจากค่าที่เรากำหนดไว้จนได้ค่าเป็น 0 มันจะสั่งให้ rPi reboot ทันที ซึ่งโดยปกติถ้าระบบทำงานปกติค่าตัวแปรจะถูกอัพเดตให้มีค่าสูงไว้ตลอด ถ้านับได้ 0 แปลว่ามัน หยุดทำงานไปแล้วนั่นเอง
ซึ่งโชคดีมากที่ Broadcom BCM2835 SoC ของ Raspberry Pi เรามาพร้อมกับ hardware-based watchdog timer ทำให้เราสามารถใช้งานได้ตามนิยามในย่อหน้าแรก
Load the bcm2708_wdog kernel module
ทำได้โดยเปิดไฟล์ /etc/modules แล้วเพิ่มบรรทัดนี้ลงไป
bcm2708_wdogจากนั้นสั่ง load module เพื่อให้ทำงานได้ทันที ไม่ต้อง reboot
sudo modprobe bcm2708_wdog
Install the software watchdog daemon
ติดตั้ง package watchdog ด้วยคำสั่ง
sudo apt-get install watchdog
และสั่งให้ทำงานทุกครั้งเมื่อเริ่มระบบ
sudo update-rc.d watchdog defaults
Configure the watchdog daemon
เปิดไฟล์ /etc/watchdog.conf ขึ้นมาแก้ไข โดยเอาเครื่องหมาย # ออกจากหน้าบรรทัดเหล่านี้เพื่อให้โปรแกรมอ่านค่า parameter เหล่านี้
#watchdog-device
.
.
.
#max-load-1 = 24
หลังจากนั้นสั่งให้ service watchdog ทำงานด้วยคำสั่ง
sudo /etc/init.d/watchdog startลองหางานหนักๆให้มันทำงานแล้วดูว่าระบบมัน auto reboot ให้รึเปล่า
เท่านี้ก็ได้ผู้ช่วยคนใหม่มาคอย reboot ให้แล้วครับ
BASIC PROGRAMMING PI and Hardware
Within these instructions, we shall only cover some very basic programming, more detailed examples and tutorials will be made available from the “Meltwater Raspberry Pi Hardware” site (http://pihw.wordpress.com/) in the learning section.
วันจันทร์ที่ 5 สิงหาคม พ.ศ. 2556
Git: มารู้จักกับโปรแกรมบริหารซอร์สกันเถอะ
Git: มารู้จักกับโปรแกรมบริหารซอร์สกันเถอะ
labels: Git by Nattawut Phetmak
1969 Linus Torvalds (คนเดียวกับผู้สร้าง Linux) เกิด
1972 กำเนิดโปรแกรม SCCS โปรแกรมจัดการซอร์สโปรแกรมแรกๆ
1990 กำเนิดโปรแกรม CVS
2000 กำเนิดโปรแกรม SVN
2005 Linus ให้กำเนิด Git
Git เป็นโปรแกรมบริหารจัดการซอร์สตัวหนึ่ง เนื่องจากในการพัฒนาโปรแกรมนั้น เราอาจมีการลองผิดลองถูกอยู่หลายทางว่าได้ผลลัพท์เป็นที่น่าพอใจหรือไม่ หรือบางครั้งฟีเจอร์ใหม่ๆ ที่เพิ่มเข้าไปอาจจะทำให้ระบบล่ม ต้องถอยกลับไปก่อนหน้าที่จะเกิดข้อผิดพลาดนั้น การใช้โปรแกรมบริหารซอร์สจะช่วยให้เราแก้ไขปัญหาต่างๆ ได้อย่างมีประสิทธิภาพมากขึ้น
โดย Git นั้นเป็นโปรแกรมบริหารซอร์สแบบกระจายศูนย์ ที่จะแจกซอร์สทั้งหมดให้ผู้ใช้ทุกคนเหมือนกัน ไม่แบ่งแยกชนชั้นครับ (ถ้าใครเป็น CVS/SVN มาก่อน ก็อาจถือได้ว่าต้องเรียนรู้ใหม่เกือบหมดเลยทีเดียว)
ผู้ใช้ Windows สามารถใช้ msysGit แทนได้ (โปรแกรมจะไปรันบน MinGW อีกที)
ส่วนผู้ใช้ Linux ก็เช่นเคย
หลังจากติดตั้งโปรแกรมเรียบร้อยแล้ว ก็ต้องตั้งค่าเริ่มต้นที่จำเป็นกันหน่อย โดยสั่ง
ลองเริ่มใช้โปรแกรมเลยดีกว่า สมมติจะสร้างโปรเจค
Git จะสร้างไดเรกทอรี
คราวนี้มาเขียนโปรแกรมหลักของโปรเจคนี้กัน
ทดสอบแล้วรันได้ไม่มีปัญหา ก็ได้เวลาสั่งให้ Git จำ code เข้าระบบโดย
เท่านี้ก็เรียบร้อยครับ
ปล. โปรแกรมบริหารซอร์สแบบนี้ ใช้คนเดียวยังไงก็ไม่สนุก อย่างลืมชวนเพื่อนๆ มา code เล่นด้วยกันนะครับ
1972 กำเนิดโปรแกรม SCCS โปรแกรมจัดการซอร์สโปรแกรมแรกๆ
1990 กำเนิดโปรแกรม CVS
2000 กำเนิดโปรแกรม SVN
2005 Linus ให้กำเนิด Git
Git เป็นโปรแกรมบริหารจัดการซอร์สตัวหนึ่ง เนื่องจากในการพัฒนาโปรแกรมนั้น เราอาจมีการลองผิดลองถูกอยู่หลายทางว่าได้ผลลัพท์เป็นที่น่าพอใจหรือไม่ หรือบางครั้งฟีเจอร์ใหม่ๆ ที่เพิ่มเข้าไปอาจจะทำให้ระบบล่ม ต้องถอยกลับไปก่อนหน้าที่จะเกิดข้อผิดพลาดนั้น การใช้โปรแกรมบริหารซอร์สจะช่วยให้เราแก้ไขปัญหาต่างๆ ได้อย่างมีประสิทธิภาพมากขึ้น
โดย Git นั้นเป็นโปรแกรมบริหารซอร์สแบบกระจายศูนย์ ที่จะแจกซอร์สทั้งหมดให้ผู้ใช้ทุกคนเหมือนกัน ไม่แบ่งแยกชนชั้นครับ (ถ้าใครเป็น CVS/SVN มาก่อน ก็อาจถือได้ว่าต้องเรียนรู้ใหม่เกือบหมดเลยทีเดียว)
ผู้ใช้ Windows สามารถใช้ msysGit แทนได้ (โปรแกรมจะไปรันบน MinGW อีกที)
ส่วนผู้ใช้ Linux ก็เช่นเคย
apt-get install git กันได้เลยหลังจากติดตั้งโปรแกรมเรียบร้อยแล้ว ก็ต้องตั้งค่าเริ่มต้นที่จำเป็นกันหน่อย โดยสั่ง
1
2
| $ git config --global user.name 'Name Surname'$ git config --global user.email 'name@example.com' |
ลองเริ่มใช้โปรแกรมเลยดีกว่า สมมติจะสร้างโปรเจค
hello ก็สั่งดังนี้
1
2
3
4
| $ mkdir hello$ cd hello$ git initInitialized empty Git repository in ~/hello/.git/ |
Git จะสร้างไดเรกทอรี
.git/ พร้อมไฟล์ระบบต่างๆ ของโปรเจคนี้ให้ครับคราวนี้มาเขียนโปรแกรมหลักของโปรเจคนี้กัน
1
2
3
| $ echo 'print("hello world!")' > hello.py$ python hello.pyhello world! |
ทดสอบแล้วรันได้ไม่มีปัญหา ก็ได้เวลาสั่งให้ Git จำ code เข้าระบบโดย
1
2
3
4
5
| $ git add hello.py$ git commit -m 'init program'[master (root-commit) 2dd5f8a] init program 1 files changed, 1 insertions(+) create mode 100644 hello.py |
เท่านี้ก็เรียบร้อยครับ
ปล. โปรแกรมบริหารซอร์สแบบนี้ ใช้คนเดียวยังไงก็ไม่สนุก อย่างลืมชวนเพื่อนๆ มา code เล่นด้วยกันนะครับ
สมัครสมาชิก:
บทความ (Atom)
Re: How to build an arduino energy monitor - measuring current only
I translated this tutorial into German. It´s not perfect but I hope it could help someone.-->Link.
Ich hab´ den Tutorial übersetzt, ist sehr schlecht geschrieben, da Deutsch nicht meine Muttersprache ist, aber verständlich sollte es sein... für fragen: