-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
189 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# DDC/CI VCP library | ||
This is an Arduino library for controlling external computer monitors over the VESA DDC/CI standard. This standard is present on many different types of connectors but depends heavily on the actual manufacturer to implement it properly. Check if your setup is actually compatible with this. | ||
|
||
# Examples | ||
Some simple examples can be found in the examples directory. | ||
|
||
# Functionality | ||
- setting and reading brightness | ||
- setting and reading power status | ||
- setting and reading input source | ||
- custom VCP commands | ||
|
||
More Functionality can easily be added. See [ddcutil](https://www.ddcutil.com/vcpinfo_output/) for some further reference on VPC codes. | ||
|
||
# Connector | ||
The Arduino is to be connected to VGA, HDMI or DVI using the corresponding pins for DDC. This is essentially an I2C connection and uses the standard arduino Wire library so use the appropriate pins for I2C on your microcontroller. | ||
|
||
Disclaimer: I only tested this with a VGA connection, however DVI and HDMI should work as well. Pay attention to using the correct voltages though! | ||
|
||
## VGA | ||
- Pin 15: DDC Clock (SCL) | ||
- Pin 12: DDC Data (SDA) | ||
|
||
## DVI | ||
- Pin 6: DDC clock (SCL) | ||
- Pin 7: DDC Data (SDA) | ||
|
||
## HDMI | ||
- Pin 15: DDC Clock (SCL) | ||
- Pin 16: DDC Data (SDA) | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,21 @@ | ||
|
||
#include "DDCVCP.h" | ||
|
||
DDCVCP ddc; | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
while (!ddc.begin()) { | ||
Serial.print(F("- Unable to find DDC/CI. Trying again in 5 seconds.\n")); | ||
delay(5000); | ||
} | ||
Serial.print(F("- Found DDC/CI successfully.\n")); | ||
} | ||
|
||
void loop() { | ||
ddc.setBrightness(10); | ||
delay(3000); | ||
ddc.setBrightness(50); | ||
delay(3000); | ||
ddc.setBrightness(100); | ||
delay(3000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,98 @@ | ||
|
||
/* | ||
DDCVCP.cpp - Library for controlling monitors over DDC/CI. | ||
Created by Toni Tanner, 2021. | ||
*/ | ||
|
||
#include "Arduino.h" | ||
#include "DDCVCP.h" | ||
|
||
DDCVCP::DDCVCP() | ||
{ | ||
|
||
} | ||
|
||
bool DDCVCP::begin() { | ||
Wire.begin(); | ||
Wire.beginTransmission(_I2CAddress); | ||
if (Wire.endTransmission() == 0) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
// op: VCP opcode. Can be found with ddc capabilities | ||
// value: 16bit value | ||
void DDCVCP::setVCP(byte op, uint16_t value) { | ||
Wire.beginTransmission(_I2CAddress); | ||
Wire.write(0x51); | ||
Wire.write(0x84); | ||
Wire.write(0x03); | ||
Wire.write(op); | ||
Wire.write(byte(value >> 8)); | ||
Wire.write(byte(value)); | ||
Wire.write((_I2CAddress << 1) ^ 0x51 ^ 0x84 ^ 0x03 ^ op ^ byte(value >> 8)^byte(value)); //XOR checksum. Include all bytes sent, including slave address! | ||
Wire.endTransmission(); | ||
} | ||
|
||
uint16_t DDCVCP::getVCP(byte op) { | ||
Wire.beginTransmission(_I2CAddress); | ||
Wire.write(0x51); | ||
Wire.write(0x82); | ||
Wire.write(0x01); | ||
Wire.write(op); | ||
Wire.write((_I2CAddress << 1) ^ 0x51 ^ 0x82 ^ 0x01 ^ op); //XOR checksum. Include all bytes sent, including slave address! | ||
Wire.endTransmission(); | ||
delay(40); | ||
Wire.requestFrom(_I2CAddress, 12); | ||
byte response[12]; | ||
int i = 0; | ||
while (Wire.available()) // slave may send less than requested | ||
{ | ||
byte c = Wire.read(); // receive a byte as character | ||
response[i] = c; | ||
i++; | ||
//Serial.printf("%x ",c); // print the character | ||
} | ||
return (response[8] << 8) + response[9]; | ||
} | ||
|
||
void DDCVCP::setBrightness(int value) | ||
{ | ||
if (value > 100) { | ||
value = 100; | ||
} | ||
setVCP(0x10, value); | ||
} | ||
|
||
uint16_t DDCVCP::getBrightness() | ||
{ | ||
return getVCP(0x10); | ||
} | ||
|
||
// 0x01:VGA, 0x03:DVI, 0x0f:DP | ||
void DDCVCP::setSource(uint16_t value) { | ||
setVCP(0x60, value); | ||
} | ||
|
||
uint16_t DDCVCP::getSource() { | ||
return getVCP(0x60); | ||
} | ||
|
||
|
||
// true:on, false:suspend | ||
void DDCVCP::setPower(bool value) { | ||
if (value) { | ||
setVCP(0xD6, 0x01); | ||
} | ||
else { | ||
setVCP(0xD6, 0x03); | ||
} | ||
} | ||
|
||
bool DDCVCP::getPower(){ | ||
byte power = getVCP(0xD6); | ||
if (power==0x01){ | ||
return true; | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,32 @@ | ||
/* | ||
DDCVCP.h - Library for controlling monitors over DDC/CI. | ||
Created by Toni Tanner, 2021. | ||
*/ | ||
|
||
#ifndef DDCVCP_h | ||
#define DDCVCP_h | ||
|
||
#include <Wire.h> | ||
#include "Arduino.h" | ||
|
||
|
||
class DDCVCP | ||
{ | ||
public: | ||
DDCVCP(); | ||
bool begin(); | ||
void setBrightness(int value); | ||
uint16_t getBrightness(); | ||
void setVCP(byte op, uint16_t value); | ||
uint16_t getVCP(byte op); | ||
void setSource(uint16_t value); | ||
uint16_t getSource(); | ||
void setPower(bool value); | ||
bool getPower(); | ||
private: | ||
uint8_t _I2CAddress = 0x37; | ||
}; | ||
|
||
#endif | ||
|
||
|