Hello again, Cemetech!
I wasn't here for ages now due to quite a hard time in life...

Well, here I am back. In a recent talk in SAX I told KermPhD about my new Raspberry Pi and he suggested making a topic for my possible projects.

First some pictures (sorry for worse-than-potato quality, pictures taken with a phone cam and not much tweaking):

Overall view of the RPI itself, the already attached capacitive touchscreen, mini-keyboard (turned out to be not as unconvenient as feared) and a basic electronics kit:


Closeup of Raspberry Pi 3:


Closeup of the 7'' capacitive touchscreen:


Mini-keyboard with integrated mouse:


And of course the contents of the electronics kit:


The electronics kit is quite interesting for playing around with, it is made with plugs and does not require soldering. There is some quite basic stuff, like resistors, LEDs and such stuff, but there are 7-segment displays, a LED matrix and other more advanced things. It also includes a basic manual, but it only explains what the components do and some Pin basics. It is assumed you know either C or Python, which is both false for me.

On the Raspberry Pi itself:
I installed Raspbian on it and managed to configure it for the touchscreen and the keyboard (the latter one was tricky!). I don't have any expirience with it yet, I wasn't even able to download and install programs on it via OS-built in "Appstore".


So, I will post questions and results here, and my first questions are:
1) I am quite certain I will have to learn C++, one way or another. So do you think learning C is a better idea than Python? Any advice?
2) What good resources and manuals are there for starters? I've seen a ton of YouTube videos and such stuff, but most of it left me with no clue. Maybe because I can't even program it.
Wow, awesome setup there, Nik! I'm particularly enamored of that keyboard.

Nik wrote:
The electronics kit is quite interesting for playing around with, it is made with plugs and does not require soldering. There is some quite basic stuff, like resistors, LEDs and such stuff, but there are 7-segment displays, a LED matrix and other more advanced things. It also includes a basic manual, but it only explains what the components do and some Pin basics. It is assumed you know either C or Python, which is both false for me.
Does it provide some sample programs you can run so you can simultaneously learn the electronics parts (before you master the programming) and also explore the programming?

Quote:
On the Raspberry Pi itself:
I installed Raspbian on it and managed to configure it for the touchscreen and the keyboard (the latter one was tricky!). I don't have any expirience with it yet, I wasn't even able to download and install programs on it via OS-built in "Appstore".
Assuming you mean Synaptic (the package manager GUI), you will indeed want to install programs via that, or just pop open a console and use apt-get, the command-line version of what Synaptic does.

Quote:
So, I will post questions and results here, and my first questions are:
1) I am quite certain I will have to learn C++, one way or another. So do you think learning C is a better idea than Python? Any advice?
2) What good resources and manuals are there for starters? I've seen a ton of YouTube videos and such stuff, but most of it left me with no clue. Maybe because I can't even program it.
1) Since you have experience in TI-BASIC, I'd personally recommend doing a little bit of Python first, then starting to also learn C, perhaps attacking the two simultaneously. The barrier to entry in Python is going to be slightly lower (ie, easier to get started), but you don't want to ignore C/C++ entirely.
2) One of the nice things about Python is that you can run it just about anywhere without having to figure out complex compilers and libraries (although that's increasingly true for C/C++ as well, I suppose. And don't get me started on Java). Thus, you can start writing and running programs on your main computer to learn Python if you're concerned about doing all your learning on the Pi. Assuming you remember enough about TI-BASIC, one interesting approach would be to just read a few Python programs, then start trying to combine the syntax you see for Python with the structural knowledge you have from TI-BASIC. If it's going to be only your second or third programming language, though, a more structured approach would probably yield better best-practices. How about starting with Python's official tutorial?
KermMartian wrote:
Wow, awesome setup there, Nik! I'm particularly enamored of that keyboard.
Haha, thanks. That keyboard indeed looks cute! I purchased it on Amazon (Sorry for the German. I couldn't switch it to English...).

KermMartian wrote:
Does it provide some sample programs you can run so you can simultaneously learn the electronics parts (before you master the programming) and also explore the programming?
There is one single example for a blinking LED. And an instruction on how to compile and run it. But nothing more, unfortunately.

KermMartian wrote:
1) Since you have experience in TI-BASIC, I'd personally recommend doing a little bit of Python first, then starting to also learn C, perhaps attacking the two simultaneously. The barrier to entry in Python is going to be slightly lower (ie, easier to get started), but you don't want to ignore C/C++ entirely.
Ah, thanks a lot! So the plan is: First some Python basics, then some C.

