1

I am currently working on a university Raspberry Pi RC Car Project that deals with image collection along with key user input data. What i cannot seem to understand from various tutorials online is to transmit the data taken from the raspberry pi to the pc aka stream the data and save it locally on the PC. Right now the images the pi takes end up all black unless i give it a longer time out, and this is not my optimum solution towards this issue. Any recommendations to approach taking images at the same time as the user input and storing it together as a csv locally on the pc would be appreciated. A total newbie with Pis

This is the code that i am working with at the moment.

import RPi.GPIO as gpio
import time
import sys
import Tkinter as tk
from PIL import Image 
import numpy as np
import os
import csv
import picamera
import datetime
import numpy as np

def snapPhoto():
  timestampStr = datetime.datetime.now().strftime("%d %H:%M:%S")  
  with picamera.PiCamera(resolution=(640, 480), framerate=90) as camera:                                                                                                                        
    camera.shutter_speed = 800                                                                            
    camera.start_preview()                                                                                         
    time.sleep(1)                                                                                                                    
    camera.capture("{0}\n".format(timestampStr)+'.jpg', use_video_port=True)                    

def init():
 gpio.setmode(gpio.BCM)
 gpio.setup(17, gpio.OUT)
 gpio.setup(22, gpio.OUT)
 gpio.setup(23, gpio.OUT)
 gpio.setup(24, gpio.OUT)

def forward(tf):
 gpio.output(17, True)
 gpio.output(22, False)
 gpio.output(23, True)
 gpio.output(24, False)
 time.sleep(tf)
 gpio.cleanup()

def reverse(tf):
 gpio.output(17, False)
 gpio.output(22, True)
 gpio.output(23, False)
 gpio.output(24, True)
 time.sleep(tf)
 gpio.cleanup()

def left(tf):
 gpio.output(17, True)
 gpio.output(22, True)
 gpio.output(23, True)
 gpio.output(24, False)
 time.sleep(tf)
 gpio.cleanup()

def right(tf):
 gpio.output(17, False)
 gpio.output(22, False)
 gpio.output(23, False)
 gpio.output(24, True)
 time.sleep(tf)
 gpio.cleanup()

def stop(tf):
 gpio.output(17, False)
 gpio.output(22, False)
 gpio.output(23, False)
 gpio.output(24, False)
 time.sleep(tf)
 gpio.cleanup()


def key_input(event):
 init()
 #print 'Key:' , event.char
 key_press = event.char
 sleep_time = 0.030

if key_press.lower() == 'w':
    forward(sleep_time)
    with open("/home/pi/Desktop/data.csv", "a") as log:
        log.write("{0}\n".format('w'))
        snapPhoto()
        pass
elif key_press.lower() == 's':
    reverse(sleep_time)
    with open("/home/pi/Desktop/data.csv", "a") as log:
        log.write("{0}\n".format('s'))
        pass
elif key_press.lower() == 'a':
    left(sleep_time)
    with open("/home/pi/Desktop/data.csv", "a") as log:
        log.write("{0}\n".format('a'))
        pass
elif key_press.lower() == 'd':
    right(sleep_time)
    with open("/home/pi/Desktop/data.csv", "a") as log:
        log.write("{0}\n".format('d'))
        pass
elif key_press.lower() == 'x':
    stop(sleep_time)
    with open("/home/pi/Desktop/data.csv", "a") as log:
        log.write("{0}\n".format('x'))
        pass
else:
    pass

command = tk.Tk()
command.bind('<KeyPress>',key_input)
command.mainloop()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.