Kronos Robotics and Electronics
Site Map
 
Home Zeus Projects App Notes Downloads Dios Athena Forums
 

DAN152

Build a remote IO Port for your PC using the Dios Ultra

  By Michael Simpson

 

In this application note I'm going to show you how to control the world with your PC using a Dios ultra Chip as the interface.   I will keep things simple and we will use a simple commands structure to tell the Dios what we want it to do.   I will use the Dios Mini Ultra in the examples but the code and hookup is the same for all Dios Products and chips.  On the PC side I will use the new KRobject and VB to create the control program.   This can be used as a starting point for your own projects.

 

Programming the Remote IO program

The first thing to do is to program the Dios.  Depending on what chip or board you are using will determine how you do it.  In our case we are using the Dios Mini Ultra.  We are going to use the built-in Uart.  The Uart is located on IO ports 8 and 9.  To get the ports connected to the PC you can use a separate EZ232 Driver connected up to these ports as shown in Figure 1.

Figure 1

This is the easiest way to program the Dios when you are using the UART.   You can use the utility terminal connected to the EZ232 driver. If you are going to do lots of development this is the only way to go.  Another major advantage to this method is that you can use the print command to help debug.   Once you get your development done you can remove the second EZ232 driver and reconfigure the jumpers so the onboard driver is connected to the UART.

The second method is to program the Dios then switch the configure jumpers.  You will have to swap comports as well because you cant use the comport that's connected to the programmer.  The best way to do this is to use the KRconnect utility.   This utility lets you open and close the port.  Here is what  you do.

  • Program the Dios

  • Close the Dios App

  • Reconfigure the jumpers as shown in Figures 2 and 3.

  • Open the port with KRConnect.

  • Test

  • Close Com Port with KRConnect

  • Start Dios software and resume programming

As you can see the first method is much easier.  However since I have written the program for you its not really necessary to use either method at this time unless you want to make modifications.  If you do at that time you can decide how to proceed.

Figure 2

This is the normal programming mode.

 

Figure 3

This is UART Mode

 

The following program is used to monitor the UART.  It collects two bytes then sets or collects data for a given port.

Program  (download it here)

'Remote IO Demo
func main()

   dim cmdidx
   dim cmd
   dim cmddat0,cmddat1
   dim timeoutcounter
   clear

   'Lets use the hardware Uart
   hsersetup baud,HBAUD115200,start,txon,inwait,1000


'------------------------------------------------------
'This is the main loop. At this point we collect the
' data. Once we have two bytes we go and process the
' commands.
'------------------------------------------------------
cmdloop:
   inc timeoutcounter
   if timeoutcounter > 5 then
      timeoutcounter = 0
      cmdidx = 0
      goto cmdloop
   endif
   hserin cmdloop,cmd
   timeoutcounter = 0
  branch cmdidx , cmd0, cmd1

'Fall through
   cmdidx = 0
   goto cmdloop

'This is the first byte. It will be used to tell us what to do
' with the second byte.
cmd0:
   cmddat0 = cmd
   cmdidx = cmdidx + 1
   goto cmdloop

'This is the second byte. In our case its always the port number
cmd1:
   cmddat1 = cmd
   cmdidx = 0
   goto proccmds



'--------------------------------------------------
'At this point we have all the data lets process
'the data. The first byte is our command byte.
'--------------------------------------------------
proccmds:

   branch cmddat0,dosetinput,dosetoutput,dogetinput,dosetoutputhigh,dosetoutputlow

'Fall through BAD COMMAND
   goto cmdloop

dosetinput:
   input cmddat1
   goto cmdloop

dosetoutput:
   output cmddat1
   goto cmdloop

dogetinput:
   hserout ioport(cmddat1)
   goto cmdloop

dosetoutputhigh:
   high cmddat1
   goto cmdloop

dosetoutputlow:
   low cmddat1
   goto cmdloop

endfunc
 