KermMartian wrote:
2) [...] Assuming you remember enough about TI-BASIC, one interesting approach would be to just read a few Python programs, then start trying to combine the syntax you see for Python with the structural knowledge you have from TI-BASIC. If it's going to be only your second or third programming language, though, a more structured approach would probably yield better best-practices. How about starting with Python's official tutorial?
These are good tips. Thanks a lot! So let me start with some PC programs then, and go on with Raspberry Pi projects afterwards.
Okay, so, recently I asked Kerm to give me a simple task to do in Python, and he suggested creating a guessing program.

Here's what I made:
Code:
import random
while True:
   number = random.randrange(1,100)
   tries  = 0
   guess  = 0
   print("Guess my number!")
   while number != guess:
      tries += 1
      guess = eval(input("Your guess: "))
      if guess < number:
         print("More!")
      if guess > number:
         print("Less!")
   print("Correct! You guessed in " + str(tries) + " tries! Now do it again and better.")


Edit: Corrected "PHP" to "Python", thanks CHill!
I am a little tired now, sorry...
Nik wrote:
Okay, so, recently I asked Kerm to give me a simple task to do in PHP, and he suggested creating a guessing program.

Here's what I made:
Code:
import random
while True:
   number = random.randrange(1,100)
   tries  = 0
   guess  = 0
   print("Guess my number!")
   while number != guess:
      tries += 1
      guess = eval(input("Your guess: "))
      if guess < number:
         print("More!")
      if guess > number:
         print("Less!")
   print("Correct! You guessed in " + str(tries) + " tries! Now do it again and better.")

I dont have a lot of experience with PHP, but that looks a whole lot like Python...
EDIT: I think you meant python, not PHP.
Nice! The Python program works great for me. Also, that Pi and electronics stuff look pretty fun. If I didn't already have enough projects that I need to finish first… Wink
Nik wrote:
Okay, so, recently I asked Kerm to give me a simple task to do in Python, and he suggested creating a guessing program.

Here's what I made:[elided]
Nice work; that's more or less exactly how I'd recommend you make that! What are you going to try next with Python? How about a quadratic formula solver? Wink
Thanks for the support!
KermMartian wrote:
How about a quadratic formula solver? Wink
Okay, let me try! For an additional challenge, I will ask for the formula in ax^2 + bx + c = 0 form and parse it, rather than directly prompt abc! Smile
Nice, that's a great idea. For bonus points, try to find at least the three ways to do that parsing that I can think of off the top of my head.
Yuck, I would not want to use that tiny keyboard.
KermMartian wrote:
For bonus points, try to find at least the three ways to do that parsing that I can think of off the top of my head.
Thanks for the challenge, but, honestly, I got stuck. Do you mean three different commands? Or three different approaches to the problem? Confused
oldmud0 wrote:
Yuck, I would not want to use that tiny keyboard.
As I said above, it turned out to be not that inconvenient...
I'm suggesting three different approaches to the problem. I'd be happy to help you with some hints, though, tailored to what you've tried so far. About the keyboard, "not that inconvenient", or "not that convenient"?
KermMartian wrote:
I'm suggesting three different approaches to the problem. I'd be happy to help you with some hints, though, tailored to what you've tried so far.
The only way I could think off would be looking for the "+" and "-" signs, break the string at them, remove the "x²" and "x", and fill up any missing entries with 0. But I was puzzled, as that is really the only way I can think off.
For the program itself: I made the solver, but haven't started the parser - for the reason above.

And thanks for your efforts! Smile

