GPS Speedometer & Rear View Camera - Carver - 09-02-2019
Hi All,
I've been writing two python apps that have now become one. I started off with the GPS Speedometer which works quite well. Then I wanted an app to control the rear view camera, like the Everlander YouTube solution, but I didn't want hardware buttons.
The problem I'm having is that a want them to stay in the foreground. When booting they come up just fine with my app up-front. I can switch the camera on and off no problem at all. It's when I use OpenAuto that I can't bring my apps to the foreground very easily.
Does anyone have a solution?
Here's a really rubbish, but it gets the point across, video I just uploaded to YouTube:
My code can be found on GitHub, here: python gps speedometer and camera control
RE: GPS Speedometer & Rear View Camera - Carver - 09-10-2019
Hi All,
I've updated the script to include rear-view camera Start, Stop & Record buttons. Must look into learning PyQT to make the graphics better...
RE: GPS Speedometer & Rear View Camera - Daniel_BlueWave - 09-10-2019
Thank you for sharing. Looks promising.
We are sure that many OpenAuto Pro users can benefit form you solution. Keep doing good job.
RE: GPS Speedometer & Rear View Camera - cantonebiat - 09-11-2019
(09-10-2019, 10:37 AM)Carver Wrote: Hi All,
I've updated the script to include rear-view camera Start, Stop & Record buttons. Must look into learning PyQT to make the graphics better...
Great Work!
RE: GPS Speedometer & Rear View Camera - skrimo - 02-09-2020
Tried to get speedo to work but have no luck. I would really appreciate the help, because my cars speedometer sensor died, and it will take me a month to get new one.
I allready have GLOBAL SAT BU-353-S4 USB GPS connected to the raspberry pi that with a script synchronize gps time to the raspberry pi.
I have Raspberry pi 4 connected to the official 7inch touchscreen, latest OAP6.0 software,...
RE: GPS Speedometer & Rear View Camera - ktb - 02-09-2020
(02-09-2020, 08:01 AM)skrimo Wrote: Tried to get speedo to work but have no luck. I would really appreciate the help, because my cars speedometer sensor died, and it will take me a month to get new one.
I allready have GLOBAL SAT BU-353-S4 USB GPS connected to the raspberry pi that with a script synchronize gps time to the raspberry pi.
I have Raspberry pi 4 connected to the official 7inch touchscreen, latest OAP6.0 software,...
You changed the following, right? I know your GPS has a different device name based on playing around with your other time sync script.
gps = serial.Serial("/dev/ttyACM1", baudrate = 9600)
RE: GPS Speedometer & Rear View Camera - skrimo - 02-09-2020
OK will try it again
RE: GPS Speedometer & Rear View Camera - ktb - 02-09-2020
Note: If you don't have a Pi Camera hooked up and working, you will also have to comment out some lines from speedo.py
Add your user to the staff group
pi@raspberrypi:~ $ sudo adduser pi staff
Adding user `pi' to group `staff' ...
Adding user pi to group staff
Done.
Reboot -- or -- logout and login again
pi@raspberrypi:~ $ id pi
uid=1000(pi) gid=1000(pi) groups=1000(pi),4(adm),20(dialout),24(cdrom),27(sudo),29(audio),44(video),46(plugdev),50(staff),60(games),100(users),105(input),109(netdev),999(spi),998(i2c),997(gpio)
pi@raspberrypi:~ $ mkdir ~/software
pi@raspberrypi:~ $ cd ~/software
pi@raspberrypi:~/software $ git clone https://github.com/CarverFan/carver.git
Cloning into 'carver'...
remote: Enumerating objects: 14, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 14 (delta 3), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (14/14), done.
pi@raspberrypi:~/software $ cd carver
Convert the files to have proper Unix line endings (the developer likely created these files on Windows).
pi@raspberrypi:~/software/carver $ dos2unix speedo.py
pi@raspberrypi:~/software/carver $ dos2unix gaugelib.py
pi@raspberrypi:~/software/carver $ dos2unix rvcamlib.py
Edit speedo.py to verify/set the correct GPS device (in my case /dev/ttyACM0).
pi@raspberrypi:~/software/carver $ nano speedo.py
pi@raspberrypi:~/software/carver $ cat speedo.py
#!/usr/bin/python3
from tkinter import *
#import tkinter as tk
#from tkinter.font import Font
#from tkinter import messagebox
from time import time, sleep
import random
import gaugelib
import serial
from picamera import PiCamera
import rvcamlib
gps = serial.Serial("/dev/ttyACM0", baudrate = 9600)
win = Tk()
#a5 = PhotoImage(file="g1.png")
#win.tk.call('wm', 'iconphoto', win._w, a5)
win.title("Speed")
win.geometry("200x320+0+0")
win.resizable(width=False, height=False)
win.configure(bg='black')
runWindow = rvcamlib.rearViewCam(win)
g_value=0
x=0
course="0"
def read_every_second():
global x
global g_value_mph
global course
#g_value=random.randint(0,70)
line = gps.readline().decode("utf-8")
data = line.split(",")
if data[0] == "$GNVTG":
# km/h
g_value = float(data[7])
# mph
g_value_mph = (g_value / 1.609)
courseEmptyTest = data[1]
print("cempty: %s" % (courseEmptyTest))
if courseEmptyTest == '':
course = 0
else:
course = float(data[1])
if course == 0:
courseText = 'North'
elif 1 <= course <= 44:
courseText = 'NNE'
elif course == 45:
courseText = 'NE'
elif 46 <= course <= 89:
courseText = 'ENE'
elif course == 90:
courseText = 'East'
elif 91 <= course <= 134:
courseText = 'ESE'
elif course == 135:
courseText = 'SE'
elif 136 <= course <= 179:
courseText = 'SSE'
elif course == 180:
courseText = 'South'
elif 181 <= course <= 224:
courseText = 'SSW'
elif course == 225:
courseText = 'SW'
elif 226 <= course <= 269:
courseText = 'WSW'
elif course == 270:
courseText = 'West'
elif 271 <= course <= 314:
courseText = 'WNW'
elif course == 315:
courseText = 'NW'
elif 316 <= course <= 359:
courseText = 'NNW'
else:
courseText = '???'
p1.set_value(int(g_value_mph), str(courseText))
print("mph: %.2f, course: %s" % (g_value_mph, courseText))
print("VTG: %s" % (data))
if data[0] == "$GNRMC":
#print("RMC: %s" % (data))
if data[2] == "A":
dateTime = str(data[9]) + str(data[1])
latgps = float(data[3])
if data[4] == "S":
latgps = -latgps
latdeg = int(latgps/100)
latmin = latgps - latdeg*100
lat = latdeg+(latmin/60)
longps = float(data[5])
if data[6] == "W":
longps = -longps
londeg = int(longps/100)
lonmin = longps - londeg*100
lon = londeg+(lonmin/60)
direction = data[8]
with open("/media/usb/gps/gps-data-" + str(data[9]) + ".log", "a+") as pos:
pos.write("Lat: %s, Lon: %s, dt: %s\n" % (lat, lon, dateTime))
if 'g_value_mph' in globals():
pos.write("mph: %.2f, Direction: %s\n" % (g_value_mph, direction))
x+=1
if x>100:
#graph1.draw_axes()
x=0
win.after(100, read_every_second)
p1 = gaugelib.DrawGauge2(
win,
max_value=100.0,
min_value=0.0,
size=200,
bg_col='black',
unit = "SPEED", unit1="HEADING", bg_sel = 2)
p1.grid(row=0, columnspan=3)
read_every_second()
mainloop()
Edit rvcamlib.py to change vidpath variable if necessary
pi@raspberrypi:~/software/carver $ nano rvcamlib.py
pi@raspberrypi:~/software/carver $ cat rvcamlib.py
#!/usr/bin/python3
from time import time, sleep
from tkinter import *
from picamera import PiCamera
from datetime import datetime, date, timedelta
camera = PiCamera()
vidpath = '/home/pi/Videos/'
class rearViewCam:
def __init__(self, master):
self.master = master
self.button_clicks = 0
self.labelText = StringVar()
self.labelText.set("Cam Status Off")
self.camStatus = Label(master, textvariable=self.labelText)
self.camStatus.grid(row=2,columnspan=3)
self.startButton = Button(master, text="Start", command=self.startCam)
self.startButton.grid(row=1,column=0)
self.stopButton = Button(master, text="Stop", state=DISABLED, command=self.stopCam)
self.stopButton.grid(row=1,column=1)
self.recButton = Button(master, text="Record", fg="green", command=self.recCam)
self.recButton.grid(row=1,column=2)
def startCam(self):
self.labelText.set("Running")
self.stopButton.config(state=NORMAL)
camera.resolution = (1024, 768)
camera.start_preview(fullscreen = False,
window = (185,25,510,350))
def stopCam(self):
if self.startCam is not None:
self.startf = None
camera.stop_preview()
self.labelText.set("Stopped")
def recCam(self):
self.button_clicks += 0
self.labelText.set("Recording ")
self.recButton['text'] = "Start"
if self.button_clicks == 0:
self.button_clicks += 1
self.recButton['text'] = "Started"
self.recButton['fg'] = "red"
# start recording
now = datetime.now()
dtStr = now.strftime("%d%m%Y-%H%M%S")
vidfile = vidpath + "vid-" + dtStr + ".h264"
camera.resolution = (1024, 768)
camera.start_recording(vidfile)
else:
self.labelText.set("Stopped Recording")
self.recButton['text'] = "Record"
self.recButton['fg'] = "green"
# stop recording
camera.stop_recording()
self.button_clicks = 0
Install the files
pi@raspberrypi:~/software/carver $ sudo install -o root -g staff -m 0770 -T speedo.py /usr/local/bin/speedo.py
pi@raspberrypi:~/software/carver $ sudo install -o root -g staff -m 0770 -T rvcamlib.py /usr/local/bin/rvcamlib.py
pi@raspberrypi:~/software/carver $ sudo install -o root -g staff -m 0770 -T gaugelib.py /usr/local/bin/gaugelib.py
RE: GPS Speedometer & Rear View Camera - skrimo - 02-10-2020
Somehow managed to fix speedometer in my car.. And also this looks way too complicated for me to get it to work.
|