📜 ⬆️ ⬇️

How I was looking for an idea for the first project on Arduino or Wake-on-LAN on Arduino.



Prehistory


At one time, after watching a video about how people make various devices like Hexfalls, he had respect for those people who did this, with a desire to learn how to do something like that. For myself personally, for some unknown reason, I could feel a big difference in emotions from a programmed controller with a trivial blinking of the LED in comparison with a complex algorithm in a software product, and the first one won. Deciding that the only available way for me to achieve that state when something like Hexfall comes out from under my hands is to start programming elementary things. The choice fell on the Arduino due to the availability of the platform itself and an excess of information on it.

Where to begin?


Probably the most frequent question when you start a new business is “where to start?” I didn’t want to do something unnecessary, but something very complicated could lead to the fact that without understanding the details could cool down to the project without mastering it . Then I remembered one feature of my PC, which gave me enough inconvenience. Due to certain circumstances, I often have to connect to my home computer. Naturally, in order to connect via RDP, the computer must be turned on. Based on this, there were two options: 1) leave the PC on (which is at least inconvenient); 2) wake it up before connecting.

Obviously, the second solution is more concise both economically and practically. Any attempts to make wake-on-lan work stably, ended with the computer becoming unavailable because it did not get out of sleep. To be more precise, he could have been awakened within a limited time (about 15-30 minutes) after going to sleep. It was not possible to wake up beyond this time interval. Different boards and different dances with a tambourine around the BIOS were tried. The result was always the same. I admit the thought that it is still possible under the given conditions on this hardware, but the time spent on solving the problem was too large. As a result, during the next "trip" I had to leave the computer turned on unattended for several days. I think most people understand that you cannot say that the task of remote access has been solved. Considering that all that is required during physical contact for waking up is a short press of a button (simply closing the contacts), I decided that this is a fairly simple project, and very useful for me.
')

No sooner said than done


The first thing I started with was the definition of how everything would work and the minimum necessary set for solving this problem. The functional part of the solution was as follows. Arduino works as a web server and waits for a signal. When receiving an on / off signal, it checks the status of the PC (if it is not already running / turned off) and, making sure that the conditions are met for a short time, closes the contacts of the on / off button. It's pretty simple.

The set is also quite simple: Arduino nano, ethernet MINI ENC28J60, wires for connecting contacts and 1 transistor (I initially thought I would do without a transistor, just applying the same voltage as the first contact to the second contact, but empirically found that the board was waiting for the equivalent voltage on the second contact, and just a short to ground of the first).

The power is taken from the USB, and the power-on check is removed from the free pin for the cooler on the motherboard.

imageimage

The choice of ethernet MINI ENC28J60 fell due to the small size and the fact that the craftsmen have already written a library to work with this Arduino board.

It all works like this: Mac address, IP, subnet mask, port and buffer size are initiated. Further initialization of the ENC28J60 and ethernet / ip boards. Then the buffer in the loop is checked if something has come up with a request. The request of interest to us is the page requested by the GET method with the address to which we will respond. If we receive a request for the root page (“GET / HTTP ...”), we give the answer “It works!” Simulating Apache. In the headers we also imitate Apache in every possible way (Server: “Apache / 2.4.9 (Win32)”, that’s that), so that Vasya, who has read the Hacker magazine, tried to understand why he couldn’t break the server. In case the request does not go to the root page, then if the requested page is not the one that we have determined to enable / disable, we issue “404 Not Found”.

Connection is still not difficult. I do not see the meaning of the scheme. As a matter of fact, 3 boards (Arduino nano, ENC28J60, motherboard) and 1 transistor are connected to each other. I decided that for those who are not strong in circuit design, it would be clearer to present a simple table at the intersection of columns in which there will be a connection.

Arduino nanoENC28J60motherboardtransistor
+5+ 5USB
D13SCR
3v3VIN
GNDGND
D2Int
D12SO
D11ST
D10CS
D8CPU_fan
D6base
GNDemitter
Power swcollector
GNDGND


image

For convenience, all the wires were heat-shrunk, and the board was ENC28J60 filed, so that it could be mounted on the rear panel. The donor for the fasteners was some kind of ancient network card, to which firewood is not found anywhere else.

image

When working after receiving a request to turn on / off, the program looks at whether there is a voltage on the “CPU_fan”, based on this, decides whether it is necessary to supply power to the transistor. If necessary, it delivers a current to the base of the transistor and switches it back through time. The current on the base of the transistor allows it to open and close the contacts “Power SW” and “GND”.

The goal is achieved. Moreover, I got the opportunity to display the PC after BSOD, since we can send a signal that will emulate a 4 second press of the power button.

Conclusion


This is not the most difficult thing that has been done. There were also my own, more complex projects, and writing code “to help” other people, but, first, for the first article I wanted to choose a not complicated “project” (too loud a word for the above), corresponding to the “sandbox”, secondly The first project is like a first love. It sinks into the soul. Thus, I would like to try to motivate, to show that the first step may be easier than it seems. And if at least one person tries after reading, I will assume that the article was a success. I advise you to start the “smallest” with a video from Jeremy Blum.

PS: We are waiting for a parcel with a colleague to build a quadrocopter and are already thinking of collecting hexfall. And it was worth just to try ...

Link to skatech and library for working with ENC28J60.

Source: https://habr.com/ru/post/249507/


All Articles