How do you run python code from your computer to a raspberry PI?
I would love to get into a little bit of robotics coding to build some really cool things! #computer #programming #technology #computer-science
Once that's done, your best bet is to go to https://www.raspberrypi.com/software/ and download the Raspberry Pi Imager. From there you can decide if you want a GUI on the Pi or not (you probably don't want or need the overhead for robotic projects, so under "Choose OS" you'd pick "Raspberry Pi OS (Other)", then the appropriate "Raspberry Pi OS Lite" for your hardware). The program walks you through burning an SD card, insert in your Pi, and *poof* you have Linux. Log in, run "python", rock and roll.
Once your code's stable, then you can make the Pi filesystems read-only so that power-up and power-down are simple. See https://learn.adafruit.com/read-only-raspberry-pi/ for an excellent article on how that's done. Another approach is to put a UPS "Hat" on your Pi -- really a small battery backup with the capability to tell the Pi to power down gracefully when its capacity starts to wane. I've taken both avenues, and they both work fine.
In order to get programs from your development host to the Pi, a couple of avenues are available:
- You can simply use SFTP to upload your programs to your Pi, then run them via an SSH console.
- You can invest in an IDE like PyCharm, which you can use to remotely execute and debug your code.
- You can just do your development directly on the Pi using something like vim, then run and debug your code in another SSH session.
I find that for small projects, the last option works just fine.
I never did it myself but I believe Fred's suggestion is probably what you need:
- get some python environment on your computer and make sure it runs
- get some rasberry pi integrated development environment and/or software development kit and check if it needs to be configured to use the python you installed or if it comes with its own. In case of the latter, you may not need to install another python environment.
Then make a simple program and try to upload it on your target.
I would recommend to start with some general python coding first, learn how to debug and then go embedded. Embedded systems come with some complexity that may be hard to deal with if you are not use to standard debugging.
Joe recommends the following next steps:
There is most likely an integrated development environment (known as an IDE) of some kind. you would write the code on your computer, and possibly even test it in a virtual environment. Then, via a USB cable, wifi, or bluetooth, download the code onto your raspberry pi. I'm not sure then what triggers it to run, but that's my guess.