Recommended Posts

I have read all sorts of complaints about Robot Inventor and by inference Spike Prime. Some are valid (eg poor documentation)... some are less so (eg colour scheme). One thing seems clear is that the hardware is well thought out (yes there are issues with cables).

Now in robotics three elements stand out as being super important: being able to use multiple motors (motors are basic building blocks), multiple sensors plus having the computational brain (and software) to hold it all together. Unfortunately Lego only provide 6 ports on each hub and have 2 versions of software both of which initially appear limiting. Whereas wireless Inter-hub communication could be very helpful enabling models to use multiple hubs and access both software platforms  this is not something that Lego have explicitly provided at the moment. There is however a very simple and seemingly reliable work around available immediately that could help in cases where high speed comms and high data volumes are less important. This is to use optical communication.

The idea which I have tested is to use the distance sensor to signal light flashes to the colour sensor. The number of flashes in a fixed time frame thus delivers information from Transmitter to Receiver. As expected using downloaded compiled code speeds the process up though not massively.

This process could be 2 way, could enable daisy chaining of hubs and could be expanded to longer instructions (again high speed not being a limitation).

On the downside the process sacrifices at least one port on each of a pair of hubs (if the requirement is for one way communication between the pair). The sensors need to be carefully and firmly positioned for reliability although there is no other requirement for any connection between them. In this context a model containing the one hub could “launch” the second.

As SP and RI software can be easily swapped on any hub the user has the choice of using SP/SP or SP/RI or RI/RI platforms.

Unfortunately size limitations prevent me from uploading images of the set up and demo code at the moment.

 

 

 

Share this post


Link to post
Share on other sites

I have been working on something similar :classic:

Files should be hosted elsewhere. Maybe you can use Google Drive, Dropbox, Git, Bricksafe to host your files. I am interested in taking a look.

Share this post


Link to post
Share on other sites
 
I thought let's bring this info to here for the case it will disappear elsewhere. Thanks @Tcm0 until now I only read people saying it was not possible :) So this is very good news :)
 
 
# Sender Spike Prime or Robot Inventor Hub
# Code by Gianluca Cannalire

import utime
import hub
from hub import port

port.A.mode(port.MODE_FULL_DUPLEX)
a=port.A
a.baud(115200)

i=0
while True:
    utime.sleep_ms(150)
    p=hub.button.center.was_pressed()
    if p==True:
        i=i+1
        hub.display.show(i)
        print("Send: " + str(i))
        a.write(str(i))
        if i==9:
            i=0
# Receiver Spike Prime or Robot Inventor Hub
# Code by Gianluca Cannalire

import utime
import hub
from hub import port

port.B.mode(port.MODE_FULL_DUPLEX)
b=port.B
b.baud(115200)

i=0
while True:
    utime.sleep_ms(150)
    s=b.read(100).decode()
    if len(s) > 0:
	hub.display.show(s)

The above example code from Gianluca Cannalire to let two LEGO hubs talk to each other via a wire between them, if you press the center button on the "sender" it will increase the number (up to 9, and then starting at 1 again) and show it on the hub, send it to the receiver hub, that then will reads the number and displays it.

His comments:

Quote
You can run the code from REPL, but I don't find a way to save to *.py file and run from here.
The problem is in the baud / read / write method which are not standard members of the "Port" class.
These functions "appear" only after call the mode.(port.MODE_FULL_DUPLEX) function.So if you try to use this code in a .py file, you get an error. I need to understand better how to overcome this problem ...
 
You can talk to any non-LEGO Hardware if they are a TTL UART device.

Adding a small delay after the "mode.(port.MODE_FULL_DUPLEX)" you can fix the above mentioned error, as Nard Strijbosch suggested.

 

Edited by BrickDesignerNL

Share this post


Link to post
Share on other sites
On 1/14/2021 at 7:41 AM, Skookumjim said:

The idea which I have tested is to use the distance sensor to signal light flashes to the colour sensor. The number of flashes in a fixed time frame thus delivers information from Transmitter to Receiver. As expected using downloaded compiled code speeds the process up though not massively.

I used to use a fibre optic cable (from the ancient Technics Fibre Optics kit) to link an RCX brick to a Scout brick to do the same thing.  The novelty of it (quite a few years ago!) extended it to controlling Micro Scouts and even a Bionicle Manta driving base (look it up kids :wink: - Lego did some weird stuff back then). 

