Why is the USB_VCP module gone?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
bittware
Posts: 45
Joined: Mon Aug 18, 2014 3:27 am

Why is the USB_VCP module gone?

Post by bittware » Sat Sep 13, 2014 11:49 am

Hello,
After I flashed in latest micropython, I can not find the USB_VCP module which is mentioned in documentation.
While repl_uart module seems like the substitution. Then I tried
>>>vcp = repl_uart()
>>>vcp.send(1, timeout=500)
But it prompted me "AttributeError: 'NoneType' object has no attribute 'send' "
All example codes that I can find lack info. regarding this USB_VCP/repl_uart.
Can anybody help me on this? Thanks.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Why is the USB_VCP module gone?

Post by dhylands » Sat Sep 13, 2014 4:24 pm

USB_VCP is documented here: http://micropython.org/doc/module/pyb/USB_VCP

Here is an exmple that uses it: https://github.com/dhylands/upy-example ... er/keys.py and here's how you use repl_uart: https://github.com/dhylands/upy-example ... er/boot.py (look at the init function). Running repl_uart with no args returns whatever was previously set or None if it hsasn't been set yet.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Why is the USB_VCP module gone?

Post by dhylands » Sat Sep 13, 2014 4:31 pm

What repl_uart does is cause the REPL to be sent to a UART, in addition to having it on the USB serial. By default the repl only goes to the usb. repl_uart() returns None in this case, which is why you got the error you did.

bittware
Posts: 45
Joined: Mon Aug 18, 2014 3:27 am

Re: Why is the USB_VCP module gone?

Post by bittware » Sun Sep 14, 2014 2:21 am

dhylands wrote:USB_VCP is documented here: http://micropython.org/doc/module/pyb/USB_VCP

Here is an exmple that uses it: https://github.com/dhylands/upy-example ... er/keys.py and here's how you use repl_uart: https://github.com/dhylands/upy-example ... er/boot.py (look at the init function). Running repl_uart with no args returns whatever was previously set or None if it hsasn't been set yet.
The question is USB_VCP does not exist in lastest micropython build any more. It's gone. How can I find it back?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Why is the USB_VCP module gone?

Post by dhylands » Sun Sep 14, 2014 2:57 am

bittware wrote:
dhylands wrote:USB_VCP is documented here: http://micropython.org/doc/module/pyb/USB_VCP

Here is an exmple that uses it: https://github.com/dhylands/upy-example ... er/keys.py and here's how you use repl_uart: https://github.com/dhylands/upy-example ... er/boot.py (look at the init function). Running repl_uart with no args returns whatever was previously set or None if it hsasn't been set yet.
The question is USB_VCP does not exist in lastest micropython build any more. It's gone. How can I find it back?
Sure it is. I just built the latest, flashed it and this is what I see:

Code: Select all

Micro Python v1.3.1-75-g8369559 on 2014-09-13; PYBv1.0 with STM32F405RG
Type "help()" for more information.
>>> 'USB_VCP' in dir(pyb) 
True
>>> pyb.USB_VCP
<class 'USB_VCP'>
>>> u = pyb.USB_VCP()
>>> u.send('Test\r\n')
Test
6
USB_VCP is in the pyb module, and normally boot.py has an import pyb statement in it, so pyb is already imported in your REPL. If, for some reason your boot.py doesn't have an import pyb statement, then you'll need to do

Code: Select all

import pyb
from the REPL before pyb.USB_VCP() will work.

bittware
Posts: 45
Joined: Mon Aug 18, 2014 3:27 am

Re: Why is the USB_VCP module gone?

Post by bittware » Sun Sep 14, 2014 3:41 am

dhylands wrote:
bittware wrote:
dhylands wrote:USB_VCP is documented here: http://micropython.org/doc/module/pyb/USB_VCP

Here is an exmple that uses it: https://github.com/dhylands/upy-example ... er/keys.py and here's how you use repl_uart: https://github.com/dhylands/upy-example ... er/boot.py (look at the init function). Running repl_uart with no args returns whatever was previously set or None if it hsasn't been set yet.
The question is USB_VCP does not exist in lastest micropython build any more. It's gone. How can I find it back?
Sure it is. I just built the latest, flashed it and this is what I see:

Code: Select all

Micro Python v1.3.1-75-g8369559 on 2014-09-13; PYBv1.0 with STM32F405RG
Type "help()" for more information.
>>> 'USB_VCP' in dir(pyb) 
True
>>> pyb.USB_VCP
<class 'USB_VCP'>
>>> u = pyb.USB_VCP()
>>> u.send('Test\r\n')
Test
6
USB_VCP is in the pyb module, and normally boot.py has an import pyb statement in it, so pyb is already imported in your REPL. If, for some reason your boot.py doesn't have an import pyb statement, then you'll need to do

Code: Select all

