# Micropython, Thonny,  Raspberry Pico & USB port



## Neptunus (Sep 18, 2022)

Hi,
I am trying to react my development boards in Thonny IDE,  there seems to be a permission issue with the USB port and USB device permission! 
Which ports and and permission do i need for to configure? 
I am fresh rookie with FreeBSD so please give me a noob friendly and understandable guide!


----------



## hselasky@ (Sep 18, 2022)

Is your application using libusb or /dev/XXX ?

Try to use `usbconfig` and `chown XXX:XXX /dev/ugenX.Y` to your user.


----------



## Neptunus (Sep 18, 2022)

hselasky@ said:


> Is your application using libusb or /dev/XXX ?
> 
> Try to use `usbconfig` and `chown XXX:XXX /dev/ugenX.Y` to your user.




```
# usbconfig  
ugen1.1: <Intel EHCI root HUB> at usbus1, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=SAVE (0mA)
ugen2.1: <Intel EHCI root HUB> at usbus2, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=SAVE (0mA)
ugen0.1: <Intel XHCI root HUB> at usbus0, cfg=0 md=HOST spd=SUPER (5.0Gbps) pwr=SAVE (0mA)
ugen0.2: <A4Tech USB Optical Mouse> at usbus0, cfg=0 md=HOST spd=LOW (1.5Mbps) pwr=ON (100mA)
ugen1.2: <vendor 0x8087 product 0x8008> at usbus1, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=SAVE (0mA)
ugen2.2: <vendor 0x8087 product 0x8000> at usbus2, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=SAVE (0mA)
ugen0.3: <vendor 0x8087 product 0x0032> at usbus0, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON (100mA)
ugen0.4: <MicroPython Pyboard Virtual Comm Port in FS Mode> at usbus0, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON
(500mA)
#
```


----------



## Neptunus (Sep 18, 2022)

Neptunus said:


> # usbconfig
> ugen1.1: <Intel EHCI root HUB> at usbus1, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=SAVE (0mA)
> ugen2.1: <Intel EHCI root HUB> at usbus2, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=SAVE (0mA)
> ugen0.1: <Intel XHCI root HUB> at usbus0, cfg=0 md=HOST spd=SUPER (5.0Gbps) pwr=SAVE (0mA)
> ...


this is the output i get in the Thonny shell:
Couldn't find the device automatically. 
Check the connection (making sure the device is not in bootloader mode) or choose
"Configure interpreter" in the interpreter menu (bottom-right corner of the window)
to select specific port or another interpreter.

i have installed the arm-none-eabi-gcc arm-none-eabi-newlib and pip install pyusb.


----------



## Neptunus (Sep 18, 2022)

in linux i hade to typ cmd: chmod a+rw /dev/ttyACM0.
the question is now how to i find that  chown XXX:XXX /dev/ugenX.Y


----------



## elgrande (Sep 18, 2022)

I guess in your case it is `chown <your_user>:<your_group> /dev/ugen0.4`


----------



## Neptunus (Sep 18, 2022)

elgrande said:


> I guess in your case it is `chown <your_user>:<your_group> /dev/ugen0.4`


so the cmd will be be the following : chown neptunus:wheel /dev/ugen0.4


----------



## elgrande (Sep 18, 2022)

Neptunus said:


> so the cmd will be be the following : chown neptunus:wheel /dev/ugen0.4


Sounds right to me


----------



## hselasky@ (Sep 19, 2022)

Linux: /dev/ttyACM0
FreeBSD: /dev/cuaU0


----------



## hselasky@ (Sep 19, 2022)

If your device shows up like /dev/cuaU0 there is an "dialer" group which you can add users to, which give access.

Also try:
`usbconfig show_ifdrv`


----------



## mer (Sep 19, 2022)

Or you could add a devd config file in /usr/local/etc/devd that does something like below.  This is specific for a
Nikon D610 camera ,but if you change vendor/product you can make it work for your device.

`notify 100 {
       match "vendor" "0x04B0";
       match "product" "0x0434";
       action "chgrp wheel /dev/$cdev && chmod 660 /dev/$cdev";
};`


----------



## Neptunus (Sep 19, 2022)

hselasky@ said:


> If your device shows up like /dev/cuaU0 there is an "dialer" group which you can add users to, which give access.
> 
> Also try:
> `usbconfig show_ifdrv`





> # usbconfig show_ifdrv
> ugen1.1: <Intel EHCI root HUB> at usbus1, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=SAVE (0mA)
> ugen1.1.0: uhub0: <Intel EHCI root HUB, class 9/0, rev 2.00/1.00, addr 1>
> ugen2.1: <Intel EHCI root HUB> at usbus2, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=SAVE (0mA)
> ...


Thank you for you reply,


