Connecting several Yoctopuce modules at the same time

Connecting several Yoctopuce modules at the same time

There is a beginner's question which comes back to support from time to time: can you use several Yoctopuce modules, identical or not, on the same machine? The answer is obviously yes. It was even a requirement that figured prominently when we imagined the general design of Yoctopuce products ten years ago. This being said, we could develop our answer some more...



Don't smile, even if this is a beginner's question, it remains a relevant question. Many cheap competing products have trouble when you try to connect several of them on the same machine:

  • Many are based on serial over USB protocols: connecting them creates a virtual serial port that applications can use to communicate with the device. It's practical and easy to use in any programming language. The catch is that it's difficult to know in advance the port number which is going to be created, moreover this number can sometimes change if you connect the device on a different USB port. The solution used by many editors is to scan all the serial ports until you find the correct device, which brings us to the second issue.
  • One way to simplify mass production of an electronic product consists in manufacturing strictly identical products, at the hardware level and at the firmware level. Thus, if you have two strictly identical modules connected to the same machine, you have no way to distinguish them from one another. Even worse, you can't even be 100% sure of the port number which was assigned to them, because there is no guarantee that the wiring has not been reversed at some point.

So you can wonder how Yoctopuce did to avoid these issues.

The Yoctopuce version

USB products of the Yocto range are not using the serial over USB technology, but a "HID vendor specific" protocol. This has numerous advantages:

  • No need for a serial communication port
  • No need to install a driver because there is always a HID driver installed on all the machines of the creation: it is used by the keyboard and the mouse

Serial numbers

Moreover, all the Yoctopuce modules of the same model are not strictly identical: they all have a distinct serial number. At Yoctopuce, we have a whole infrastructure which ensures that all the modules which come out have a unique serial number. This serial number is stored in a non-erasable area of the module's microcontroller and cannot be modified.

Thanks to this, you can connect several Yoctopuce modules, identical or not, on the same machine and distinguish them without any ambiguity.

Logical names

However, you don't necessarily want to hard code the serial numbers of all your modules in your software. Therefore, you can assign to each module and each feature of a module a logical name to identify its function. These names are stored in the non-volatile memory of the microcontroller: they resist to a restart of the module. It's very useful if you want to make several copies of the same system based on Yoctopuce modules.

Of course, all the Yoctopuce programming libraries enable you to list all the Yoctopuce modules connected to a machine and to retrieve both their serial numbers and their logical names. You can find more details in this post.

Limitations

As always, it's not totally magical: there are limitations. For example, it's not because there are 127 available addresses on a USB bus that you can connect 127 USB devices at the same time. Your computer and your operating system probably have a much lower limit.
The Yoctopuce API has another limitation: on the same machine, you can have only one program at a time which talks to Yoctopuce modules in USB mode. This may seem a problem if you intend to run several independent experiments on the same machine, but in fact you can easily work around this limitation thanks to the network mode.

The VirtualHub

You don't have to connect all your modules directly on the machine on which your monitoring program is running. You can find in the "support" section of the Yoctopuce web site a small program called VirtualHub. Not only does this program provide an interface to configure the Yoctopuce modules, but it also provides network access to the Yoctopuce modules connected to the machine on which it is running. And switching a program from USB mode to network mode requires only one line of code.

Nothing prevents you from using the network mode to access the local machine. Thus, if we run a VirtualHub on our machine and that in our code we replace the call

YAPI.RegisterHub("usb",errmsg)


by

YAPI.RegisterHub("127.0.0.1",errmsg)


we access the Yoctopuce modules connected to the local machine through the VirtualHub and we don't have the limitation on the number of different programs which access the Yoctopuce modules at the same time. Note however that the VirtualHub counts as one program which runs in USB mode.

Conclusion

Yes, you can connect several Yoctopuce modules at the same time on the same machine, they were designed for this purpose. There are indeed some limitations, but you can easily work around them.

Add a comment No comment yet Back to blog












Yoctopuce, get your stuff connected.