Is there enough info out there about the port specs for either a dedicated fibre optic link between hubs or some other suitably isolated electronic link?  Effectively a one-way serial link.  Or a bi-directional serial link with a bit of work maybe?  Need to know a lot more about the internals for that.  Is any of that type of detailed technical info out there yet for these hubs?

Share this post


Link to post
Share on other sites
1 hour ago, Laid Back Koala said:

I used to use a fibre optic cable (from the ancient Technics Fibre Optics kit) to link an RCX brick to a Scout brick to do the same thing.  The novelty of it (quite a few years ago!) extended it to controlling Micro Scouts and even a Bionicle Manta driving base (look it up kids :wink: - Lego did some weird stuff back then). 

Is there enough info out there about the port specs for either a dedicated fibre optic link between hubs or some other suitably isolated electronic link?  Effectively a one-way serial link.  Or a bi-directional serial link with a bit of work maybe?  Need to know a lot more about the internals for that.  Is any of that type of detailed technical info out there yet for these hubs?

As earlier quoted the protocol used by the hub is TTL UART. And you can link two hubs together if you make a link cable with two connectors.

Since it also has Bluetooth it might be interesting to see if you can find a lib that can scan for other devices, and then connect to them, to so then the hubs can talk serial (uart) over bluetooth between the hubs.

The bluetooth MAC-addresses of the hub are exposed in code when you sync it with the hub (zip file contains xml with this info).

Edited by BrickDesignerNL

Share this post


Link to post
Share on other sites

I think that lego will make an official option to connect two spike hubs at one point but as far as I know, it's only possible with the wired connection as of yet. There is the uBluetooth library but from what I've heared you can only use it to connect the hub to BLE devices like the smart hubs.

Share this post


Link to post
Share on other sites
On 1/13/2021 at 8:41 PM, Skookumjim said:

There is however a very simple and seemingly reliable work around available immediately that could help in cases where high speed comms and high data volumes are less important. This is to use optical communication.

On the downside the process sacrifices at least one port on each of a pair of hubs (if the requirement is for one way communication between the pair). The sensors need to be carefully and firmly positioned for reliability although there is no other requirement for any connection between them. In this context a model containing the one hub could “launch” the second.

Hypothetical idea ....

If you don't mind the hubs being physically linked together, then there is another way that might work freeing up one of the two required for the optical connection. If the hubs are "bolted" together, then any motion of the transmitter will be felt by the receiver and since they have gyros inside, then a predefined sequence of motion of the first could be read as a signal by the second. You still need to use a port to connect to a motor to, say, rotate the combined hubs in a certain sequence so it would save one port only. Then you'd have to determine what the gyro output was for say a 5 deg left, 10 deg right, 5 degree left "shake" of the hub and call that signal 1. Do 10 deg right, then 10 deg left for another signal, and so on and so you have a "fingerprint" of different motions that each can be read and mean something different. Of course, this motion would need to be independent of any other motion of the larger model, or at least occur at a faster speed than any other similar motion (so simple rotating will not work if the whole model also rotates at similar speeds). And it clearly won't be high speed comms. It is probably too impractical for most builds that move.

Share this post


Link to post
Share on other sites
9 hours ago, Tcm0 said:

I think that lego will make an official option to connect two spike hubs at one point but as far as I know, it's only possible with the wired connection as of yet. There is the uBluetooth library but from what I've heared you can only use it to connect the hub to BLE devices like the smart hubs.

Just found this page https://lego.github.io/lego-ble-wireless-protocol-docs/ is this also for the spike prime / robot inventor hub?

Share this post


Link to post
Share on other sites
27 minutes ago, BrickDesignerNL said:

Just found this page https://lego.github.io/lego-ble-wireless-protocol-docs/ is this also for the spike prime / robot inventor hub?

Yes and no. The hub uses some other kind of communication for hub <-> PC (a protocol that uses Bluetooth Classic). The protocol you linked (it uses Bluetooth low energy) is used by the smarthubs (control+, boost etc).

However, the mindstorms/spike hub is capable of sending BLE (Bluetooth low energy) commands with the uBluetooth library I mentioned. But uBluetooth sends raw BLE commands, no Lego wireless commands. So you would have to write a library to send lego wireless commands via ubluetooth library. I think that someone here posted a library for the powered up remote but there is none for the other hubs so far.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.