KermMartian wrote:
About the keyboard, "not that inconvenient", or "not that convenient"?
Not that inconvenient. You might expect worse from such a small thingy.
Got it, thanks for clarifying about a keyboard. I'm increasingly thinking I need my own one of those. Smile About the splitting: for two more methods, take a look at using regular expressions, and also look at the string.split() function.
So, after some hard time with learning Regular Expressions, here's my new code. This is just a "test version", as I am not yet far enough to be able to extract the data from the search command - it gives me an object, but, obvoiusly, I cannot just store this into an integer variable.

Code:
import math
import re

print("Quadratic formula solver")

while True:
   print("")
   print("Please enter the formula")
   formula = input()
   print(re.search("[+-]",formula))     // this line returns "<_sre.SRE_Match object; span=(4, 5), match='+'>"
   
   a = float(input("a  = "))     // these are the leftovers from when I directly prompted a, b and c
   b = float(input("b  = "))
   c = float(input("c  = "))
   
   root = b**2-4*a*c     // actual code starts here
   
   if root < 0:
      print("This formula has no solution")
   
   if root == 0:
      print("x = " + str(b**2 / (2*a)))
   
   if root > 0:
      print("x1 = " + str((b**2 + math.sqrt(root)) / (2*a)))
      print("x2 = " + str((b**2 - math.sqrt(root)) / (2*a)))

I tried storing it to a variable and trying var[0], but this didn't work too. So, my question is: How do I make use of this data?

Edit: Comments
Edit2: Found a solution - re.search() returns an object, containing a span where the substring was detected. re.search(...).start() returns the first number, re.search(...).end() returns the second number.
I was able to finish the program now:

Code:
import math
import re

print("Quadratic formula solver")

while True:
   print("")
   print("Please enter the formula in 0=ax^2+bx+c form")
   formula = input("0=")
   
   search = re.search("[+-]",formula)
   if search:
      breakpoint1 = search.start()
      search = re.search("[+-]",formula[breakpoint1 + 1:])
      if search:
         breakpoint2 = search.start() + breakpoint1 + 1
   
   a = int(formula[:breakpoint1 - 3])
   b = int(formula[breakpoint1 + 1:breakpoint2 - 1])
   c = int(formula[breakpoint2 + 1:])
   
   root = b**2-4*a*c
   
   if root < 0:
      print("This formula has no solution")
   
   if root == 0:
      print("x = " + str(b**2 / (2*a)))
   
   if root > 0:
      print("x1 = " + str((b**2 + math.sqrt(root)) / (2*a)))
      print("x2 = " + str((b**2 - math.sqrt(root)) / (2*a)))


Based on this, I will try to make the formula's components optional - so you can leave one or two off. I created my code with this in mind, so it shouldn't be hard.

Edit: OK, the formula can be in any order, and parts of it may be missing. Just no syntax checking.

Code:
import math
import re

print("Quadratic formula solver")

while True:
   print("")
   print("")
   print("Please enter the formula")
   formula = input("0  = ")
   
   breakpoint2 = len(formula)
   sign1 = "+1"
   sign2 = "+1"
   sign3 = "+1"
   a = 0
   b = 0
   c = 0
   
   search = re.search("[+-]",formula)
   if search.start() == 0:
      sign1 = formula[:0] + search.group(0) + "1"
      formula = formula[1:]
      search = re.search("[+-]",formula)
   else:
      sign1 = "+1"
   
   if search:
      breakpoint1 = search.start()
      sign2 = search.group(0) + "1"
      search = re.search("[+-]",formula[breakpoint1 + 1:])
      
      if search:
         sign3 = search.group(0) + "1"
         breakpoint2 = search.start() + breakpoint1 + 1
   
   var = formula[:breakpoint1]
   if "x^2" in var:
      a = int(var[:len(var) - 3]) * int(sign1)
   elif "x" in var:
      b = int(var[:len(var) - 1]) * int(sign1)
   elif len(var) > 0:
      c = int(var) * int(sign1)
   
   var = formula[breakpoint1 + 1:breakpoint2]
   if "x^2" in var:
      a = int(var[:len(var) - 3]) * int(sign2)
   elif "x" in var:
      b = int(var[:len(var) - 1]) * int(sign2)
   elif len(var) > 0:
      c = int(var) * int(sign2)
   
   var = formula[breakpoint2 + 1:]
   if "x^2" in var:
      a = int(var[:len(var) - 3]) * int(sign3)
   elif "x" in var:
      b = int(var[:len(var) - 1]) * int(sign3)
   elif len(var) > 0:
      c = int(var) * int(sign3)
   
   print("")
   print("a  = " + str(a))
   print("b  = " + str(b))
   print("c  = " + str(c))
   print("")
   
   root = b**2-4*a*c
   
   if root < 0:
      print("This formula has no solution")
   
   if root == 0:
      print("x  = " + str(b**2 / (2*a)))
   
   if root > 0:
      print("x1 = " + str((b**2 + math.sqrt(root)) / (2*a)))
      print("x2 = " + str((b**2 - math.sqrt(root)) / (2*a)))
