biker67
Posts: 30
Joined: Wed Oct 24, 2018 1:58 pm

errors at run time under auto start

Sun Dec 09, 2018 10:30 pm

This code is the product of all my previous post and runs without error using "run module". Most recently I have been hungup on getting auto start to function at boot. With the URL listed below , I think that start at boot is possible. There is a problem however. A raspberry pi post is the source of the most help concerning auto start. It is executable (anyone can run it 3X under permissions tab).
https://www.raspberrypi-spy.co.uk/2015/ ... y-pi-boot/
The errors listed on the terminal screen are in the IMAGE attached. I have no idea how to reproduce those same errors. When the program is in IDLE ,DEBUG is not an option.
Image
see bottom for image.
The "autorun" doesn't like line 7, turtle.setup("799, 479")
objects to FILE <"string"> in line 6, etc....

[code #!/usr/bin/python3
import turtle
from turtle import *
import tkinter as tk
import time, random
import RPi.GPIO as GPIO
turtle.setup(799,479)

# --- functions --- (lower_case_names)
def main():
global red, blue, green, pink, orange, cyan, grey, yellow
global acolor, equip, txtcolor, wirepos, fun1, fun2, status, height, width
global color, w, t, Choice
equip="back"
red = 5
blue = 25
green = 23
pink = 6
orange = 17
cyan = 13
grey = 16
yellow = 12
status = 1
height = 150.0 # now it is float
width = height * .75
width = round(width, 2)

def initGPIO():
global red, blue, green, pink, orange, cyan, grey, yellow
out_putslist = ['5','25','23','6','17','13','16','12']
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(5,GPIO.OUT,initial=1)
GPIO.setup(25,GPIO.OUT,initial=1)
GPIO.setup(23,GPIO.OUT,initial=1)
GPIO.setup(6,GPIO.OUT,initial=1)
GPIO.setup(17,GPIO.OUT,initial=1)
GPIO.setup(13,GPIO.OUT,initial=1)
GPIO.setup(16,GPIO.OUT,initial=1)
GPIO.setup(12,GPIO.OUT,initial=1)

initGPIO()

rect_list = [(-350,190,-330,140,0,0,"red","black","HORN"," ",5,1),
(-200,190,-190,140,-190,120,"blue","aquamarine","NAVAGA","LIGHTS",25,1),
(50,190,60,140,60,120,"green","black","COCKPIT","LIGHTS",23,1),
(200,190,220,140,220,120,"pink","black","T-TOP","LIGHTS",6,1),
(-350,-50,-330,-100,-330,-120,"orange","black","BILGE","PUMP",17,1),
(-200,-50,-180,-100,-180,-120,"cyan","black","WASH","DOWN",13,1),
(50,-50,70,-100,70,-120,"grey","black","FRONT","WELL",16,1),
(200,-50,220,-100,220,-120,"yellow","black","BACK","WELL",12,1)]

def draw_rect(x1, y1, width, height, color):
y1 = -y1
print(x1, y1)
canvas = turtle.getcanvas()
canvas.create_rectangle((x1, y1, x1+width, y1+height), fill=color, width=0)

def draw_it(): # draws one colored square with lables
height = 150.0 # now it is float
width = height * .75
width = round(width, 2)
turtle.penup()
draw_rect(x1, y1, width, height, color)
turtle.goto(x2,y2)
if color == "blue":
turtle.color("aquamarine")
turtle.write(fun1,font=('Arial', 14, 'normal'))
turtle.goto(x3,y3)
turtle.write(fun2,font=('Arial', 14, 'normal'))
if color == "blue":
turtle.color("black")
turtle.penup()
return

def all_off():
print("shit1")
for [x1,y1,x2,y2,x3,y3,color,txtcolor,fun1,fun2,wirepos,status] in rect_list:
w = (x1)
t = (y1+10)
channel = int(wirepos)
status = 1
print(channel, status)
GPIO.output(channel,status) # set channel to high
print(Choice)
x1 = w; y1 = t; width = 112; height = 10
color = ("white")
draw_rect(x1, y1, width, height, color)
print("\033[4\033[J")

def get_pixel_color(x, y):
# canvas use different coordinates
y = -y
canvas = turtle.getcanvas()
ids = canvas.find_overlapping(x, y, x, y)
if ids: # if list is not empty
index = ids[-1]
color = canvas.itemcget(index, "fill")
if color != '':
return color.lower()

return "white" # default color

def modify_global_variables(rawx,rawy):
global xclick
global yclick
global equip
global acolor
global w, t, Choice
w = 0
t = 0

xclick = int(rawx)
yclick = int(rawy)
Choice = (get_pixel_color(xclick, yclick)) # color of square touched

if Choice == "black":
return

if Choice == "darkred": # KILL SWITCH
print(Choice)
all_off()

if Choice == "aquamarine":
return

if Choice == "white":
x1=-225; y1=20; width=450; height=50 # cleanup verify zone
color="white"
draw_rect(x1, y1, width, height, color)
return

for x1,y1,x2,y2,x3,y3,color,txtcolor,fun1,fun2,wirepos,status in rect_list:
if Choice in [x1,y1,x2,y2,x3,y3,color,txtcolor,fun1,fun2,wirepos,status]:
x1=-225; y1=20; width=400; height=50
color = "white"
#turtle.pendown()
draw_rect(x1, y1, width, height, color) # on / off rectangle erased

x1=-225; y1=20; width=200; height=50
color = "red2"
draw_rect(x1, y1, width, height, color)

x1=-25; y1=20; width=50; height=50
color = Choice;
draw_rect(x1, y1, width, height, color)

x1 = 25; y1 = 20; width=200; height=50
color = "green2"
draw_rect(x1, y1, width, height, color)

color = "black"
turtle.goto(-160,-20)
turtle.write("OFF", font=('arial', 16, 'normal'))

turtle.goto(160,-20)
turtle.write("ON", font=('arial', 16, 'normal'))

turtle.goto(-60,-20)
turtle.write(fun1, font=('arial', 14, 'normal'))
equip = fun1
acolor = Choice # color of function clicked on
return

if Choice == "green2": # on means light goes off!
#turn on/off gadgets
for [x1,y1,x2,y2,x3,y3,color,txtcolor,fun1,fun2,wirepos,status] in rect_list:
if acolor in [x1,y1,x2,y2,x3,y3,color,txtcolor,fun1,fun2,wirepos,status]:
w = (x1)
t = (y1+10)
channel= int(wirepos)
status = 0
GPIO.output(channel,status)
function_on_off()

if Choice == "red2": # off means light comes on!
#turn on/off gadgets
for [x1,y1,x2,y2,x3,y3,color,txtcolor,fun1,fun2,wirepos,status] in rect_list:
if acolor in [x1,y1,x2,y2,x3,y3,color,txtcolor,fun1,fun2,wirepos,status]:
w = (x1)
t = (y1+10)
channel= int(wirepos)
status = 1
GPIO.output(channel,status)
function_on_off()
return

def function_on_off():
if Choice == "red2":
color = "black"
if Choice == "green2":
color = "magenta"
x1=w; y1=t; width=112; height=10
draw_rect(x1, y1, width, height, color)
turtle.goto(0,0)
x1=-225; y1=20; width=450; height=50
color = ("white")
turtle.pendown()
draw_rect(x1, y1, width, height, color)
color = ("black")
turtle.penup()
return

# --- main ---# Global variables specifying the point clicked

xclick = 0
yclick = 0
wirepos=0

# Draw rectangles

height = 150.0 # now it is float
width = 100
width = round(width, 2)

# Use tkinter.Canvas to draw rectangle
for x1,y1,x2,y2,x3,y3,color,txtcolor,fun1,fun2,wirepos,status in rect_list:
turtle.hideturtle()
draw_it() # main loop rectangle draw 1st x

turtle.goto(-20,180)
turtle.pendown()
turtle.pensize(10)
turtle.color("darkred")
circle(15)
turtle.penup()
turtle.goto(-40,140)
turtle.write("KILL",font=('Arial', 16, 'normal'))
turtle.color("black")

# Gets the click & Modifies the global variables


turtle.onscreenclick(modify_global_variables)

turtle.done()

#main program logic
if __name__ == '__main__':
main()
][/code]
Attachments
a snapshot of RPi problems_resized.jpg
a snapshot of RPi problems_resized.jpg (49.62 KiB) Viewed 145 times