import pyb
from the REPL before pyb.USB_VCP() will work.
Hi, dhylands
Thanks for the timely feedback.
See the attached picture for what I got. There is no USB_VCP within pyb and sys modules.
I might flash the wrong version of mircopython. Then how could I read out mircopython version running on my chip?
Attachments
2014-09-14 11_34_14-COM3 - PuTTY.png
2014-09-14 11_34_14-COM3 - PuTTY.png (37.26 KiB) Viewed 9804 times

bittware
Posts: 45
Joined: Mon Aug 18, 2014 3:27 am

Re: Why is the USB_VCP module gone?

Post by bittware » Sun Sep 14, 2014 3:49 am

dhylands wrote:
bittware wrote:
dhylands wrote:USB_VCP is documented here: http://micropython.org/doc/module/pyb/USB_VCP

Here is an exmple that uses it: https://github.com/dhylands/upy-example ... er/keys.py and here's how you use repl_uart: https://github.com/dhylands/upy-example ... er/boot.py (look at the init function). Running repl_uart with no args returns whatever was previously set or None if it hsasn't been set yet.
The question is USB_VCP does not exist in lastest micropython build any more. It's gone. How can I find it back?
Sure it is. I just built the latest, flashed it and this is what I see:

Code: Select all

Micro Python v1.3.1-75-g8369559 on 2014-09-13; PYBv1.0 with STM32F405RG
Type "help()" for more information.
>>> 'USB_VCP' in dir(pyb) 
True
>>> pyb.USB_VCP
<class 'USB_VCP'>
>>> u = pyb.USB_VCP()
>>> u.send('Test\r\n')
Test
6
USB_VCP is in the pyb module, and normally boot.py has an import pyb statement in it, so pyb is already imported in your REPL. If, for some reason your boot.py doesn't have an import pyb statement, then you'll need to do

Code: Select all

import pyb
from the REPL before pyb.USB_VCP() will work.
Hi dhylands,
I just commented out all codes in main.py. I saw the first prompt containing the micropython version info. as captured in the attached picture.
It is version 1.2-15-g951ed9d on 2014-07-20.
At least in this version, the USB_VCP does not exist.
It also seems I might have flashed the wrong file two days agao.
Attachments
2014-09-14 11_44_20-COM3 - PuTTY.png
2014-09-14 11_44_20-COM3 - PuTTY.png (34.25 KiB) Viewed 9804 times

bittware
Posts: 45
Joined: Mon Aug 18, 2014 3:27 am

Re: Why is the USB_VCP module gone?

Post by bittware » Sun Sep 14, 2014 3:59 am

dhylands wrote:
bittware wrote:
dhylands wrote:USB_VCP is documented here: http://micropython.org/doc/module/pyb/USB_VCP

Here is an exmple that uses it: https://github.com/dhylands/upy-example ... er/keys.py and here's how you use repl_uart: https://github.com/dhylands/upy-example ... er/boot.py (look at the init function). Running repl_uart with no args returns whatever was previously set or None if it hsasn't been set yet.
The question is USB_VCP does not exist in lastest micropython build any more. It's gone. How can I find it back?
Sure it is. I just built the latest, flashed it and this is what I see:

Code: Select all

Micro Python v1.3.1-75-g8369559 on 2014-09-13; PYBv1.0 with STM32F405RG
Type "help()" for more information.
>>> 'USB_VCP' in dir(pyb) 
True
>>> pyb.USB_VCP
<class 'USB_VCP'>
>>> u = pyb.USB_VCP()
>>> u.send('Test\r\n')
Test
6
USB_VCP is in the pyb module, and normally boot.py has an import pyb statement in it, so pyb is already imported in your REPL. If, for some reason your boot.py doesn't have an import pyb statement, then you'll need to do

Code: Select all

import pyb
from the REPL before pyb.USB_VCP() will work.
Hi, dhylands
I just tried the latest version. It works. Thanks for the help.
But one more thing, is there any way that USB_VCP baud rate could be customized just like what UART does?
Thanks again.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Why is the USB_VCP module gone?

Post by dhylands » Sun Sep 14, 2014 5:01 am

USB_VCP has no concept of baud rate. It isn't needed.

When you connect to usb_serial, the baud rate that you use is ignored. You only need a baud rate with a UART.

bittware
Posts: 45
Joined: Mon Aug 18, 2014 3:27 am

Re: Why is the USB_VCP module gone?

Post by bittware » Sun Sep 14, 2014 6:38 am

dhylands wrote:USB_VCP has no concept of baud rate. It isn't needed.

When you connect to usb_serial, the baud rate that you use is ignored. You only need a baud rate with a UART.
I know REPL needs baud rate of 115200 which is fixed by design.
However, once I need USB_VCP for other purpose, e.g. customized data transmission, then I need to lower this baud rate in order to interface the communication software running on PC. This software communication does not support baud rate of 115200.

Post Reply