New user, overwhelmed, where to start!?
There are tons of examples, so many different ways to do things, but, as far as I can tell, no clear starting point for a new user. I have the P2 Eval board along with the Add-on boards. I am trying to learn Sping2/PASM.
Simple question: How to read a pushbutton? What to expect the state of the pushbutton to be?
The best question of all though, how would I find this out on my own? I am reading through the Parallax Propeller 2 Spin2 Language Documentation and I am having difficulty finding pertinent information. Browsing through the forums hasn't yielded any clear starting point. There is a lot of jargon, acronyms, and verbiage that seem to answer questions but are foreign to a beginner.
Thank you for your assistance. I am really looking forward to getting all of the boards attached and working on my Eval board at some point!
For my pushbutton scenario: Assume using "Control" board and the P2 Eval board. Assume "Control" board is placed on the P0 through P7 pins on the Eval board with the GND pins lined up properly. I have the four leds blinking just fine using this simple code:
PUB main () repeat PINHIGH(0 ADDPINS 3) waitms(1000) PINLOW(0 ADDPINS 3) waitms(500)
Comments
I wrote an object for that control board. The short answer is pinread() to read the state of a pin, or a group of pins. The attached demo should get you started.
Other simple examples:
https://www.parallax.com/propeller-2/quick-bytes/
@JonnyMac Thank you for the example code. This includes a lot of information that will help with serial and buttons! I noticed many of the demos included with the Spin2 download of the Prop tool have top objects included but no way to see the child object. Your example code has the top object and all the child objects as well. For me, this is incredibly helpful!
@whicker Thank you for sharing the quick-bytes link. That is very helpful if the quick bytes has something very specific, otherwise, it is very overwhelming for a new user. In my case, I used the quick bytes to get started with the LED Matrix and was successful.
Sounds like you're using the four button add-on board from the Accessory Set - https://www.parallax.com/product/p2-es-eval-board-accessory-set/
The old Prop1 method of reading the inbuilt INA variable still works. But the alternative new way is via PINREAD() method.
So this code echoes the four button switches to their respective LEDs. Of note is the add-on board is lacking pull-down resistors for the buttons. Therefore to prevent the inputs from staying high all the time I've added config for active pull-down using weak (15k) outputs on the input pins.
Makes a good example of showing how I/O pins, even on the Prop1, are always inputs. Even while they're ordinary outputs, they're still readable as inputs. You just see the level of the output then.
Another quirk with that add-on board is the pin order for the lower two buttons and LEDs is swapped.
@evanh and @JonnyMac , apparently pinw is not the same as wrpin. Thank you for the help! I have thoroughly pressed my palm against my forehead today for not catching this before now. The code turned out quite simple:
However, I still don't fully understand the meaning of all the Pin methods in the Parallax Spin2 Documentation. The details are a little sparse and the short examples included in the document are few.
No, it's not. pinw is a short for pinwrite which allows you to write the digital level of one or more pins (it also sets the DIR bit[s] to 1 for output mode). wrpin is used to set special pin configuration bits (e.g., for enabling pull-ups or pull-downs or setting a smart pin mode). What can be confusing at first is how to deal with pull-ups and pull-downs. Keep in mind that even when a pin is in regular output mode (not a smart pin), the input register can see what's going on. To add a pull-down to a pin, we do this:
The wrpin() line is telling the P2 to insert a 15K resistor between the pin an the FET that switches that pin to ground when it's an output and low. The second line engages that FET which causes the pin to go low through the 15K resistor. Yes, we can still read the pin as an input because the input register is available when the pin is in a tri-state mode (input or output-high or output-low).
If you come from the Arduino world, the two lines above are similar to the pinmode() function -- except that the P2 has pull-ups and pull-downs, and different levels for each (i.e., it's more flexible).
Other pin commands for tri-state operation
The idea of a pingroup can be confusing as well. What this allows you to do is specify a contiguous group of pins (that shouldn't cross the pin 31/pin 32 boundary). If you wanted to treat P0..P3 as a group, you could define that group like this:
You could do the same thing manually like this:
...where 0 is the base pin and 3 is the number of additional pins in the group.
Smart pins are another topic -- you might want to get very comfortable with controlling pins via the tri-state modes before tackling the smart pins (ADCs, DACs, PWM, UARTs, SPI, etc.)
In the early days of the P2 I wrote an article for Nuts & Volts magazine. It may help you.
-- https://www.nutsvolts.com/magazine/article/an-introduction-to-the-parallax-propeller-2
@JonnyMac this was an excellent explanation, thank you! I understand much better now.
TL;DR Suggestion - a forum post dedicated to explaining to newcomers how they can navigate the long form videos available on the Parallax YouTube channel.
@JonnyMac I have been watching some of the videos, especially this one "Spin 2 Beginners Series Part 1: RBG LEDs with JonnyMac". My initial thoughts when searching through the videos on the Parallax YouTube channel was, "Three hours!", "Two hours!", etc...until I noticed there are time tags in the comments. I also found the link in the description of the video to the forum post that includes your documents mentioned in the video. It might be helpful for newcomers to have a forum post explaining this info. If this already exists, I must have over looked it. Thanks for all your help, the videos go to great lengths to assist in understanding the P2 ins and outs along with explaining the coding portion and has been very informative.