Help needed with commands sent via serial

I would like to build a 4wd rover that will be remotely controlled using LabView on a pc. Eventually I would like to add an Xbee 900mhz link and hopefully video to the project as well. I am new to microcontrollers and have the Atom Pro 28 and their usb lab board. I have a basic understanding of electronics, I’m just lacking in the programming area.

How do I get a concatenated string of hex sent via serial to command HPWM and other outputs? The string is kinda long (PC80827F7F80FFFF000100320000X) the LabView code was originally written by another person for an underwater ROV. I am in the process of paring down the strings and removing a lot of unneeded items without wrecking the VI.

If someone could point me in the right direction, I would greatly appreciate it. If someone could just show me how to activate a simple output with Labview, it would be a step in the right direction

um since your question seems to revolve around how to program something in labview wouldn’t it make more sense to post this type of question on a labview support forum and tell them your application is controlling an rov than posting it on a robotics forum asking about how to write labview code?

perhaps an analogy would be walking into an alanon group session looking for help with a compulsive gambling problem… just a thought.
:unamused:

also maybe I misunderstood the point of the question… or which end of the system you were asking for help with. I’m not really sure. :open_mouth:

Sorry, I think I drank too much coffee when I posted the question.

I understand the LabView end well enough to get it to send whatever string needed. As far as the Atom Pro goes…I’m clueless. If I set labview to send a hex string indicating a button pressed or joystick position (usually something like -100 to 100 decimal then converted to hex). How I get that hex value to to point to a command in atom code. I imagine would there would be a table or array of some sorts. I really don’t understand variable, constant and such things yet.

Is there a book out there that can enlighten me so I won’t irritate everyone here with my wacky coffee fueled questions?

Um…if I understand your question right, you want to do something like this?

' the variable "value" contains the data sent through the serial port

if value = $94 then '148 in hex
' Put your instructions here
endif

I think that should be about right.

Hopefully I didn’t come off as too irritated, my comment was more of a “think about it” approach.
Anyway, there is a manual for the AtomPro, which documents the basic functions mostly but isn’t really much of a teaching tool for programming the things. One thing that suffers is the lack of a handshake between the BAP and a host when using RS-232. If you are going wireless and have a TTL output from your module anyway you might be best served to use the hardware serial functions in the BAP. These require you use P14 and P15 as your serial lines. ALL of the other serial functions are bit-banged and thus suffer from the need to sit there and actually wait for a serial command, requiring some sort of handshake or risking the loss of serial data.
Once you have the hserial setup and functioning (a nice part about hserial using a separate set of dedicated pins is you can still use the built in rs-232 for programming and debugging while testing the hardware serial operation) you have to figure out if you plan on using single byte commands, strings or packets and write an appropriate handler.
Then, as wowy7 suggests, it eventually boils down to nested if-then-else statements or using the on…goto statements to vector operation based on some command value.

Not sure of your question, but if you need an example of code on the Atom, I suggest you generate a program using PowerPod. Make it for COM, and you’ll see how to receive a packet and decode it. You can then adapt it to take your packet (string).

See this thread:

lynxmotion.net/viewtopic.php?t=3445

Alan KM6VV

EddieB, you didn’t seem irritated to me, I guess im just worried about bothering people. I respect everyones knowledge and am grateful for the help, I wouldn’t be able to get far without knowledgeable people like you guys.

The syntax manual really hasn’t given much help. I guess this is due to my lack of programming knowledge.

I will try the examples above and post what I come up with. I will try something simple with hyper terminal to see if I can make something work. I just ordered a ttl level shifter from sparkfun to allow me to use hserial instead serin.

Thanks tons and if you know of any readings to help me understand better, please let me know

Thanks EddieB, wowy and km6vv. I got it to work!!! I’m so pumped!!!

I set it to make p8 low when the char a is recieved, then blink when timeout is reached.

now i just have to get it to take my strings.

[code]ENABLEHSERIAL
sethserial h9600,h8databits,hnoparity,h1stopbits

main
in_data var long

   hserin 500, expd, [in_data]   

   if in_data = "a" then    
       low p8              
   else
       high p8            
  endif
  serout s_out, N9600, "got data ", in_data]   
   goto main

expd
high p8
pause 100
low p8
pause 100
high p8
pause 100
low p8
pause 100
goto main[/code]

When I start using a longer string, how should set the variable? word, sword? I’m still a little confused on these things.

Congrats on getting this to work!!!