As I already mentioned on SAX, I got the Raspberry Pi to blink the LED, and I also figured out that I was stupid.
In the booklet which came with the electronics kit, there is indeed only one program, but also a note, "For more information visit blah blah". I just ignored it until today, which turned out to be a mistake, as I found a Github link there, which allowed me to clone all the programs to the circuits right onto my RPi.
So, besides making the LED blink, I made it be controllable by a button, some more LED circuits and controlling an RGB LED today.
Then, for now, I made a break, and tomorrow I will continue. I decided not to look at what exercises will be next yet, so I will have a surprise. Smile

A side question: Should I post pictures/code/whatever on that? Or rather only my questions?

And also, thanks to Kerm who takes his time for me and helps me to learn all that stuff! Smile

EDIT: For my first project on the RPi, I think I will combine the lesson about PWM and the RGB LED and try to make the RGB LED gradually change colors. But that's work for tomorrow.
Yes, please add pics and code and everything else. I have a RPi myself, so I'm interested with this.
Nik wrote:
As I already mentioned on SAX, I got the Raspberry Pi to blink the LED, and I also figured out that I was stupid.
In the booklet which came with the electronics kit, there is indeed only one program, but also a note, "For more information visit blah blah". I just ignored it until today, which turned out to be a mistake, as I found a Github link there, which allowed me to clone all the programs to the circuits right onto my RPi.
So, besides making the LED blink, I made it be controllable by a button, some more LED circuits and controlling an RGB LED today.
Then, for now, I made a break, and tomorrow I will continue. I decided not to look at what exercises will be next yet, so I will have a surprise. Smile
That sounds like a good plan.

Quote:
A side question: Should I post pictures/code/whatever on that? Or rather only my questions?
If it's new stuff (ie, not in your kit's tutorials), you should absolutely post pictures and code for other people to learn from.

Quote:
And also, thanks to Kerm who takes his time for me and helps me to learn all that stuff! Smile
It's entirely my pleasure; I love when other people have fun learning.

Quote:
EDIT: For my first project on the RPi, I think I will combine the lesson about PWM and the RGB LED and try to make the RGB LED gradually change colors. But that's work for tomorrow.
Good luck! Are you thinking about how that's going to work?
Quote:
EDIT: For my first project on the RPi, I think I will combine the lesson about PWM and the RGB LED and try to make the RGB LED gradually change colors. But that's work for tomorrow.
Good luck! Are you thinking about how that's going to work?[/quote]
I thought about it a bit...
I would definitely need a PWM function, which I could feed some numbers easily. Since I even have one given and explained already, though, that is not a problem.
The real challenge is making PWMs with different tacts working together. I cannot use simple delays. I would either have to calculate delays so that the function toggles all three LEDs in a cycle, which could too be tricky, or I would have to check against the system clock and see when which LED has to be toggled.
I guess the first one is more elegant, so I will try to do it first. But the second one should be easier, as a backup plan.

EDIT: I am working on it right now, and now, that I am making my own stuff and not following a tutorial I have a question. The pin layout on the RPI includes some ground pins, some 5v pins and some IO pins - but how is the layout done? It makes no sense to me.
Plus, the pins are named, like in the image below. How are they even numbered, and why do some have different numbers at once?
(The programs I have use the numbers that are grey, and all worked so far, but the layout is still weird. And does that mean I only have six GPIO pins?)

  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement