Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : MM2 multiple UI question
Author | Message | ||||
dasyar Regular Member Joined: 13/04/2015 Location: United StatesPosts: 58 |
I still have my MM on a breadboard with an XBee module attached (com2) and com1 hooked to the Raspberry Pi /dev/ttyAMA0 port. With the program below I can turn on/off the LED via an XBee login, but how do I add a com1 login that also responds to the do ... loop UI? Basically I would like to be able too login from an XBee or the RPi and have a UI session, respond to the commands. Is there some way of doing 'INPUT #1 AND INPUT #2,dat$' or maybe a separate loop that checks to see if there are chars waiting in the #1 or #2 buffer, then proceeding to the main loop? Or maybe there is a better way to do this? My next step, add a DHT22 module and be able to data log it to file on the RPi, if that is possible. Thanks ' Test1.bas Open "COM2:9600" As #1 ' -> XBee Pause 2000 Open "COM1:115200" As #2 ' -> /dev/ttyAMA0 (Raspberry Pi) SetPin 15, dout Print #1,"Test1 program" 'Main loop Do Print #1, ">" ' XBee Input #1,dat$ ' XBee If dat$ = "quit" Then Exit If dat$ = "onled" Then onLED If dat$ = "offled" Then offLED ' Print #1,Chr$(10) 'LF ? ' Print #1,Chr$(13) 'CR ? Loop Close #1 Close #2 sub onLED pin(15) = 1 end sub sub offLED pin(15) = 0 end sub |
||||
jman Guru Joined: 12/06/2011 Location: New ZealandPosts: 711 |
Hi You could use the LOC command to check if the buffers had any content from the manual LOC( [#]fnbr ) "For a serial communications port opened as 'fnbr' this function will return the number of bytes received and waiting in the receive buffer to be read. The # is optional" Regards Jman |
||||
dasyar Regular Member Joined: 13/04/2015 Location: United StatesPosts: 58 |
Out of curiosity, there is a line of example code , in the manual: [code] A$ = INPUT$(1, #1) : B$ = INPUT$(1, #1) [/code] What does the ':' in between the two statements do? Also in the manual, the INPUT command explanation does not show what an INPUT with '()' is supposed to accomplish, maybe for the experts it is obvious, for me, it is not. So what is the '1', in the parenthesis doing. |
||||
Chris Roper Senior Member Joined: 19/05/2015 Location: South AfricaPosts: 280 |
The Colon is a command separator, it allows you to have more than one command on a line rather than one line per command. The first 1 is saying to retrieve only a single character from the buffer, the second #1 is the handle of the port being read. So the Line you show retrieves 2 bytes from Handle #1, the first byte is stored in A$ and the second in B$. Hope that helps, Cheers Chris http://caroper.blogspot.com/ |
||||
dasyar Regular Member Joined: 13/04/2015 Location: United StatesPosts: 58 |
[code] print #1, ">" [/code] For the 'print' command, is their some way of controlling CR associated wit it? It seems that this is wreaking havoc on my terminal screen output, I am getting a CR in places where I need better control. Also I noticed that the 'INPUT' command when used with '#', is not showing a '?', in some cases that is a good thing. In the code snippet bellow, I was testing to see if the 'INPUT' command was actually waiting for a keypress, which it is. But I noticed my 'do ... loop' is not working as expected, it is not responding to my inner 'IF' statements. In fact when I do key in a command, I always get the "Nothing yet", with no response to my keyed in command. So it seems that the use of 'LOC' is clearing out the buffer, is that the way 'LOC' was intended to be used? [code] ' Test1.bas Open "COM2:9600" As #1 ' -> XBee Pause 2000 Open "COM1:115200" As #2 ' -> /dev/ttyAMA0 (Raspberry Pi) SetPin 15, dout Print #1, "Test1 program" print #1, ">" 'Main loop Do input #1,dat$ if (loc(#1) > 0) then If dat$ = "quit" Then Exit If dat$ = "onled" Then onLED If dat$ = "offled" Then offLED else print #1, "Nothing yet" endif Loop Close #1 Close #2 sub onLED pin(15) = 1 end sub sub offLED pin(15) = 0 end sub [/code] |
||||
Chris Roper Senior Member Joined: 19/05/2015 Location: South AfricaPosts: 280 |
Terminate the Print Argument with a ; character to suppress <CR/LF) In Your Example: [Code]print #1, ">";[/code] should solve your problem. I will have to come back to the second question when I have time to read the code :) http://caroper.blogspot.com/ |
||||
Chris Roper Senior Member Joined: 19/05/2015 Location: South AfricaPosts: 280 |
Input is waiting for data, when you press enter the data is transferred from the buffer to dat$. So, unless you pressed enter twice, there should be nothing in the buffer and LOC will always return 0. I don't have access to a micromite to test but this should work: [code] 'Main loop Do input #1,dat$ If dat$ = "quit" Then END If dat$ = "onled" Then onLED If dat$ = "offled" Then offLED Loop [/code] Also there is no Exit defined, use END, as above, to exit the program. if you want to use LOC then you could use it in your example like this: [code] 'Main loop Do if (loc(#1) > 0) then dat$ = INPUT$(LOC(1), 1) ' Read all the characters in the input buffer If dat$ = "quit" Then END If dat$ = "onled" Then onLED If dat$ = "offled" Then offLED else print #1, "Nothing yet" endif Loop [/code] Cheers Chris http://caroper.blogspot.com/ |
||||
dasyar Regular Member Joined: 13/04/2015 Location: United StatesPosts: 58 |
Thanks Chris, I am reading the manual, but somehow my interpretation of what I read was not working as expected. The reason I was using 'exit' is because I just wanted to break out of the do...loop, I think when you use the 'end', it actually ends the program. The reason I am using 'loc()', is that I want to check if source #1 or #2 has any thing in the buffer and then do the main loop accordingly. I want the main loop UI to be accessible by #1 or #2, by whichever one is logged in. This is the coding structure that I am trying to get a handle on. I was trying to implement a logical operator OR to check the loc(#1) OR loc(#2), but that did not work, at least not the way I had it coded. |
||||
dasyar Regular Member Joined: 13/04/2015 Location: United StatesPosts: 58 |
OK, I am using "User Manual MMBasic Ver 4.6". In there it states "The old standard of EXIT on its own(exit a do loop) is also supported." I guess my interpretation of that is not correct, in the code below? When I run the program the print stuff following the do loop is not being shown on the terminal screen. When I use 'EXIT DO', the same thing occurs. Not sure what is going on at this point. [code] ' Test1.bas Open "COM2:9600" As #1 ' -> XBee Pause 2000 Open "COM1:115200" As #2 ' -> /dev/ttyAMA0 (Raspberry Pi) SetPin 15, dout Print #1, "Test1 program" print #1, ">"; ' ';' is used to suppress a CR 'Main loop Do INPUT #1, dat$ If dat$ = "quit" Then Exit If dat$ = "onled" Then onLED If dat$ = "offled" Then offLED Print #1,Chr$(13) 'CR ? print #1, ">"; Loop Print #1,Chr$(13) print #1, "Closing PORTS and ending program." Close #1 Close #2 end sub onLED pin(15) = 1 end sub sub offLED pin(15) = 0 end sub [/code] |
||||
BobD Guru Joined: 07/12/2011 Location: AustraliaPosts: 935 |
dasyar It is no longer good enough to tell us only what manual you are using. There are too many versions of hardware and software in use now, many of them Beta versions with extra capabilities. The version of firmware is more important. This can be found from your files if you know which one you last loaded or displaying the variable MM.VER in the running system. Bob |
||||
dasyar Regular Member Joined: 13/04/2015 Location: United StatesPosts: 58 |
MM.VER = 4.06, Hmm, does this mean I have some old chip(s)? Since I am new here, I guess I should ask, how often does the MM.VER change around here. I purchased my chips, probably around five months ago, and what, the MM version is up 4.6? So is there an archive for MMBasic Manuals, and I should really be reading a 4.06 manual instead? Not sure what to do next. |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5913 |
4.06 is V4.6 so you are not too far behind. V4.7 is in beta. There are also Maximites, which have slightly different syntax for some commands, so it can be difficult for others to know for sure what you are using. Jim VK7JH MMedit MMBasic Help |
||||
dasyar Regular Member Joined: 13/04/2015 Location: United StatesPosts: 58 |
CGMICROMITE2 - Micromite MkII Maximite computer on a chip - single DIP microcontroller. This is a 28 pin chip that I have implemented on the breadboard. And I am using TeraTerm as the program to log into the chip via XBee module. To tell the truth, I did not think that such a small little program, which I have shown a couple posts back, would be giving me so much trouble, or at least working as expected. |
||||
Print this page |