-
Re: What is the best way to learn Python?
michaelkellettMar 2, 2015 8:59 AM (in response to peterjcs23)
The Pi is Linux machine so you could use C if you wanted.
You should only need to use Python if you want to use hardware with no C support.
On the other hand Python is quite popular so you might want to learn it anyway.
There is a lot of stuff on the web - trawl about until you find something you like.
Bookwise, I started with Beginning Python, Magnus Lie Hetland - published in 2005 - I don't much recommend it (not because there is anything wrong with it but because it's 10 years old now.)
MK
-
Re: What is the best way to learn Python?
peterjcs23 Mar 3, 2015 3:08 AM (in response to michaelkellett)Hi Michael, does the Raspberry Pi come with a C compiler, I thought Python was supplied? I see Python as a (personal) barrier to getting going with RsPi. so I'm going to set about learning it...Peter
-
Re: What is the best way to learn Python?
michaelkellettMar 3, 2015 3:23 AM (in response to peterjcs23)
The RPI is (currently) a Linux thingy so GCC is available (see Roy's reply above) so you can code in pretty much anything on it. I'm no RPi expert (I haven't ever used one and the only thing that would tempt me (a little) will be if Microsoft implement a decent go at Windows on it.)
MK
-
Re: What is the best way to learn Python?
peterjcs23 Mar 3, 2015 3:37 AM (in response to michaelkellett)It may not be Microsoft Word but this keeps popping up on twitter...
...says...
LibreOffice is a free office suite that provides the same functionality as Microsoft Office. A standard install of LibreOffice provides you with applications such as
- Writer - Word Processor
- Calc - Spreadsheets
- Base - Database
- Impress - Presentation
- Draw - Illustration
- Math - Equations
-
-
Re: What is the best way to learn Python?
peteroakesMar 3, 2015 7:57 AM (in response to peterjcs23)
It comes with or it is easy to load with apt-get a C compiler, also geany editor etc
-
Re: What is the best way to learn Python?
peterjcs23 Mar 4, 2015 5:21 AM (in response to peteroakes)Using C is tempting as I used it before but I see a lot of python code on this community blog - if I start using RaspPi I should learn python.
-
-
-
Re: What is the best way to learn Python?
peterjcs23 Mar 4, 2015 3:39 AM (in response to michaelkellett)Hi Michael, seems like you need to use C to access the SPI and interrupts...
thanks, Peter
-
-
Re: What is the best way to learn Python?
ProblemchildMar 2, 2015 9:36 AM (in response to peterjcs23)
Has Mike says you can use "C" on the RPI just fine the Compiler is supplied on the latest Rasbian images with out needing to install it so you an just continue with this.
Yes most released software on the RPI is in Python generally because it's simpler than C if you still want to learn it I would suggest starting a project that requires it and this should push you to learn.
Alternatively how about taking a computing module on EdX that does Python like the MIT one... It's free even!
(or 50$ for an exam if you want a certificate)
-
Re: What is the best way to learn Python?
peterjcs23 Mar 4, 2015 3:46 AM (in response to Problemchild)Hi John, thanks for the tip to use Edx, it looks quite interesting as I have never done a computer science course. https://www.edx.org/course/introduction-computer-science-mitx-6-00-1x-0#.VPbTL-GCmy0
I learned Fortran (IBM punch cards), Bit-Slice machine code and Intel8080 assembler too long ago. Peter
-
-
Re: What is the best way to learn Python?
royleith Mar 2, 2015 10:06 AM (in response to peterjcs23)1 of 1 people found this helpfulI suggest 'Learning Python' by Mark Lutz and David Ascher and published by O'Reilly as it often explains the Python way of dealing with c programming tasks. There are lots of examples and exercises (with solutions). Once you get to grips with the Python objects, the very best resource is the wonderful,
In fact, browse the site, first, and see if the downloads and on-line references, tutorials and other documentation are enough to get you going. Once you get functions, strings, tuples, lists, classes, dictionaries and the like, the documentation should make lots of sense.
Imports are to Python as includes are to c. Python imports are modules which add functionality, but most of the ones you want are included by default when Python is installed (by default in the Pi). The Pi also has the IDLE IDE installed for both the current Python 2.7 (widely used across many platforms) and Python 3 (the future). I have written Python programs on the Pi which access the command line, use COM ports and the Tkinter GUI module and they run with minor changes on Microsoft Windows by installing the same modules.
As Michael says, you can program in most languages using the Pi. However, Python on the Raspberry Pi comes as standard with a module to access the GPIO features (although the more complex issues such as I2C, serial and PWM have yet to be added). The Broadcom chip is complex and many of its features are entwined with the Linux operating system. It may not be that straight forward to use every GPIO feature. Also, the Pi2 puts its control and read registers at different addresses. The joy of using the Python modules is that the ins and outs of Linux and Broadcom are already sorted. There are plenty of examples of PWM and I2C programs written in Python just using the simple I/O pins rather than the dedicated Broadcom pins. However, C would be the way to go if you want precise time dependant programming as Python is interpreted and has the occasional mid-program tidy-up. Even pre-compiled Python may be a problem.
I just checked with the Synaptic Package Manager and GCC is already installed in the Pi. Java is in the repository as is Fortran, Ada, Objective C, C++, Cobol... you get the idea! There are lots of others such as Ruby and Forth. However, if you want to use c or c++ you will have to do a fair amount of research to drive the GPIO hardware to the full without killing the operating system. All the usual OS stuff is available to C and C++.
-
Re: What is the best way to learn Python?
peterjcs23 Mar 4, 2015 4:01 AM (in response to royleith)Hi Roy thanks for the advice and comprehensive reply.
Learning Python looks like a pretty good book, generally I like O'Reilly books, I use their C Pocket Reference all the time.
python.org is a great resource as you say.
As you may have guessed I am interested in access functions like SPI and interrupts, that look like more of a challenge. I have got used to using PSoC processors and the extensive C support from Cypress.
Peter
-
-
Re: What is the best way to learn Python?
Capper Mar 2, 2015 10:15 AM (in response to peterjcs23)Introduction to Computer Science and Programming Using Python
edX - 6.00.1x is an introduction to computer science as a tool to solve real-world analytical problems
https://www.edx.org/course/introduction-computer-science-mitx-6-00-1x-0#.VPSLYI6VkUM
Scott
-
Re: What is the best way to learn Python?
LenReinhart Mar 2, 2015 11:10 AM (in response to peterjcs23)1 of 1 people found this helpfulIf you haven't found it yet, http://www.themagpi.com/ is a free magazine about all things RPi. There are many projects in python as well as other languages. All the issues are available for download. There are 30 issues now plus some specials.
Python is a high level language and it allows fast problem solving. If it turns out that the problem needs more speed, there are linkages to "C" so the low level stuff can go fast.
I took a free course taught by the Google self driving car guy from https://www.coursera.org/ The course was great, but I don't think a complete python novice would appreciate it (unless fairly fluent in some other languages). There are other courses that are a bit more basic.
-
Re: What is the best way to learn Python?
peterjcs23 Mar 4, 2015 4:15 AM (in response to LenReinhart)Hi Leonard, thanks for the tips. MagPi is now at Welcome to the MagPi | Raspberry Pi...There is plenty to go at there, I'm sure I'll learn a lot.
Interesting that so say one can mix C and Python. Sounds like I'll need C to access fast interfaces like SPI and interrupts.
The https://www.coursera.org/ ; some stuff looks sophisticated as you say. There is a Programming for Everyone (Python) course starting in June, that may be suitable.
https://www.coursera.org/course/pythonlearn
Peter.
-
Re: What is the best way to learn Python?
peteroakesMar 4, 2015 7:00 AM (in response to peterjcs23)
Actually you can easily access SPI with Python as all the hi speed stuff is done in hardware, you just output to a register and watch the magic happen (well a file from pythons perspective)
Sent from my iPhone
-
Re: What is the best way to learn Python?
peterjcs23 Mar 4, 2015 7:09 AM (in response to peteroakes)...okay Peter, it has been a bit confusing over SPI. When I buy a RaspPi does python come with these fast functions documented? They sound like a RaspPi specific function. Is the documentation online, I did have a look but failed to find how to use SPI? ...Peter
-
Re: What is the best way to learn Python?
clem57Mar 4, 2015 7:17 AM (in response to peterjcs23)
You may want to check this out for a discussion on SPI and Raspberry Pi using Memory: http://www.element14.com/community/thread/39396/l/comments-for-using-rpi-with-spi-memory
Cheers,
Clem
-
Re: What is the best way to learn Python?
clem57Mar 4, 2015 7:19 AM (in response to clem57)
As a bonus, it uses Python too!
-
Re: What is the best way to learn Python?
peterjcs23 Mar 5, 2015 3:04 AM (in response to clem57)I picked up some useful GPOI/SPI links from element14 on twitter...
Raspberry Pi 3 Model B GPIO 40 Pin Block Pinout
http://sourceforge.net/p/raspberry-gpio-python/wiki/Home/
https://pypi.python.org/pypi/RPi.GPIO
...sounds like RPi is not ideal for real time work.
-
Re: What is the best way to learn Python?
LenReinhart Mar 5, 2015 4:13 AM (in response to peterjcs23)It all depends on how fast you need to respond; Linux by default is nonpreemptive. The Beagle Bone Black, which I have in addition to the RPi B, B+ and Pi2, has two additional processors on to respond to real time events. Exploring Beagle Bone by Derek Molloy (564 pages) is the best guide I’ve found for it. I got it for $10 more than the Pi, but it has on board storage for the OS and twice as many I/O pins, so I believe it is worth it. The Pi is good for many types of embedded systems though. Someone even used it as a brains for a DLP printer, but he is probably not using the default Linux on it.
-
Re: What is the best way to learn Python?
royleith Mar 5, 2015 4:15 AM (in response to peterjcs23)The RPi is fine for real-time work, but you have to use common sense. Linux is specifically NOT a real time operating system. It is common for serial ports, ethernet ports and other protocols to be set up for debugging purposes. I seem to remember that the hardware I2C pins on the Raspi default to reading any connected I2C memory (and, yes, I've got a couple of cheap 4k chips to play with at some time). Python, even on a true, real-time operating system is interpreted and has automatic housekeeping that can hit timing.
However, raw, non-pre-compiled Python can still be used, for instance, to create an I2C interface on GPIO I/O pins. In-line C code can be embedded in Python objects as a formal part of the language. The I2C and SPI hardware GPIO interfaces are fast and real-time as long as you stop Linux interfering (that is the complexity of providing real-time access to those hardware functions via Python modules).
One of the tricks with Python to improve speed and timing is to 'pre-compile' the object tree and names. I don't do that with the wolfmixer because it obfuscates the code and I want other folk to use my code and ideas, if they want. Pre-compiling certainly reduces all the time taken to reduce the object names to table pointers and code to addresses.
Next, there is a software platform called SWIG 2 for Python that permits C (and C++, IIRC) libraries to be presented as Python objects. I have used it to compile a bit-banging Python program for the FDTI chip on the Raspi. It worked very well, but all the hard work had already been done for me and I had no idea what I was about.
Finally, I have bought a handful of Arduino Mono Chinese clones for a couple of quid each. The Arduino IDE works on the Raspi and any challenging real-time requirements can be dealt with by the tiny Mono for the price of a couple of TI 555 timers. I see this as handy for hobbyist stuff, but any professional use of the Pi should not need additional controllers, just an understanding of what it takes to get real-time functions or real-time hardware working on a complex operating system.
-
Re: What is the best way to learn Python?
clem57Mar 5, 2015 6:23 AM (in response to royleith)
Has anyone thought about loading FreeRTOS on the PI?
-
-
-
-
-
-
-
-
Re: What is the best way to learn Python?
ftruzzi Mar 2, 2015 2:27 PM (in response to peterjcs23)The edX course recommended by Scott is great.
Also check out learnpythonthehardway.org
-
Re: What is the best way to learn Python?
dmnchild Mar 2, 2015 5:02 PM (in response to ftruzzi)This will link you to the html online version. I have found this helpful myself. I have also been doing various book exercises as well to keep it changed up.
-
Re: What is the best way to learn Python?
peterjcs23 Mar 4, 2015 5:14 AM (in response to ftruzzi)thanks Francesco, learnpythonthehardway.org looks good and there is the book too. It sounds quite basic but perhaps a good think for me as I'm more used to low level programming...Peter
-
-
Re: What is the best way to learn Python?
peterjcs23 Mar 3, 2015 9:19 AM (in response to peterjcs23)I'm beginning to get the idea I should have asked the best way to learn about Linux as the OS seems to be fundamental!
-
Re: What is the best way to learn Python?
clem57Mar 3, 2015 9:39 AM (in response to peterjcs23)
Just a random thought, but what about JSON? It can run in a web page environment but also outside!
Clem
-
Re: What is the best way to learn Python?
mconnersMar 3, 2015 9:43 AM (in response to clem57)
Are you talking about Javascript and Node.js?
JSON is javascript object notation, but has also become a popular data exchange format.
Mike
-
-
Re: What is the best way to learn Python?
peterjcs23 Mar 4, 2015 5:24 AM (in response to clem57)Clem okay, there are plenty of options with the Raspberry Pi, I get that now. I see a lot of python examples, so I may start there. Peter
-
Re: What is the best way to learn Python?
peteroakesMar 4, 2015 7:02 AM (in response to peterjcs23)
One thing to remember, Python is interpreted, c is compiles and therefor will pretty much always be way faster
Sent from my iPhone
-
-
-
Re: What is the best way to learn Python?
peteroakesMar 3, 2015 10:00 AM (in response to mconners)
You should check out “Node Red” for the PI, it looks to be awesome and a great intro to programming on the PI
-
Re: What is the best way to learn Python?
clem57Mar 3, 2015 10:20 AM (in response to peteroakes)
Thanks peteroakes
Even install for Rpi 2 at http://nodered.org/docs/hardware/raspberrypi.html
I am very impressed!
Clem
-
Re: What is the best way to learn Python?
peteroakesMar 3, 2015 11:42 AM (in response to clem57)
Your welcome, I think this environment is worthy of a few blog posts, it looks to be a great tool and is very extendable for additional hardware
-
-
-
Re: What is the best way to learn Python?
peterjcs23 Mar 4, 2015 5:28 AM (in response to peteroakes)Hi Peter, yes I like the look of Node Red. Visual programming can be very effective, I've used PSoC Creator with good results.
Peter
-
-
-
-
Re: What is the best way to learn Python?
peteroakesMar 3, 2015 10:46 PM (in response to peterjcs23)
Life long friend of mine has started some interesting stuff with Code Red and posted on YouTube https://www.youtube.com/watch?v=xoQ_Fs31xtM
Enjoy
Peter
-
Re: What is the best way to learn Python?
ProblemchildNov 15, 2015 4:15 PM (in response to peterjcs23)
With a project, preferably your own that you are interested in so you are likely to stick with it.
Failing that the EdX Computing course is very good as it teaches Python in a very structured manner and is free!
I have written software in C for embedded processors. Raspberry Pi uses Python, so what is the best way to learn it? What is the best book? What about a web based tutorial?
C has a standard core and suppliers of compilers add functions. Is Python similar, do I need to learn the Raspberry Pi version?
Thanks, Peter