Serial Interface: On-line code

Robot friends:

I’ve finally managed to figure out how to command the VEX controller via the serial port “on line” mode (after a lot of trial and error). I still can’t read all the sensors yet (but I’m working on it) but here is how to talk to the motors.

I’ve written a Visual Basic program (learning edition available free from Microsoft) that talks to the VEX controller

This subroutine sets the motors via the serial port. The online code has a comand string with 8 bytes of data. The first byte must be “AA” (hexadecimal) and the second “55” (also in hex). Then send the motor number, a zero, and then the setting from 0-255. Byte 5 is the command byte, and 21 (decimal, 15 hex) is the command to write to the PWM motor control. Follow with two more 00 bytes.

You call it with a statement like “MotorControl(1,127)”

Sub MotorControl(ByVal mtr As Integer, ByVal val As Integer)
    Dim crlf As String = ControlChars.CrLf
    mtr = mtr - 1 '0 - 7 for motors
    Dim myBuff(9) As Byte
    Dim offset As Integer
    Dim count As Integer
    offset = 0
    count = 8
    myBuff(0) = &HAA
    myBuff(1) = &H55
    myBuff(2) = mtr
    myBuff(3) = 0
    myBuff(4) = val
    myBuff(5) = 21
    myBuff(6) = 0
    myBuff(7) = 0
    myBuff(8) = 0
    Try
        SerialPort1.Write(myBuff, offset, count)
    Catch ex As Exception
        Console.WriteLine("An Error occured motor control: '{0}'", ex)
    End Try

End Sub

This is working just fine. Remember to download the “online” code to the VEX controller. I have a minature laptop commanding a VEX robot via wifi.

Cheers,
Francis Govers

Thanks fxgovers for posting this information… I have not started working with much beyond the Basic Vex and EasyC.

MarkO

Here are the rest of the command codes for “DDT” (Dynamic Debug) that the on-line mode uses. You can see that “21” writes to the PWM (Pulse Width modulated) motor drivers.

#define READ_CMD 0 // Dynamic Debug commands
#define READ_PWMs 1 // Reads PWM data
#define READ_rxSPI 2 // Used for reading rxdata
#define READ_txSPI 3 // Used for reading txdata
#define UPDATE_PWM_MASK 7 // Used for updating the PWM Mask
#define READ_EE_DATA 8 // Used for reading EE data

#define WRITE_CMD 20
#define WRITE_PWMs 21 // Updates PWM data
#define WRITE_rxSPI 22 // Used for updating rxdata
#define WRITE_txSPI 23 // Used for updating txdata
#define WRITE_EE_DATA 25 // Used for writing EE data

fxgovers

What you have accomplished is fantastic! It seems to me that networking Vex Controllers is now possible using the technique that you discovered with its serial ports. Could you explain how this is done (which Vex Ports are used) and describe the actual Vex application code that you wrote? Did you need to do any voltage level translation for the RS-232 interface? I am sure Vex users including myself would be curious to know.

He is using the Debug Code found in the IFI Downloader.

No voltage translation would need to be done between the Vex Controllers, just between the Vex Controller and the PC, using the Programming Module.

MarkO is right. I should have said that I have the programming cable and use it for commanding. A programming cable is necessary to put the VEX into on-line mode (althought I’ll have to try debug mode with the default code. I’ll report back as soon as I can try this). If you don’t have the programming cable this will not work… It is theoretically possible to build a simple level shifter for the RS-232 signals using a max232 chip, but I’ve not tried it with my program.

So sorry, programming cable required for now.

I tried this with the default code, and had no success. You must have a programming cable and kit for this technique to work.

Sorry.

Francis Govers

If you just wanted to network vexes with out using some kind of other computer in between, than you could use the sparkfun bluetooth radios or similar connected to the tx/rx and write your own serial driver on the vex.

What is being done here is cool because it uses the DDT, which can be easily incorporated into other programs.

~ Christopher

Yes, any number of wireless serial interfaces would work. There are a number of 802.11 based wireless serial servers that would function very well with this technique.

