question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't use screen AND motors ?

See original GitHub issue
  • **ev3dev version: 4.4.32-17-ev3dev-ev3
  • **ev3dev-lang-python version: python_ev3dev-0.8.0.post4-py2.7.egg (not sure this is what’s wanted)

Hi,

I can’t figure what the problem is with my code : I want to calibrate my light sensor, in order to follow a black line. I want the robot to oscillate 4 times, so that the sensor can update the max_white and max_black values. I have succeeded using the lcd screen and the motors, but separately. If I put all my functions in the same file, it will not work, but if I use the functions in different files, the code works. In fact, the motors will run, but the display isn’t even changed from its original state, and the values are not updated.

I am not exactly sure if it’s a bug somewhere, or if it’s due to my very beginner level in programming.

Here is my code :

#!/usr/bin/python3
#  -*- coding: utf-8 -*-
from ev3dev.ev3 import *
from  PIL import ImageFont
from threading import Thread
from time import sleep
lcd = Screen()
globalstop = 0
ts = TouchSensor()
color_sensor = ColorSensor()
color_sensor.mode='COL-REFLECT'
motor_left = LargeMotor('outB')
motor_right = LargeMotor('outC')
f = ImageFont.truetype('/usr/share/fonts/truetype/msttcorefonts/Arial.ttf', 15)
max_white = 0
max_black = 100

def motors():
    global globalstop
    sleep(0.5)
    for i in range(4):
        if i % 2 == 0:
            motor_right.run_to_rel_pos(position_sp=180, speed_sp=200, stop_action='brake')
            motor_left.run_to_rel_pos(position_sp=-180, speed_sp=200, stop_action='brake')
            motor_right.wait_while('running')
            motor_left.wait_while('running')

        else:
            motor_right.run_to_rel_pos(position_sp=-180, speed_sp=200, stop_action='brake')
            motor_left.run_to_rel_pos(position_sp=180, speed_sp=200, stop_action='brake')
            motor_right.wait_while('running')
            motor_left.wait_while('running')
        print (i+1)
    globalstop = 1

motors = Thread(target=motors())


def display_and_update():
    global max_white, max_black, globalstop
    while globalstop == 0:
        lcd.clear()
        lcd.draw.text((10, 10), "max_white : %s" % max_white,font=f)
        lcd.draw.text((10, 40), "max_black : %s" % max_black,font=f)
        lcd.update()
        if max_white < color_sensor.value():
            max_white = color_sensor.value()
        if max_black > color_sensor.value():
            max_black = color_sensor.value()

disp_and_update = Thread(target=display_and_update())

#start the threads
motors.start()
disp_and_update.start()

#finally, output the values
print ("max_white : ", max_white, "max_black : ", max_black)

Any help appreciated !

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ddemidovcommented, Dec 9, 2016
0reactions
dlechcommented, Dec 10, 2016

I think (?) that virtual terminal 2 is reserved for Brickman child apps

OpenRoberta, specifically. But if openroberta.service is not running, it is free.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do you fix the touch screen in a car? - Jerry
Reboot the touchscreen by turning it off and back on again; Recalibrate the screen from the settings menu; Perform a factory reset. If...
Read more >
8 Best Ways to Fix Android Auto Black Screen Issue
The Android Auto black screen issue has plagued several users. Are you one of them? If yes, here are some solutions to fix...
Read more >
Car display screen unresponsive. Touchscreen lockout
Your browser can't play this video. ... Car display screen unresponsive. ... Seafoam-- can't believe what it did to my engine !! Project...
Read more >
How To Fix A Touch Screen Car Stereo - Motorist Care
Step 1: Remove The Car Stereo · Step 2: Dissemble The Car Stereo · Step 3: Detach The Main Wires Of The Screen...
Read more >
How to Reboot Your Car's Infotainment System
Press and hold the Back button, the Nav button, and the Mute button for at least 10 seconds.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found