Skip to main content
4 answers
4
Asked 477 views

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

+25 Karma if successful
From: You
To: Friend
Subject: Career question for you

4

4 answers


1
Updated
Share a link to this answer
Share a link to this answer

Jerome’s Answer

I do it all the time. Since I'm using Raspberry Pi Model B units, I bought a couple of inexpensive Edimax USB wireless dongles, one for each Pi. You may or may not want to do that, as wired connection or built-in WiFi may better suit your needs.

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.

Happy developing!
1
0
Updated
Share a link to this answer
Share a link to this answer

Fred’s Answer

I don't have a raspberry pi, so i'm not sure, but i have a guess...

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.
0
0
Updated
Share a link to this answer
Share a link to this answer

Joe’s Answer

I like the answers given so far but also wanted to mention using some prebuilt images for the device. For example QEngineering has a few builds for specific Pi use cases and focus areas. This will save you the time of installing multiple libraries and configuration efforts. For example here is one for doing Deep Learning:

https://github.com/Qengineering/RPi-image

Joe recommends the following next steps:

Visit QEngineering GitHub
Search repositories for Pi image of interest
Use Etcher or similar tool to burn image to microSD card
0
0
Updated
Share a link to this answer
Share a link to this answer

Mickael’s Answer

Hi Cooper,

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.
0