> ugen0.2: <MicroPython Pyboard Virtual Comm Port in FS Mode> at usbus0, cfg=0 md=HOST spd=FULL (12Mbps) pwr=ON (500mA)
> ugen0.2.0: umass0: <MicroPython Pyboard Virtual Comm Port in FS Mode, class 239/2, rev 2.00/2.00, addr 1>
> ugen0.2.1: umodem0: <MicroPython Pyboard Virtual Comm Port in FS Mode, class 239/2, rev 2.00/2.00, addr 1>


its says at usbus0, so i assume that this might be the /dev/cuaU0
can you briefly guide me with the command line ?


----------



## Neptunus (Sep 19, 2022)

after the following cmd in Konsole @ root:


> chown a+rw /dev/cuaU0


when i start Thonny i still get the following output in the shell>


> Couldn't find the device automatically.
> Check the connection (making sure the device is not in bootloader mode) or choose
> "Configure interpreter" in the interpreter menu (bottom-right corner of the window)
> to select specific port or another interpreter.


----------



## Neptunus (Sep 19, 2022)

i did this:


> root@Core:~ # id neptunus
> uid=1001(neptunus) gid=1001(neptunus) groups=1001(neptunus),0(wheel),44(video)


and then i did this:


> pw usermod neptunus -G dialer


and when i did that and typ : id neptunus


> uid=1001(neptunus) gid=1001(neptunus) groups=1001(neptunus),68(dialer)


what confuses me now, just a moment ago i hade this: 


> uid=1001(neptunus) gid=1001(neptunus) groups=1001(neptunus),0(wheel),44(video) and went to this > uid=1001(neptunus) gid=1001(neptunus) groups=1001(neptunus),68(dialer)


----------



## Neptunus (Sep 19, 2022)

Now the good news is, when i go back into Thonny and settings and change the port from automatic to cuau0, it connects and i get this output in the shell:


> MicroPython v1.12-351-gbd5633778 on 2020-04-08; MCUDEV STM32F407VE with STM32F407VE
> Type "help()" for more information.
> >>>


it means ut is connected! but why does it not connect when the port option is set to automatic?


----------



## Neptunus (Sep 19, 2022)

really confusing, i disconnected and reconnected the board and the shell gives me:


> Unable to connect to /dev/cuaU0: [Errno 13] could not open port /dev/cuaU0: [Errno 13] Permission denied: '/dev/cuaU0'
> 
> Backend terminated or disconnected. Use 'Stop/Restart' to restart.


when i restarted the Thonny IDE i still get the same output!


----------



## SirDice (Sep 20, 2022)

Neptunus said:


> i disconnected and reconnected the board and the shell gives me:


Devices are created dynamically. The second you disconnect the device the associated /dev/cuaU0 device disappears. When you reconnect a _new_ device node is created. It's the same as creating a file, setting some permissions on that file and removing the whole file. When you recreate the file those original permissions are gone, it's a _new_ file. 









						C - Raspberry Pi Pico
					

Received a Raspberry Pi Pico in the mail today. I love getting new toys to play with. This thing is tiny ♥️   I assume this will just work fine on FreeBSD as you it just mounts a drive and you copy some application to it, then it should just work. But I want to try to compile some native C/C++...




					forums.freebsd.org


----------



## SirDice (Sep 20, 2022)

`pw usermod neptunus -G dialer`
Wrong command. This doesn't _add_ the dialer group to the neptunes user, it _replaces_ all secondary groups of that user with the list given by `-G`


```
-G grouplist  Set secondary group memberships for an account.  grouplist
                   is a comma, space, or tab-separated list of group names or
                   group numbers.  The user is added to the groups specified
                   in grouplist, and removed from all groups not specified.
                   The current login session is not affected by group
                   membership changes, which only take effect when the user
                   reconnects.  Note: do not add a user to their primary group
                   with grouplist.
```

If you just wanted to _add_ this user to the dailer group you use `pw groupmod dialer -m neptunes` You need to modify the group, not the user. Simply put, you are adding a user to a group, not the other way around (adding a group to a user). 


```
-m newmembers  Similar to -M, this option allows the addition of existing
                    users to a group without replacing the existing list of
                    members.  Login names or user ids may be used, and
                    duplicate users are silently eliminated.
```


----------



## Neptunus (Sep 21, 2022)

SirDice said:


> `pw usermod neptunus -G dialer`
> Wrong command. This doesn't _add_ the dialer group to the neptunes user, it _replaces_ all secondary groups of that user with the list given by `-G`
> 
> 
> ...


Thank you SirDice!
is sudo pip install pyusb necessary?


----------



## SirDice (Sep 22, 2022)

I can't remember if I needed anything extra, just the permissions on the USB port, for Thonny to work with the Pico. But I'm fairly sure I didn't need to use `pip`.


----------