biker67
Posts: 30
Joined: Wed Oct 24, 2018 1:58 pm

Re: errors at run time under auto start

Mon Dec 10, 2018 3:37 am

here is a picture perfect example of a copied program (one of many) that runs in python 3.7.1 BUT at the same time is generating red ink on the shell page; meaning it probably will not run from autostart; in the same manner that my program runs from "run Module" but hangs up if asked to auto run.
Is this the best one can expect? I realize I know very little about python but I haven't stumbled on anything yet because why ...? I don't know the answer.

Code: Select all

import turtle 

painter = turtle.Turtle()

painter.pencolor("blue")

for i in range(50):
    painter.forward(50)
    painter.left(123) # Let's go counterclockwise this time 
    
painter.pencolor("red")
for i in range(50):
    painter.forward(100)
    painter.left(123)
    
turtle.done()
Last edited by biker67 on Mon Dec 10, 2018 2:27 pm, edited 1 time in total.

DirkS
Posts: 9602
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: errors at run time under auto start

Mon Dec 10, 2018 8:20 am

Please repair your code blocks. It looks like you managed to delete some brackets...
And also post your error message(s) as text, also in a code block

biker67
Posts: 30
Joined: Wed Oct 24, 2018 1:58 pm

Re: errors at run time under auto start

Mon Dec 10, 2018 2:32 pm

This are the errors produced by the copied exmpleary from above. My plan was to grab a perfect program and run it thorough the auto start process to prove that it can be done.

Code: Select all

=============== RESTART: /home/pi/mypigraphics/monday_temp.py ===============
Traceback (most recent call last):
  File "/home/pi/mypigraphics/monday_temp.py", line 9, in <module>
    painter.left(123) # Let's go counterclockwise this time
  File "/usr/lib/python3.5/turtle.py", line 1699, in left
    self._rotate(angle)
  File "/usr/lib/python3.5/turtle.py", line 3276, in _rotate
    self._update()
  File "/usr/lib/python3.5/turtle.py", line 2660, in _update
    self._update_data()
  File "/usr/lib/python3.5/turtle.py", line 2646, in _update_data
    self.screen._incrementudc()
  File "/usr/lib/python3.5/turtle.py", line 1292, in _incrementudc
    raise Terminator
turtle.Terminator
>>> 

User avatar
topguy
Posts: 5081
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: errors at run time under auto start

Fri Dec 14, 2018 9:20 am

The error "No display name and no $DISPLAY variable set" just confirms what I said in the other thread. TkInter needs a running X-server.

Return to “Beginners”