c0pperdragon / EV3Basic

A basic compiler to target the Lego Mindstorms EV3 intelligent brick.
50 stars 19 forks source link

Networking besides mailboxes #35

Closed DanieleBenedettelli closed 3 years ago

DanieleBenedettelli commented 4 years ago

I saw it's possible to send data over UART. Is it possible to receive data on UART? Is it possible to have a port configured as I2C slave (of another EV3)? In other words, is there to use networking besides Bluetooth? Like WiFi, or Daisy Chaining?

Thanks, D

c0pperdragon commented 4 years ago

This sending data on the UART interface is already a very strange feature and is mainly intended to do configuration of those "fast" sensors that communicate their data to the EV3 using the serial protocol. As this mode of communication can not be done at the same time as I2C, the EV2 also needs a way to send stuff to the sensors which is then done on the outgoing serial line.

The EV3 does not support receiving custom UART data. While the hardware would probably be able to do so, the EV3 virtual machine does not expose this. The incomming UART data can only be interpreted as sensor readings. Also the initial handshake between EV3 and sensor is pretty complex and there is no way to trick an EV3 to somehow present itself to the partner as a sensor itself.

The EV3 can not work as I2C slave. This is a limitation of the hardware.

But with electronic engineering you could construct an intermediary device that is an I2C slave to two or more EV3s. Each EV3 could read/write data from/to this central location. As I2C communcation can only be initiated by a master, the EV3s would have to constantly poll this central storage if there is some incomming message. I am not sure how difficult this really is, but I guess you would need some pretty deep knowlege of microcontrollers.

An even more advanced method could in fact be to construct a device that identifies itself as a UART sensor to each connected EV3. In this setup data could be transfered down to the EV3s faster without polling. On the software side there is still some latency until the "sensor" readings are available the programs (about 2ms or so). A drawback of this is that the UART sending facility seems to be a bit unreliable and not every call actually reaches the target..

DanieleBenedettelli commented 4 years ago

Thanks for the detailed answer. The idea of having a custom made I2C hub that has many slave I2C ports to let many EV3 communicate is really nice, and I can make it with ease. Thanks a lot!