<< return to Pixycam.com

Support for the latest lego hub

Hello,

I’d like to know if the Pixy2 is currently supported with the lastest lego hubs (those shipped with the Spike Prime and Lego Inventor 51515 sets)?
Are there microPython APIs for the Pixy2 compatible with these hubs?
Is there a way to plug the Pixy2 on these hubs which have a different connector than those shipped with the Lego Pixy2?

Thanks in advance for your help!

Hello,
We have this, which includes support for MicroPython and the EV3:
https://docs.pixycam.com/wiki/doku.php?id=wiki:v2:python

But I’m honestly not sure if this works with the Lego sets you mention. It looks like they have different connectors, so that’s going to be a hurdle. Hope this helps!

Edward

Thank you for your answer!

I took a look at the pixy2 library here and I can see at least 2 things:

  • there are checks on the hub model in the code, so I’d have to rewrite it partially in order to avoid errors,
  • the library uses I²C to communicate with the camera, and from the looks of it, there are I²C functions built in the pybricks firmware of the EV3. From what I can read in the documentation or find on the internet, currently Pybricks for the Prime / Robot Inventor hub does not support I²C devices

The UART protocol seems to be supported by these new hubs, but I’m not sure if it will work with the Pixy2 camera.
Here is what the documentation says about serial communication on the inventor hub:

  • hub.port. MODE_FULL_DUPLEX = 1
    The port operates as a raw full duplex logic level serial port.
  • hub.port. MODE_HALF_DUPLEX = 2
    The port operates as a raw half duplex differential level serial port.

Do you know if one of those two modes would enable communication with the Pixy2 camera? It is unclear to me if the protocols on the hub and on the camera are really the same or not.

Hello,
It’s not clear to me what the hub.port is. There are no send/receive functions in the docs. It seems that the source code isn’t there, just the docs, unless I missed it.

Edward

Hello,

There are methods to work with serial communication in the documentation, but the I sent the wrong link, sorry for that.
Here is the link that describes the available methods.

This looks promising :slight_smile: I think the MicroPython code to talk to Pixy will help. Getting Pixy to use the serial UART communication should be a straightforward change. The porting guide is good for getting the details of the protocol. The version request/response is a good starting point to test out the nuts and bolts of the communication link, and an oscilloscope is useful as well. What do you think? We’re more than happy to help :slight_smile:

Edward

Hello,

Just a quick update on that topic, I just realized I hadn’t replied yet.
I was able to establish communication between my lego Hub (which I received a few weeks ago) with a raspberry pi using UART.
For speed I was able to use 230400 bauds and I didn’t try to go further since the Pixy doesn’t support it anyway.

I only tested communication in the Hub -> RPi direction for now, but there is no reason that I will encounter errors in the other direction, I try to be carefull when plugin things into the hub.

Regarding other settings it was pretty much what looks to be a standard: 8 data bits, no parity, 1 stop bit. So it matches what is described in the wiki for the Pixy 2, so it should work. I haven’t bought a Pixy2 cam yet so I can’t try, that’s something I’m planning to do in the future.

One quirk about the Lego API is that not everything works like it should:

import hub
from mindstorms.control import wait_for_seconds

port = hub.port
f = port.F
#doesn't work
#f.mode(port.MODE_FULL_DUPLEX, 115200)

#works
f.mode(port.MODE_FULL_DUPLEX)
wait_for_seconds(0.5)
f.baud(115200)

I figured that out while reading someone else’s code on GitHub: antonvh UartRemote library

Regarding which pins are used for ground / TX / RX on the hub, this website was very clear: philohome.com - The Power Functions 2.0 connector
I probably wouldn’t have figured this out on my own.

Hello,
It looks like you’re on the right path – keep us posted :slight_smile:

Edward

Please keep going! I am really looking forward to use Pixy 2.1 with the current generation of Lego Mindstorms!

I actually even wonder why Lego does not go for a cooperation. Put the Cam into a Lego housing and create an extension package for Mindstorms Robot Inventor. Like they did years back with RCX.

is this project still struggling?
I hope that it will success!