I/O Pin as Serial
G33k499
Posts: 1
I know for basic stamp, I can use the·'serout' and 'serin' commands to·listen for or send data.· Is this possible with the Propeller Chip and if so, what is the syntax?· I see the Propeller being a more cost effective solution for my projects.· Also does anyone have any suggestions when it would be best to use Basic Stamp over Propeller and vice versa?
·
Thanks,
Adam
·
Thanks,
Adam
Comments
My standard comment about the Propeller vs. Stamp is that with the Propeller, it's harder to do the easy things (e.g., blink an LED), but MUCH easier to do the hard things (e.g., read a mouse position, display things on a screen, etc.).
I bought a Propeller protoboard and then let it sit there largely unused for months before I decided to wade in and figure it out. Now I've got three of them, plus four Propsticks, and a Propeller chip that I just wired up on my own. I suggest you buy a protoboard and a Prop Plug, and work your way through Chapter 3 of the manual. Of course you could read that chapter first to see if you think you're up to it.
As to your syntax question, the idea of object-oriented programming is that you (or others...) write "objects" to handle things like serial communications, I2C, LCD screens, etc. There isn't really a "Serin" or "Serout" command in the Propeller's Spin language, but instead, you find an object in the exchange that does that, then do something that amounts to an "include" statement (yeah, I know, the purists are screaming now) in the declarations in your program to give your program access to the object's methods, and then use them to your heart's content. For example, take a look at this:
The lines
allow my program to use the methods contained in the Debug_LCD object (which someone else wrote, and put up on the object exchange). Later on when I write LCD.gotoxy(0,0), I'm using one of those methods. A typical serial i/o method is this one, in the Full_Duplex_Serial object:
which you use like this:
That last line uses the str method to send that string out through a pin as serial data.
Post Edited (sylvie369) : 12/19/2008 7:40:13 PM GMT
Are objects like subroutines? And if so, do objects have a standard syntax to pass variables to them or can the syntax vary depending on who wrote the object?
I'm looking at the objects and noting they look a bit like Calls in .net, where you pass variables inside brackets. Is this how it is done, and if it is, does one put a comment when one includes an object that describes some of the syntax for that object (so you can remember how to use it).
Also, should one note how much space the object takes up and the resources it uses. I'm thinking one could have a three line program that references three large objects and suddenly there is no space left.
And is it possible to copy and paste the entire referenced object code into the main program? Is this allowed or is the proper protocol to reference it and then look it up externally?
Lots of really dumb questions I'm sure.
I'm mindful of how QB went in the early 1990s where a basic program went from one single linear text file into a program that referenced subs that one could visualise seperately via the interpreter but were not contiguous. I remember at the time it was confusing, then it became very natural, and now, looking back at those programs 15 years later, they are confusing again.
I'd like to put half a page of comments next to that object reference describing how it works. Is that the way to do things?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
· -- Carl, nn5i@arrl.net
- The objects vary in syntax depending on the author, however most come with simple example programs to explain usage, and the objects you find in the object exchange are generally documented within the source code.
- The size of an object is completely dependent on the content of the object. SPIN / assembly code are only ever created once, while variables within an object are created per instance of that object in your code. The Propeller tool can tell you how much code / data are used by a given object. If an object contains functions you don't use, removing them will reduce the size of the object.
- There is nothing wrong with creating modified copies of existing objects to suit your needs, just make sure to differentiate them from the original so you don't go blaming some poor author for bugs you created. [noparse]:)[/noparse]
- There is no reason you can't copy the code from the object directly into your program if the object is simply SPIN functions you need (like Simple_Serial).· If the object contains data as well as code, then it's a little more complicated. Some apps use objects like C++ uses classes, as a way to keep data and related functions together, and allow the creation of more than one object of the same type. In this case, copying the object code into your own would break that. It's also a little different when the object uses assembly code, as the assembly portion has to be started on its own cog, which means you have to HAVE a spare cog.
Jason
Post Edited (JasonDorie) : 12/19/2008 12:55:43 AM GMT
Ok, I searched for BS2 in the objects library and downloaded it.
There are quite a few functions there, including Serin and Serout.
So this object allows one to code in Basic? Or at least use many of the familiar commands. And given the format looks pretty straightforward, it should be possible to add more commands?
Sweet!
Thank you very much
·
Pay it forward, man.
Bingo.
Of course you have some details to pay attention to, like what kinds of parameters a method requires, and whether or not it returns a value (as a function, for us old-school C/PASCAL types). But yup, when you want to do something, go straight to the object exchange and look for an object that covers what you need. Then just read through that object's methods to see which ones you need to use in your own programs. Using a DS1620 temperature chip? Look - Jon Williams put an object for it up there in the Exchange. An LIS302DL three-axis accelerometer? These methods are already available in an object there:
Nunchuck controller?
http://forums.parallax.com/showthread.php?p=751847
Like I said, the hard stuff is much easier with the Propeller (provided of course that someone else has already done the work)
By the way, all of this stuff is right there in Chapter 3 of the Propeller manual.
Post Edited (sylvie369) : 12/19/2008 7:41:48 PM GMT
·