Controlling Microcontroller

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
22 posts Page 1 of 3
Contributors
Filip
Coding Guru
Coding Guru
Posts: 833
Joined: Wed Jan 05, 2011 3:59 pm

Controlling Microcontroller
Filip
Hello,

This tutorial will show you how to connect to serial and write something in it.

Imports:
Code: Select all
Imporst System.IO.Ports
1. Listing all Serial(COM) ports to control (in code ComboBox)

This will get name of port
Code: Select all
Dim ports As String() = SerialPort.GetPortNames()
Code below will add ports to control (ComboBox)
Code: Select all
Dim port As String
        For Each port In ports
            ComboBox1.Items.Add(port)

        Next port
2. Connecting to port selected by user

Add this under Class
Code: Select all
Dim serialPort As New SerialPort
Code below will select serial port and open(connect) to it
Code: Select all
Try
                    serialPort.PortName = ComboBox1.SelectedItem
                    serialPort.Open()
Catch ex as exception 

End Try
Disconecting:
Code: Select all
serialPort.close()
serialPort.dispose()
3. Writing/reading to serial port
Writing:
Code: Select all
serialPort.Write("something")
Reading:
Code: Select all
Dim string As String = serialPort.ReadLine()
That's all

-visioncr0
Last edited by Filip on Sat Dec 24, 2011 6:37 pm, edited 1 time in total.
CodenStuff wrote:
Nope, it's just your sick and dirty mind. You sick twisted warped little pervo :D
User avatar
Axel
Coding God
Coding God
Posts: 1928
Joined: Sun Jun 27, 2010 9:15 pm

Re: Using Serial ports..
Axel
Hmm , I don't have any experience with this, but is a serial port a usb port ?
http://vagex.com/?ref=25000
Filip
Coding Guru
Coding Guru
Posts: 833
Joined: Wed Jan 05, 2011 3:59 pm

Re: Using Serial ports..
Filip
Axel wrote:
Hmm , I don't have any experience with this, but is a serial port a usb port ?
Yes, I'm using it to control my robot
CodenStuff wrote:
Nope, it's just your sick and dirty mind. You sick twisted warped little pervo :D
User avatar
Axel
Coding God
Coding God
Posts: 1928
Joined: Sun Jun 27, 2010 9:15 pm

Re: Using Serial ports..
Axel
Oh but can you explain more how to send power to the wires of a usb cable ?
http://vagex.com/?ref=25000
Filip
Coding Guru
Coding Guru
Posts: 833
Joined: Wed Jan 05, 2011 3:59 pm

Re: Using Serial ports..
Filip
Axel wrote:
Oh but can you explain more how to send power to the wires of a usb cable ?
Have you ever used HyperTerminal?

It is working this way:

I have a robot and this is a part of code witch is uploaded on flash memory onboard:
Code: Select all
  case 'w'://Move Forward 
    forward (leftspeed,rightspeed); 
    break; 
So when I send code below to robot
Code: Select all
serialPort.write("w")
It moves forward :)
CodenStuff wrote:
Nope, it's just your sick and dirty mind. You sick twisted warped little pervo :D
User avatar
Axel
Coding God
Coding God
Posts: 1928
Joined: Sun Jun 27, 2010 9:15 pm

Re: Using Serial ports..
Axel
Yes but you don't do the hard stuff right ? Because your robot processes it lol
http://vagex.com/?ref=25000
Filip
Coding Guru
Coding Guru
Posts: 833
Joined: Wed Jan 05, 2011 3:59 pm

Re: Using Serial ports..
Filip
Axel wrote:
Yes but you don't do the hard stuff right ? Because your robot processes it lol
Ohhh really.. I changed title of topic lol
CodenStuff wrote:
Nope, it's just your sick and dirty mind. You sick twisted warped little pervo :D
User avatar
Ffenixw0rks
VIP - Donator
VIP - Donator
Posts: 152
Joined: Sun Jun 19, 2011 2:51 pm

Re: Controlling Microcontroller
Ffenixw0rks
Not working for me. Combobox is empty and when I try msgbox(serialport.GetPortNames) - message box is not displaying! dunnno;
Maybe it's because of my notebook, but still...
Image
Filip
Coding Guru
Coding Guru
Posts: 833
Joined: Wed Jan 05, 2011 3:59 pm

Re: Controlling Microcontroller
Filip
Ffenixw0rks wrote:
Not working for me. Combobox is empty and when I try msgbox(serialport.GetPortNames) - message box is not displaying! dunnno;
Maybe it's because of my notebook, but still...
This won't list avalible ports but witch are in use. Are you sure something is connected to com(USB) port? Do you have drivers installed?

Because it lists all ports to me..
CodenStuff wrote:
Nope, it's just your sick and dirty mind. You sick twisted warped little pervo :D
User avatar
Ffenixw0rks
VIP - Donator
VIP - Donator
Posts: 152
Joined: Sun Jun 19, 2011 2:51 pm

Re: Controlling Microcontroller
Ffenixw0rks
Devices that was connected to computer: IPod and USB mouse.
Drivers for that devices are installed and working fine.
Image
22 posts Page 1 of 3
Return to “Tutorials”