ผู้เขียน หัวข้อ: งานครั้งที่ 44 เขียนโปรแกรมอ่านค่าอุณหภูมิจาก DS18B20 แสดงผล 7 segment MAX7219  (อ่าน 4223 ครั้ง)

admin

  • Administrator
  • Hero Member
  • *****
  • กระทู้: 706
    • ดูรายละเอียด
    • อีเมล์
เขียนโปรแกรมอ่านค่าอุณหภูมิจาก DS18B20 แสดงผลที่ 7 segment MAX7219

ไลบารี่เพิ่มเติม
-OneWire.h https://github.com/PaulStoffregen/OneWire
-DallasTemperature.h https://github.com/milesburton/Arduino-Temperature-Control-Library
-LedControl.h https://github.com/wayoda/LedControl/releases
*ดูวิธีติดตั้งในงานครั้งที่ 20

โจทย์การทดลอง
-เขียนโปรแกรมรับค่าอุณหภูมิที่อ่านจาก DS18B20 แสดงผลที่ 7 segment MAX7219
-โปรแกรมรายละเอียดพิเศษรายกลุ่ม (แจ้งให้ทราบเมื่อถึงชั่วโมงเรียน)

วงจรที่ใช้ในการทดลองสำหรับผู้ที่ใช้บอร์ด Arduino


วงจรที่ใช้ในการทดลองสำหรับผู้ที่ใช้ไอซี ATmega328 (ที่มี Boot Loader Arduino)


ตัวอย่างโปรแกรมอ่านค่าจาก DS18B20
โค๊ด: [Select]
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire(2);                 //Connect to Pin 2 (D2)
DallasTemperature sensors(&oneWire);
void setup(void)
{
  Serial.begin(9600);
  Serial.println("Dallas Temperature IC DS18B20");
  sensors.begin();
}
void loop(void)
{
  Serial.print(" Requesting temperatures...");
  sensors.requestTemperatures();            // Send the command to get temperatures
  Serial.println("DONE");
  Serial.print("Temperature is: ");
  Serial.print(sensors.getTempCByIndex(0));
  Serial.println(" Degrees C");
  Serial.print("Temperature is: ");
  Serial.print(sensors.getTempFByIndex(0));
  Serial.println(" Degrees F");
}

ตัวอย่างโปรแกรมแสดงผล 7 Segment MAX7219
โค๊ด: [Select]
#include "LedControl.h"
LedControl lc=LedControl(6,4,5,1); // Pin 11->DIN, 13->CLK, 12->CS, 1 = No.of devices
void setup()
{
  lc.shutdown(0,false);    // Enable display
  lc.setIntensity(0,10);   // Set brightness level (0 is min, 15 is max)
  lc.clearDisplay(0);      // Clear display register
}
void loop()
{
   lc.setDigit(0,7,2,false);   
   lc.setDigit(0,6,3,true);
   lc.setDigit(0,5,4,false);
   lc.setRow(0,4,B00110111);
   lc.setRow(0,3,B01001111);
   lc.setRow(0,2,B00001110);     
   lc.setRow(0,1,B00001110);
   lc.setRow(0,0,B01111110);   
  delay(1000);
}
« แก้ไขครั้งสุดท้าย: มิถุนายน 28, 2017, 09:15:35 AM โดย admin »