Tuesday, December 12, 2017

How to remove unused USB serial ports in windows and change port numbers

Sometimes when you connect usb to serial adapter to your pc it gets com number with very high numbers. Not every software can handle that big port numbers. For example some programs cannot work with port numbers higher than com20. So if 20 com ports are in use it is impossible to use that software.  That happens because every time you plug in new USB to serial adapter it gets new com port number, and even if you do not use it anymore port is marked as "in use".
To delete these ports open elevated command prompt: find cmd, right click on it and select "run as administrator".
Then type:

set DEVMGR_SHOW_NONPRESENT_DEVICES=1

after that run device manager:

devmgmt.msc

Enable "Show hidden devices" in the "View" menu, and uninstall grayed-out COM ports

After that you can change your device com port number: right click on it, select properties, then  advanced setting.

Friday, August 25, 2017

Remotely rename computer in windows domain.

run from cli:

netdom renamecomputer old_name  /newname:new_name  /userd:domain_admin_login  /passwordd:domain_admin_pwd

computer will be renamed after restart. If add /reboot:10 computer will be forsibly rebooted after 10 seconds.

Wednesday, August 9, 2017

How to unbrick Arduino Pro Micro 3v3 8MHz version

Recently a made a project with 3v3 version of arduino  pro micro. And accidentally uploaded sketch for arduino Micro. After that I got bricked arduino board. It was not recognized by windows, there was problems with usb enumeration(also "device descriptor request failed", "unrecognized device" etc.).
It seems that problem was with wrong bootloader, so I took my USBasp, connected it to arduino board. From arduino IDE selected right board - "SparkFun Pro Micro", selected processor Atmega32U4 (3.3V 8MHz) and tried to burn bootloader. Got an error - "verification error, first mismatch at byte 0x0000 0xce != 0xfe".
Then I tried to flash bootloader from 5V 16Mhz version, and it was uploaded successfully, but surely because of wrong crystal settings board was still bricked("usb enumeration problems").
So, solution for this is very easy, all you need is swap 3v3 and 5v bootloaders and load bootloader as it was 5v version.

To do this go to:
c:\Users\<username>\AppData\Roaming\Arduino15\packages\SparkFun\hardware\avr\1.1.6\bootloaders\caterina\

and find files Caterina-promicro8.hex and  Caterina-promicro16.hex then rename these files so Caterina-promicro8 -> Caterina-promicro16,  
Caterina-promicro16 -> Caterina-promicro8

after that go to arduino IDE, select SparkFun Pro Micro board,
select Processor Atmega32U4 (5V 16MHz),
select programmer "USBasp",
connect board to programmer and hit "Burn bootloader"

After that board was functional again.
Do not forget to rename bootloader files back to original.
If you do not have USBasp you can use another arduino board as programmer,but do not forget that levels must be the same 5v or 3v3 or use level shifters.

Tuesday, February 21, 2017

Fixed names for usb devices in linux

usb devices appear as /dev/ttyUSB<somenumber> devices. When you plug it to another USB port <somenumber> is unpredictable and you always wasting time to figure out what is the right port number for your device.
To fix this, you can create "udev" rules, so every time you plug in your device there will be the same sym link created for that particular device.

Check vendor and product id with lsusb command:

~# lsusb
Bus 001 Device 011: ID 0403:6001 FTDI FT232 USB-Serial (UART) IC 
Bus 001 Device 010: ID 0403:6001 FTDI FT232 USB-Serial (UART) IC 

ok, we have 2 FTDI chips and we can't distinguish which chip is from what device.
Let's check device serial number(we know that it is connected to ttyUSB0):

~# udevadm info -a -n /dev/ttyUSB0 | grep '{serial}'
 ATTRS{serial}=="0000:00:14.0"

Then go to /etc/udev/rules.d and create file 99-usb-serial.rules
~#sudo touch 99-usb-serial.rules

open file for edit and add these line:

SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="0000:00:14.0", SYMLINK+="arduino"

Now everytime when you plug in your board it will be accesible via symlink /dev/arduino

~# ls -l /dev/arduino 
lrwxrwxrwx 1 root root 7 Nov 15 20:11 /dev/arduino -> ttyUSB0

~# ls -l /dev/ttyUSB0
crw-rw---- 1 root uucp 188, 0 Nov 15 20:11 /dev/ttyUSB1