Cheers.
Francis Govers

Can you give examples of some serial wireless interfaces? I would like to control the vex (using DDT like you said) but wirelessly. Is 802.11 the only option or is there a Serial-to-RF adapter out there that can send data out at 75MHz?

Thanks,
Mannie

I am currently evaluating the XBEE PRO Zigbee WiFi Wireless UART for communication on my Hero 2007 robot, between the sensor controller (BioStamp III) mounted on the rotating sensor platform and the laptop located inside the robot’s main body. These XBEE wireless modules provide wireless serial interface connections such as those used by the Vex Controller for up to 30 Meters (line of sight) at 115K Baud.

:eek: Ur the guy who made Hero?
i though that was a pretty nice robot
i cant build much until i get more parts which i asked for christmas

Yes, I designed the Hero 2007 and am still working on it, although it is far from being completed. I too am missing parts and have started to make my own from scrap metal and plastic, using the original Vex and Erector Set parts as templates. Have you seen my new Gilbert III Robot? It is closer to being completed.

Gilbert III can currently carry the weight of a laptop using only two Vex motors with gearboxes, and is remotely controlled by me using the Vex RC. I am currently upgrading the robot to include two more Vex motors with gearboxes for 4WD tank drive operation so that it can move across the lawn easier, and also upgrading the main controller to use my Biostamp III board (Microchip dsPIC30F6014) with a Parallax Serial Servo Controller for semi-autonomous operation. When operating the robot in semi-autonomous mode, the Biostamp III will take over for the Vex Controller by sending the Parallax Controller servo commands. You can see Gilbert III using the following link:

https://vexforum.com/gallery/showimage.php?i=169&catid=member&imageuser=392

i’ve seen a those stamp projects in radioshack :slight_smile:
i already have tried the electronics kit which has good tests:)
but never tried the stamp programs:(
is it fun programming those stamps or even the the vex with easy C:confused:
cause i asked for the programming kit for christmas
:cool: oh and good idea using erector parts and plastic because i have some and i have a drill so i think it will be easier to build stuff now that u gave me a good tip

Remember safety when using power tools. Wear your Vex goggles to protect your eyes and work gloves to protect your hands. Use proper tools (clamps etc.) and procedures to secure the metal or plastic parts. Also wear a mask if drilling plastics.

I have gloves a plain drill and goggles and no clamp so i need to be extra careful

Hi, I’m kind of new to VB and this is exactly what I need so could you help me out with getting it to work because it won’t compile. Here is my code:
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim val As Integer
    val = TextBox1.Text
    MotorControl(1, Val)

End Sub

Private Sub Button2_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Enter


End Sub

Sub MotorControl(ByVal mtr As Integer, ByVal val As Integer)
    Dim crlf As String = ControlChars.CrLf
    mtr = mtr - 1 '0 - 7 for motors
    Dim myBuff(9) As Byte
    Dim offset As Integer
    Dim count As Integer
    offset = 0
    count = 8
    myBuff(0) = &HAA
    myBuff(1) = &H55
    myBuff(2) = mtr
    myBuff(3) = 0
    myBuff(4) = val
    myBuff(5) = 21
    myBuff(6) = 0
    myBuff(7) = 0
    myBuff(8) = 0
    Try
        SerialPort1.Write(myBuff, offset, count)
    Catch ex As Exception
        Console.WriteLine("An Error occured motor control: '{0}'", ex)
    End Try
End Sub

End Class

it compiles but doesn’t do anything when i type into “textbox1” and hit “button1”

I created the Palm controlled robot to get extra computing power and memory space in a small carry-along package. Have you looked at [it?

Steve](“http://www.hobbyvex.org/PalmVex/index.htm”)

Hi Steve,

Your Palm controlled robot looks great! I happen to own an IPAQ Pocket PC, do you have any plans to support Windows CE versions of your application?

Regards,
Daniel

Where did you get the free VB? I had the link once but lost it :frowning: