So I have managed to install OpenWrt on one of my old routers and decided to make kind of PLC device from it.
Now I know some people are dismounting router and are using led pins as GPIO.
But I just cannot make myself waste such a useful lights when I have all this input and outputs and would prefer to use ethernet wires to send and receive signals to motors and sensors.
Can it be done ?
No you cannot use the ethernet interfaces directly as GPIO pins. Both the electrical and logical signaling is much more complex than simple GPIO pins, and they will not operate at all unless they have a corresponding ethernet phy connection. An actual network protocol stack is also typically required to do anything useful with ethernet (not technically required at the L1/phy level, but practically required for devices that utilize L2 or higher connections).
The question is, is it possible to write custom driver for ethernet for OpenWrt, so it is no longer used for networking but as GPIO.
Or is it so hardware bound that it is not doable.
For making the ethernet port function as GPIO, no, not possible.
It is hardware bound. The ethernet interface is a fairly sophisticated electrical subsystem with an encoding scheme (PAM) and differential signaling with magnetics, etc.. It is nothing like a standard GPIO pin. If you make an analogy of the GPIO pin being a crystal radio set for picking up AM radio stations, the ethernet phy might be a 4K TV digital broadcast receiver.... you wouldn't expect a single diode to be able to receive and decode a digital television signal.
Thank you for your effort so far.
I'm a little desperate here so please let my ask a little more.
So I was investigating it for a while, what I found so far is that Transmission wires in ethernet are differential. Now I could use them for example to send PWM to my motor (with some differential amplifier).
So now I just have to generate PWM signal of particular shape.
As I found out it is possible to send raw data via a socket
something like socket(AF_PACKET, SOCK_RAW)
Now knowing the transmission speed I can generate packets that will represent the PWM signal.
So I have got two questions:
- Can I set the speed of the ethernet (or get the speed of the ethernet)
- Can I use socket and send data even when there is no other device connected to the wires on the other side.
I don't think you understand... it is not possible. full stop.
If you don't believe me, take a look at a data sheet for one of TI's ethernet transceivers (just as an example) and try to figure out how you would be able to send arbitrary GPIO/PWM data through that port.
You will not be able to get the ethernet port to perform as a GPIO in any way whatsoever. You could use something like a raspberry pi which has plenty of GPIO pins and a network interface. Or if you don't need networking, an Arduino will do the trick.
Differential input means four signal wires that have paired differential signal input and these are run through the ethernet transformers just behind the rj45 connector and the output/input of that transformer have the actual signal to the switch/cpu.
By doing this you can run ethernet cables (electrical) potential free floating for 100m without the fire alarm going off at or both cable endpoints at the first lightning storm or grid ground fault.
So using a RaspberryPi or similar digital input to ethernet converting device will save you a lot of never ending trouble.
I was thinking about creating buffer of bytes filled with bits (0) and (1) in appropriate places, knowing bits per second and that byte is 8 bit I could forge PWM with some margin o error.
Even if there is some additional data sent with a packet it would not have a big impact since buffer would be relatively big so it would not have a noticeable impact on motor speed.
I would use ethernet wires only for output.
A PWM signal is a square wave with fixed low frequency like 100kHz where you shift the duty cycle of the wave (PWM=PulseWidthModulation).
Even if you would get these bits out from the ethernet port you talk about, how is your plan to convert them to a PWM signal since that signal isn’t “bits traveling around”?
IMHO, you seem to be stuck on the idea of using the ethernet ports, and create a complex and unstable solution, instead of looking for a better alternative...
Differential amplifier, I think I was writing about this already.
Ok, so good luck with your PWM control system then.
@koirat - What you want to do is literally not possible. Please read up on how ethernet works at L1 (phy). When you learn about the electrical signaling characteristics and the encoding methods used, you will understand why we keep telling you this.
You need to find another solution. If you don't stop pursuing this, you will spend far more time and energy (and likely money) than you would simply buying a Raspberry Pi (or other similar device that has GPIOs already as part of the system), and I promise you that you will have zero to show for it.
OK guys your effort was not in vain.
You just purely convinced me no to follow this path.
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.