Arduino 读取显示器 EDID

arduinoedid

Arduino 和EDID(上)

Arduino 和EDID(下)

文档对应代码

// SDA (20)  HDB15-12
// SCL (21)  HDB15-15
// +5V       HDB15-9
// GND       HDB15-5

#include <Wire.h>

const int i2c_port = 0x50;
byte buffer[BUFFER_LENGTH]; // 128 byte EEPROM data buffer

void setup() {
  Serial.begin(9600);
  Wire.begin();
  while (!Serial) 
    {;}
}

void loop() {
  Serial.println("(1) Read EDID and print.");
  Serial.println("(2) getInput()");
  Serial.println("(3) Item 3");
  Serial.println("");

  while (!Serial.available()) {;}

  switch (Serial.parseInt())
  {
      case 1: ddcRead(); break;
      case 2: getInput(); break;
      case 3: Serial.println("Item 3."); break;
      default: printError("Menu item does not exist.");
  }
  
  Serial.println("*************");
}

void printError(String message) {
  Serial.println("Error: " + message);
}

void ddcRead() {
  int blocks = 128 / BUFFER_LENGTH;
  
  Serial.println("Reading DDC...");
  
  Wire.beginTransmission(i2c_port);
  Wire.write(0);
  Wire.endTransmission(); 
 
  for (int block = 0; block < blocks; block += BUFFER_LENGTH) {
    Wire.requestFrom(i2c_port, BUFFER_LENGTH);
    for (int i = 0; i < BUFFER_LENGTH; i++) {
       //Serial.println(block + i, HEX);
       byte x = Wire.read();
       buffer[block + i] = x;
       //Serial.print(x, HEX); Serial.print(" ");
    }
  }
  Serial.println("Finished reading DDC.");
  printData();
}

void printData() {
  int rows = 128 / 16;
  for (int row = 0; row < rows; row++) {
    Serial.print(" ("); 
    if (row == 0) 
      Serial.print(0, HEX);
    Serial.print(row * 16, HEX); 
    Serial.print(") ");
    
    for (int half_col = 0; half_col < 2; half_col++) {
      for (int col = 0; col < 8; col++) {
        int index = (row * 16) + (half_col * 8) + col;
        byte b = buffer[index];
        if (b < 16) {
          Serial.print(0, HEX);
        }
        Serial.print(b, HEX);
        Serial.print(" ");
//        Serial.print("["); Serial.print(index, HEX); Serial.print("]");
      }
      
      if (half_col == 0) {
        Serial.print("- ");
      }
      else {
        Serial.println();
      }
    } 
  }
}

void getInput() {
  int input_buffer_len = 16;
  char input[input_buffer_len];
  Serial.println("Enter a string. 32 chars max. Input not echoed.");
  while (!Serial.available()) { ; }
  int input_len = Serial.readBytes(&input[0], input_buffer_len);
  Serial.print("Input is: ");
  for (int i = 0; i < input_len; i++) {
     Serial.write(input[i]); 
  }
  Serial.println(".");
  Serial.println("");
}

 

参考文档
I2C and Monitor DDC – Chrisbot

用 Arduino 读取 VGA 的 EDID _ TONYLABS

发表评论

电子邮件地址不会被公开。 必填项已用*标注