How do you read/write serial data using mBot 2.4g USB WiFi dongle?


#1

Hi All,

I’ve just got the mBot Blue 2.4g (WiFi) model, and am trying to write a Python program that interfaces via the serial port. I’m using a Windows 7 laptop.

Connecting directly using a USB cable works fine: I can read/write via COM5 port using pySerial.

However, connecting the wireless 2.4g white USB dongle, I can’t read from any COM port (the one I can connect to is COM3, which I reckon must be connected to another serial port on my laptop).

Have I got it wrong, and connecting the wireless 2.4g USB dongle doesn’t create a COM serial port for me to use? If so, how on earth do I connect to the mBot from a Python program using the 2.4g dongle?


#2

I’ve been doing a bit more digging, and have ascertained that the WiFi USB device appears as a USB HID.

I’ve compiled lib-usb1 backend library from https://github.com/libusb/libusb , and installed PyUSB from http://walac.github.io/pyusb/ .

In my simple Python program, I can now enumerate the device and its ‘endpoints’, and see that there are two USB Interrupt endpoints on the device (one for IN and one for OUT).

However… attempts to perform an interrupt read from the device returns a USB error. sigh

Does anyone have any experience trying to do this, either successfully or not? I currently have no idea how the Makeblock program manages to talk to the mBot via the dongle, so trying to recreate this using Python and native USB library is going to be tough…

Does anyone know whether the serial reads/writes in the firmware code that you upload to the mBot actually transfer data over the 2.4g WiFi? or only the physically connected USB cable? Are there other commands you have to call to initialise the WiFi?

Any help most appreciated… or at least some consolation!


#3

Eureka!

I was getting LIBUSB_ERROR_IO, and it would seem this was simply due to me trying to read 1 byte at a time.

I changed the read method arguments to request 32 bytes, and down came the data! Woo hoo! :joy:

Now to write all the encoding/decoding…


#4

Hi,
I had simiral problems. I found solution. If you are interested, check https://vrbaj.github.io/mbot/. I used pywinusb, so it is working great under windows os.


#5