iT邦幫忙

0

pzem--004t、lcd連結?

小妹第一次發問,想請問各位大大,我們想用arduino uno板嘗試製作基本得電錶,但不知道怎樣連結顯示,也不知道少了些甚麼,求各位協助。
下面是我的程式:
#include <PZEM004Tv30.h>

/* Hardware Serial2 is only available on certain boards.

  • For example the Arduino MEGA 2560
    */
    SoftwareSerial pzemSWSerial(11, 12);
    PZEM004Tv30 pzem;
    #include <LiquidCrystal_I2C.h>
    #include <Wire.h>
    // Set the pins on the I2C chip used for LCD connections:
    LiquidCrystal_I2C lcd (0x27,16,2);

void setup() {
Serial.begin(115200);
lcd.begin(16,2);
lcd.init();
for(int i=0;i<3;i++)
// 閃爍三次
{
lcd.backlight(); // 開啟背光
delay(250);
lcd.noBacklight(); // 關閉背光
delay(250);
}
// Uncomment in order to reset the internal energy counter
// pzem.resetEnergy()
}

void loop() {

Serial.print("Custom Address:");
Serial.println(pzem.readAddress(), HEX);

// Read the data from the sensor
float voltage = pzem.voltage();
float current = pzem.current();
float power = pzem.power();
float energy = pzem.energy();
float frequency = pzem.frequency();
float pf = pzem.pf();

// Check if the data is valid
if(isnan(voltage)){
Serial.println("Error reading voltage");
} else if (isnan(current)) {
Serial.println("Error reading current");
} else if (isnan(power)) {
Serial.println("Error reading power");
} else if (isnan(energy)) {
Serial.println("Error reading energy");
} else if (isnan(frequency)) {
Serial.println("Error reading frequency");
} else if (isnan(pf)) {
Serial.println("Error reading power factor");
} else {

    // Print the values to the Serial console
    Serial.print("Voltage: ");      Serial.print(voltage);      Serial.println("V");
    Serial.print("Current: ");      Serial.print(current);      Serial.println("A");
    Serial.print("Power: ");        Serial.print(power);        Serial.println("W");
    Serial.print("Energy: ");       Serial.print(energy,3);     Serial.println("kWh");
    Serial.print("Frequency: ");    Serial.print(frequency, 1); Serial.println("Hz");
    Serial.print("PF: ");           Serial.println(pf);

}

Serial.println();
delay(2000);

}

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0

我要發表回答

立即登入回答