I am not sure from your posts if the strings that you are receiving are of a fixed format or not. If it is fixed, it might be easy to read all of these values in with input modifiers.

for example if the first 2 bytes are characters, followed by a four 2 hex byte numbers you could do something like:

something like:

    ...
    bIn1 var byte
    bIn2 var byte
    hIn1 var word
    hIn2 var word
    hIn3 var word
    hIn4 var word
...
    hserin 500, expd, [bIn1, bIn2, hex2 hIn1\2,hex2 hIn2\2,hex2 hIn3\2,hex2 hIn4\2]
...

Note without input modifiers I believe that hserin as well as serin and debug will only assign one byte of input to each variable, regardless of the size of the variable.

If your input does not have a fully fixed format, I would probably read the whole thing into a byte array using the string(STR) input modifier. Something like:

bMystr var byte(80)
...
hserin 500, expd, [str bMystr\80\13]

Then you will have to parse the strings and do the conversions…

Note: my example code may not be fully correct, but hopefully it might help give you some ideas…

Kurt

Thanks for all the help guys, I wanted to thank you guys earlier but I have been swamped with school and work.

I haven’t been able to work on programming much, but this is what i have come up with

ENABLEHSERIAL
   sethserial h9600,h8databits,hnoparity,h1stopbits

main



       id var byte  ; P char (of PC), identifing start of string and source
             
       lx var word  ; left stick x axis
       ly var word  ; left stick y axis
       rz var word  ; Right stick x axis
       rr var word  ; Right z rotation axis     
       btn var word ; 4 dig hex combo indicating button pressed
       
      
      
        
	
	
	        
       hserin 500, tmout, [id, hex2 lx\2, hex2 ly\2, hex2 rz\2, hex2 rr\2, hex4 btn\4]    
	if BTN = "$0000" then   
		low p8             
	       else
		high p8           
	endif
		   
	goto main 
      
tmout
       high p8               
       pause 100
       low p8
       pause 100
       high p8                 
       pause 100
       low p8
       pause 100
       goto main

Its just a test to see if I can get the BAP to see the string, I get the following error: (LINE 21) : [TOKEN ] : Expected , or ]

Line 21 is the HSERIN line. I have played with it for 3 days and cant figure out my mistake.

This looks like an issue for AcidTech (Nathan)

It appears like the #min part of the modifiers is not being accepted by the HSERIN command. Even the examples in the manual do not compile.

Kurt

Thanks, I was losing esteem rapidly. I’m using IDE v8.0.1.7, I will give the beta a shot. Do you know where I can get older versions of the IDE?

UPDATE: just tried v8.0.1.8 with the same results

I got this to compile…and it works. Don’t ask me how. I guess the sun shines on every dog’s ass once in awhile.


main        
       
; STRING
   
id var byte  ; P char (of PC), identifying start of string and source       
lx var word  ; left stick x axis
ly var word  ; left stick y axis
rz var word  ; Right stick x axis
rr var word  ; Right z rotation axis     
btn var word ; 4 dig hex combo for button
	
	        
       hserin 500, tmout, [id, hex2 lx, hex2 ly, hex2 rz, hex2 rr, hex4 btn]    
           
	if BTN =  $0000  THEN
	
	sound P9,[70\500]
	pause 100
	sound P9,[70\700]
	pause 100	
	sound P9,[70\900]
	pause 100             
	       else
		high p8           
	
	endif
		   
	goto main 
      
tmout

       high p8               
       pause 100
       low p8
       pause 100
       high p8                 
       pause 100
       low p8
       pause 100
       goto main

I get the sound when I send hex 0000 with docklight.
gonna try labview next

I was wrong, it doesn’t work properly. I realized when it was working I was mistakenly sending characters in ASCII.

Shoul you be using HSERIN? whats wrong with just SERIN?

That’s what I have been told so far. If I recall correctly, serin causes the program to stop until a command is received. I guess it would be better to allow it to run and execute without waiting for a command.

The big difference between hserin and serin is the hardware support. That is with HSERIN your pc program can send its output when it wants and the hardware on the H8 processor will receive the input and queue it up such that Atom Pro software can then read it when it wants. Where as serin is all software, so if your Atom Pro is not sitting in a SERIN wainting for the input from the PC and the PC sends the data, the data is lost.

Also as a side note, with the hardware serial port the hardware takes care of the bit timings so it is not effected by other stuff going on. Where as if for example your program uses interrupts, you may find that the serin and serout do not work properly at higher speeds sometimes as low as 9600 baud.

Kurt