This article is written under the impression of
another - many thanks to the author! This article almost managed to make your own IP KVM Switch, and it's awesome! But I will explain why almost. Yes, everything works there as the author wrote ... Until the reboot into the BIOS - all the magic is dissipated there and how much you do not try, nothing happens.
It was decided to correct this unfortunate misunderstanding and as cheap and compact as possible. Let's start with the stereotypes of Raspberry Pi and Arduino, and in the next
article we will continue on another hardware.
So what we need:
1. The video capture card must support the UVC driver, like this one. Options
full on aliexpress and other Chinese stores.
')

UVC is a standardized open source driver that is included by default on most Linux distributions. There may be problems with other drivers.
2. VGA to AV Converter:


Note! VGA to AV is needed, and not vice versa.
3. Arduino UNO, namely UNO, since it has an Atmega16u2 chip on it, it interests us first of all. Here it is next to the USB port, there are also arduins with an Atmega8u2 chip that are suitable for this and that.
4. And of course Raspberry Pi, I had version 2 b so everything written in this article is relevant for him, but in general I think there should not be any particular difficulties with other raspberry models.
Fill the distribution
Well, the input data are given, perhaps let's get started. I used the distribution 2015-05-05-raspbian-wheezy, probably it does not matter, further manipulations should be suitable for any Debian-based distribution.
We connect the video capture card to the raspberri, it is better to connect directly to the USB without using USB extension cables, especially the one that comes with the card, otherwise video braking, hanging of the rasterberry, etc. may occur.
Go to the console, update the packages:
sudo apt-get update && sudo apt-get upgrade –y
Video transfer
Check whether the board is determined:
ls /dev/video*
It should give something like: / dev / video0.
Installing Motion, we will be transmitting the captured image through it:
sudo apt-get install motion -y
We edit the autorun config:
sudo nano /etc/default/motion
In the line
start_motion_daemon
set 'yes'. Save changes Ctrl + x, y, Enter.
We edit the config of the motion itself (a):
sudo nano /etc/motion/motion.conf
Change the parameter values ​​as follows:
The parameter defines the launch of the application as a service:
daemon on
These parameters determine the resolution of the transmitted image, there is no sense in setting a higher resolution, since video capture is limited to PAL or SECAM standards, the resolution of which is 720x576. This is by the way an annoying flaw, but more on that later.
width 800 height 600
Frame rate:
framerate 25
Disable screenshots saving:
output_normal off
Image transfer quality:
webcam_quality 100
Frame rate:
webcam_maxrate 25
Cancel restrictions on connections from other ip
webcam_localhost off
Save changes Ctrl + x, y, Enter.
Restarting the parser:
sudo reboot
We are waiting for a couple of minutes if everything is done correctly, the LED on the video capture card should light up.
Connect the browser to port 8081 and open the gray or blue rectangle with the time running from the bottom.

The process has begun, we are looking for a victim to capture the signal from the VGA port, connect it to the “VGA IN” port of the converter, and connect the video capture card to the “VIDEO OUT”. It should look like this, do not worry, I have a bad cable, so the image is “double”, I tried the other image better, but the permission was not changed. 720x576 is a limitation of the converter and video capture card, which, with all the desire, cannot be overcome.

Well, how to transfer the image learned, it remains the case for small - transfer control.
Transfer of control
For this, as you may have guessed, we will use the Arduin. The choice fell on the Arduino UNO for a reason, there is a very necessary chip for our purposes called Atmega16u2, only thanks to it I managed to force the computer BIOS to define arduino as a USB keyboard. By default, as part of the Arduino board, this microcircuit plays the role of a USB to Serial converter for uploading firmware to the Atmega328p microcontroller, a large rectangular microcircuit on the Arduino board. In fact, the Atmega16u2 is the same microcontroller, but with an important difference, it is able to work directly with the USB bus. Atmega16u2, if you have the necessary firmware, can emulate almost any USB device. Do you understand what I'm doing? We will sew this engineering marvel and make us work for the good of society.
Atmega16u2 firmware
On the Internet, a
firmware was found that turns the Atmega16u2 into a USB keyboard that accepts commands of a certain type through the Serial Port.
The instructions in this article are written for windows, but Linux users can use
this one .
And so let's get started, for the firmware you will need a utility from a manufacturer called
Flip . Download, install, run and here we have a program window:

First, the buttons (daws) are not active, this is normal, we connect the arduin to the computer and close - we open two extreme contacts from the USB port, RESET and GND.

In the system, a new device should appear under the name, strangely enough, ATmega16u2 install the driver (in the program folder), select the Settings tab → Communication → USB → open in the flip program, the buttons should become active. Just in case, you can make a backup of the firmware so that you can return everything to its place. In the “File” menu, click “Load HEX File”, the program is demanding of the paths, it is best to put the firmware file in the root of the C: drive, select the desired hex file with the firmware, check whether the Erase, Program, Verify checkboxes are checked. and click "Run". Turning off - connect arduino and voila ... Now we can no longer download firmware to arduino via the built-in USB, but we got an excellent keyboard without buttons.
Do not worry about the arduino firmware, the firmware can be downloaded from the Arduino IDE via a separate USB To TTL adapter, although I must say, now it will be less convenient.
Connect the USB To TTL adapter, for example:

We will need White, Green and Black contacts as RX, TX and GND, respectively, connect them to pins with the same designations on Arduin, only the other way around RX to TX, and TX to RX. Red contact should not be used!
We connect USB To TTL to the computer, install the driver, a new COM Port should appear in the device manager. Open the arduino IDE and expose: The board is the Arduino / Genuino Uno, the Port is our newly created serial port.
Getting started with arduino firmware
Add the necessary library to the arduino IDE: Follow the link
github.com/SFE-Chris/UNO-HIDKeyboard-Library click "Clone or download" → "Download ZIP". Further, in the arduino IDE, select the “Sketch” tab → “Connect library” → “Add .ZIP library” and select the zip archive you just downloaded.
Preparation is completed, go directly to the firmware. We copy my writings:
Arduino - Sketch #include <HIDKeyboard.h> HIDKeyboard keyboard; int sbor; void setup() { keyboard.begin(); } void loop() { while (Serial.available()) {// sbor += Serial.read();// , if (sbor == 27){// for (int i=0; i<=4; i++ ){// if (sbor == 165) {// F1-F12 sbor += sbor; } sbor += Serial.read(); delay(1); } } } if (sbor > 0) { // switch (sbor){ case 505: keyboard.pressSpecialKey(F1); break; case 506: keyboard.pressSpecialKey(F2); break; case 507: keyboard.pressSpecialKey(F3); break; case 508: keyboard.pressSpecialKey(F4); break; case 509: keyboard.pressSpecialKey(F5); break; case 511: keyboard.pressSpecialKey(F6); break; case 512: keyboard.pressSpecialKey(F7); break; case 513: keyboard.pressSpecialKey(F8); break; case 340: keyboard.pressSpecialKey(F9); break; case 341: keyboard.pressSpecialKey(F10); break; case 343: keyboard.pressSpecialKey(F11); break; case 344: keyboard.pressSpecialKey(F12); break; case 13: keyboard.pressSpecialKey(ENTER); break; case 22: keyboard.pressSpecialKey(ESCAPE); break; case 127: keyboard.pressSpecialKey(BACKSPACE); break; case 9: keyboard.pressSpecialKey(TAB); break; case 32: keyboard.pressSpecialKey(SPACEBAR); break; case 26: keyboard.pressSpecialKey(PAUSE); break; case 292: keyboard.pressSpecialKey(INSERT); break; case 456: keyboard.pressSpecialKey(HOME); break; case 295: keyboard.pressSpecialKey(PAGEUP); break; case 294: keyboard.pressSpecialKey(END); break; case 296: keyboard.pressSpecialKey(PAGEDOWN); break; case 182: keyboard.pressSpecialKey(RIGHTARROW); break; case 183: keyboard.pressSpecialKey(LEFTARROW); break; case 181: keyboard.pressSpecialKey(DOWNARROW); break; case 180: keyboard.pressSpecialKey(UPARROW); break; case 293: keyboard.pressSpecialKey(DELETE); break; case 320: keyboard.pressSpecialKey((CTRL | ALT), DELETE); break; // ctl+alt+del alt + del case 346: keyboard.pressSpecialKey(ALT, F4); break; // alt+f4 shift + F4 default: keyboard.pressKey(sbor); break; } //Serial.println(sbor);// usb keyboard.releaseKey(); sbor = NULL; } }
We insert it into the arduino IDE and click the check button. Now the most crucial stage will begin, here the most important thing is to catch the moment, not many people succeed the first time. We press the download button in the arduino IDE, first the white lines with the compilation log will run, the orange ones will follow, this is the establishment of the connection to the serial port, this is the moment you need to catch and have time to press the RESET button on the board. A firmware download should occur, if everything is successful, you will see an inscription like this
avrdude: reading on-chip flash data: Reading |
If after several attempts the firmware has not yet been downloaded, try swapping the RX and TX contacts, and also check if the GND pin is connected securely.
Finish line
Open the console on the drawbar and write:
sudo raspi-config
The settings menu will open, select “Advanced Options” → “Serial” and select “No”.
Perhaps these manipulations and will not be needed, so, reinsurance. This parameter determines whether the OS on a raspberry will interact with the serial port, this interaction is mainly needed for debugging, so it’s safe to disable it, it will only interfere with us, because With Arduina we will communicate through this port, and the system will clog the air.
Install the minicom program.
Minicom is a simple program for working with a serial port.
sudo apt-get install minicom -y
We set the rights to access the device, / dev / ttyAMA0 - this is the same serial port.
sudo chown pi /dev/ttyAMA0 sudo chmod 744 /dev/ttyAMA0
Run minicom:
sudo minicom -s
The program menu will open, select the “Serial port setup” item, another menu will open, select the “Serial Device” by pressing the A key, set / dev / ttyAMA0, press Enter, then select Bps / Par / Bits under the letter E, the next one will appear menu, press C and Q line Current: should look like this: "9600 8N1" press Enter. Make sure that in the lines F - Hardware Flow Control: and G - Software Flow Control: it costs No, in general everything should be as in the screenshot below, press Enter.