Here is the list of commands for the program.

Description Byte 1  Byte 2
Set Port as Input 0 IO port
Set Port as Output 1 IO port
Return State 2 IO port
Set Port High 3 IO port
Set Port Low 4 IO port

 

Testing Your Program

In order to experiment and to test the program we can use the KRConnect program.  This software is free and located on the Kronos Robotics web site.

After connecting to the UART we send a 1 and 0.  This tells the program that port 0 will be set as output.

Next we send a 3 and 0.  This tells the program we want to make the port high.  Note that you could have sent 1,0,3,0 in one stream.  Command #2 tells the program we want the state of an IO port.   In this case the program will transmit that value.

 

Making your own PC program

Ok this is all fine for testing but what about making your own program on the PC?  You will need 2 things do build your own program.

 

1 MicroSoft Visual Basic Version 6 (I have not tested with VB.net)

2 KRobject (Free and installed with KRConnect)

 

KRobject is an object that will allow you easy access to the Dios or other microprocessors.  You will need to use the references form to use the KRobject. 

 

Once you have referenced the object you start using the object.

I have set up the following form to allow you to experiment

The code looks like this:

Option Explicit
Dim KRobject As New KRComConnect

Private Sub Command1_Click()
Dim ioport As Integer
   ioport = Val(Text1.Text)
   If ioport > 32 Then ioport = 32
   KRobject.SendData Chr(0) + Chr(ioport)
End Sub

Private Sub Command2_Click()
   Dim ioport As Integer
   ioport = Val(Text1.Text)
   If ioport > 32 Then ioport = 32
   KRobject.SendData Chr(1) + Chr(ioport)
End Sub

Private Sub Command3_Click()
   Dim ioport As Integer
   ioport = Val(Text1.Text)
   If ioport > 32 Then ioport = 32
   KRobject.SendData Chr(3) + Chr(ioport)
End Sub

Private Sub Command4_Click()
   Dim ioport As Integer
   ioport = Val(Text1.Text)
   If ioport > 32 Then ioport = 32
   KRobject.SendData Chr(4) + Chr(ioport)
End Sub

Private Sub Command5_Click()
   Dim ioport As Integer
   Dim dat$

   ioport = Val(Text1.Text)
   If ioport > 32 Then ioport = 32

'First clear any dat in KRobject buffer
   dat$ = KRobject.GetData
   DoEvents
   KRobject.SendData Chr(2) + Chr(ioport)
   dat$ = waitforbyte()
   Label2.Caption = Format(Asc(dat$))

End Sub

Private Sub Command6_Click()
'This routine sets the baudrate and com port.
   KRobject.Baud = 115200
   KRobject.Port = 2
   KRobject.ComOpen

End Sub

Private Sub Command7_Click()
   KRobject.FormVisible = True
End Sub

Function waitforbyte() As String

   Dim tdat$

DataLoop:
   tdat$ = KRobject.GetData
   DoEvents
   If tdat$ = "" Then GoTo DataLoop
   waitforbyte = tdat$
End Function


You can download the complete VB project here.  Its beyond the scope of this application note to teach you how to use visual basic but this sample project should get you started.  Once you install KRConnect a help file for the KRObject will be installed.  That help file will give you all the interface specs needed.

 

Where do we go from here?

Well the next logical step would be to add a command to setup some analog to digital ports.   Also if you want to communicate with multiple devices you will need to use the CoProc libraries.   I will do a similar application note showing how to do this.

All in all the sky is the limit.  You can add a LCD or IR Remote.  Create the ultimate burglar alarm.

 

Parts

Breadboard Speaker

 

 

DiosPro 40 Pin Chip

Dios Workboard Deluxe

 

Easy RS232 Driver  

DiosPro 28 Pin Chip

Dios 32 Pin Carrier (Carrier #1)

 

9 Pin Cable

Breadboard Regulator

 

Copyright © 2001 - 2007 Kronos Robotics