Stream Camera while Controlling GoPiGo


Hello Forum!

I want to stream what the picam capture while i control the GoPiGo with “w” “a” “s” “d” as the script provided “”.

In order to the streaming video i wrote this little code and it works:

import all the libraries needed
camera = PiCamera()
camera.framerate = 5
rawCapture = PiRGBArray(camera, size(w,h))

from frame in camera.capture_continuous (rawCapture, format"bgr", use_video_port=True):
     image_RGB = frame.array

     cv2.imshow("Image", image_RGB)
     key = cv2.waitKey(1) & 0xFF
     if key == ord("q"):

With this code, where and how would you put the:

   while True:
           print "nCmd:",
           a = raw_input()
           if a=='w':
           elif a=='a':
           elif a=='d':
           elif a=='s':
           elif a=='x':

in order to work at the same time?

Thanks a bunch again!


To make them work at the same time, you can either have 2 different programs running in 2 sessions via VNC or SSH or you can have a single program with multiple threads. It would be hard to get it to work without threads in a single program.



Sorry, but i’m a noob and i don’t know what you mean by threads. Is there an easy way to get all this stuff running into one script ?

Thanks again karan!


check out this link here :Python Multithreaded Programming.

Running several threads is similar to running several different programs concurrently


Thanks Exadon!

I’ve been testing some examples, and i understand how it works (more or less). On the scripts i wrote, It seems that only works one thread.

So, I own a Raspberry pi B+, can i deal with threading codes whit the B+ ? or should i upgrade to Raspberry pi 2 in order to send two programs by two different threads just to run them in parallel ?

Seriously, thank you very much!


You are fine with any model of the raspberry pi.


Well, I’ve been trying some examples but i can only execute one program.

I wrote this code:

import threading

class prog(threading.Thread):

       def __init__(self): 
       def run(self):
               while True:
                      print "First program"

class prog2(threading.Thread):
def run(self):
while True:
print “Second program”



And… with this code i get all the time: “First program”

So if you please, can tell me why the second program isn’t running, i’ll be grateful.

Thanks a bunch!


Stackoverflow might be a better place to look for answers around threading. I am not sure what the problem is exactly but there will be a lot of good posts on stackoverflow to get you started with threading like this: .



Thanks again Karan!!

I’ll ask there!