Let's save these settings as default settings “Save setup as dfl” and close “Exit from Minicom”.
Connection
We are going further, now we have almost everything ready, it remains only to connect the arduin to the raspberry serial port, something like this:

There is one thing here, Arduino and Rasperri have different levels of tension, and in theory they need to be coordinated, I advise you to read the
article .
Although everything worked directly for me without coordination, you should not imitate a bad example and acquire a logic level converter, the simplest one looks like this:

Or at least collect the voltage divider on the resistors.

Launch
Everything is ready, you can start.
We check all connections, we include raspberry pi, we pass into the raspberry console, we start minicom. Immediately make a reservation, I connected to raspberry via ssh, I used KiTTY (a modified version of PuTTY) as a client, this is important. with other terminals, the values ​​of the transmitted keys may be different and, accordingly, it will be necessary to make a correction for the wind - change the switch case transition number.
In general, I hand over to you as they say "as is". Well, on this perhaps finish, self-made IP KVM is ready.
PS
Lastly I will describe what happened in the dry residue.
Pros:
- Price- The device turned out relatively inexpensive
- Raspberry Pi: about 2700 rub.
- Arduino UNO: about 400 rubles.
- VGA to AV Converter: approximately 700 rub.
- Video capture fee: 500 rub.
- Total: 4300rub.
- Fine tuningYou can intercept almost any combinations and assign almost any keys to them up to KEYBOARDPOWER and VOLUMEUP, by the way possible values ​​can be viewed in the header file HIDKeyboard.h, or you can add your own.
Minuses:
- Deceleration of both video and transmission of clicks
- The second and biggest is
the image quality , a sad smiley is simply needed here, it is terrible, even if you reduce the resolution on the target computer to a minimum, the maximum that can be done is to configure the BIOS and select the item in the loader. But isn't KVM really needed for this? .. And for everything else, there is radmin and others like it.
To be continued ...