I am coding a display for a formula car team I work on and have hit a snag. My code on my pi compiled well enough and when it wasn't wired into the car's CAN network it said the network was down but I was still able to make it open the window and all my gauges would read 0. However once that display was moved off my TV and into the car's 4" LCD screen and it was wired into the CAN network the board was able to pull data from the network no problem and the code compiles with no errors but the window that contained my gauges would no longer open, the terminal would read everything it was supposed to for a successful connection to the network but no window with gauges appear. My code is below and the dimensions of my screen according to the data sheet it 800x480.
Code: Select all
#!/usr/bin/env python3 from tkinter import * import tkinter as tk from tkinter.font import Font from tkinter import messagebox import time import random import gaugelib import can import RPi.GPIO as GPIO import os import queue from threading import Thread COOL_data = 0x8CFFF548 RPM_data = 0x8CFFF048 SHAFT_data = 0x6FA020A print('\n\rLets Go Racing!') print('\n\rBring up CAN0...') #bring up can interface at 500mbps os.system("sudo /sbin/ip link set can0 up type can bitrate 500000") time.sleep(0.1) print('\n\rReady') try: bus = can.interface.Bus(channel='can0', bustype='socketcan_native') except OSError: print('cannot find CAN.') exit() def can_rx_task(): #receive thread while True: message = bus.recv() if message.arbitration_id == COOL_data or message.arbitration_id == RPM_data: q.put(message) q = queue.Queue() rx = Thread(target = can_rx_task) rx.start() win = tk.Tk() #a5 = PhotoImage(file="g1.png") these two lines caused errors but the code compiles and displayed without them #win.tk.call('wm', 'iconphoto', win._w, a5) win.title("Cyclone Racing") win.geometry("400x240+60+6") win.resizable(width=True, height=True) win.configure(bg='black') g_value=0 rpm=0 ratio = 0 gear = 0 shaft = 0 coolant = 0 x=0 def read_every_second(): global x message = q.get() if message.arbitration_id == RPM_data: rpm = message.data*256 + message.data p1.set_value(int(rpm)) if message.arbitration_id == COOL_data: coolant= message.data*256+message.data if coolant >32767: coolant = (cool-65536)/10 p2.set_value(int(coolant)) if message.arbitration_id == SHAFT_data: shaft=message.data ratio = rpm/shaft p3.set_value(float(ratio)) x+=1 if x>100: # graph1.draw_axes() x=0 win.after(100, read_every_second) p1 = gaugelib.DrawGauge2( win, max_value=20000, min_value=0, size=300, bg_col='black', unit = "Tach. RPM",bg_sel = 2) p1.pack() #p2 = gaugelib.DrawGauge2( edited out because this will be used in the future but not immediately for the first race # win, # max_value=5, # min_value= 0, # size=150, # bg_col='black', # unit = "Gear",bg_sel = 2) #p2.pack(side = RIGHT) p3 = gaugelib.DrawGauge3( win, max_value=200.0, min_value= 0.0, size=150, bg_col='black', unit = "Temp. F",bg_sel = 1) p3.pack(side = LEFT) read_every_second() mainloop()