-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to write/draw to LCD screen? #194
Comments
The All operations are applied to internally help image, which is dumped to the actual LCD when from time import sleep
import ev3dev.auto as ev3
screen = ev3.Screen()
smile = True
while True:
screen.clear()
# Screen.draw returns a PIL.ImageDraw handle
screen.draw.ellipse(( 20, 20, 60, 60))
screen.draw.ellipse((118, 20, 158, 60))
if smile:
screen.draw.arc((20, 80, 158, 100), 0, 180)
else:
screen.draw.arc((20, 80, 158, 100), 180, 360)
smile = not smile
# Update lcd display
screen.update()
sleep(1) |
Your code gives me the following error: Once I've managed to write or draw to the screen, how do I get Brickman back? |
I am still using python2 on ev3 (its the default I think). It looks like division on line 2310 should be changed to integer division ( |
No worries, for I'm just leaving also for a two week vacation. |
When you run your scripts from brickman menu, you should get your own screen. It will switch back to brickman when your script finishes. If you run your script from ssh session, you would get weird results: brickman and your script will both write to the same screen. |
I've never yet run a script from Brickman. I have to modify the file permissions before I can do that, don't I? Will Brickman know that it should use Python3? |
@dlech has spoken! To run an application that writes to the display via SSH:
It seems a bit complicated, but it's reasonably easy. If you don't mind a little blinking cursor showing up on top of your program, I believe you can skip steps 2 and 4. This also means that the console isn't small, because instead of using the one on the tiny EV3 display, you are using a normal one and just displaying your code's shapes on the display. As for running it with Brickman, I believe you just need to do two things (once per Python program).
|
You have to press ESC 3 times to exit |
Fixed. |
This change has already been made, however @ndward is using version 0.6.0, which doesn't support Python 3 in full. See #195 (comment). |
It's common to run, via SSH, Python scripts that can only be terminated with Ctrl+C. What is the equivalent trick to stop the same scripts if they are launched from within Brickman? |
You can long press back button to end any program that was started with brickman. Another useful shortcut is back+enter to reset the brick. |
I followed the instructions above to make a script executable from Brickman: And it worked for this script
but not for this one (I used chmod as suggested)
The same script works fine via SSH. How come the line |
When the first line starts with a
Make sure the file has unix line-endings. When you forget to convert from Windows format, bash thinks that an extra |
If you run the program vis SSH using |
WasabiFan says to use |
'Make sure the file has unix line-endings.' This is of course easier said than done! Especially since I'm targeting Python beginners who use Windows. Can I assume that this unix line ending issue is only an issue for shebangs and shouldn't be an issue elsewhere? Your shebangs are my shenanigans! |
It is safe to assume that Windows line endings will cause all sorts of problems on Linux. IMHO, it would be best to make beginners aware of this from the very start and point out how to save files with unix line endings in whatever text editor you are using so that they just get in the habit of always using unix line endings. You will never be able to launch a program from the brick without a working shebang, so it's best to just get it right from the start. |
Have you ever tried to open a file on Windows and gotten the "Open with..." dialog asking you to choose a program? This is the equivalent, but for Linux. Instead of teaching the operating system to assume that So, if you run your code as
Yes, as I understand it the first will invoke Python 3 while the second will run Python 2. As for the line endings issue, yes, you will need to use the UNIX-style line endings. Your editor probably has a button for that, so it shouldn't be an issue. |
We just had a power outage so my computer restarted and now the shebang seems to work fine even where it did not before. I've been using MobaXterm's internal text editor recently and I notice it is set to Unix format by default so I should never have had any problems with code typed there. Maybe a problem was caused by me pasting some code there that was copied from somewhere else? I'm not expecting this to be an issue, then, for Windows people who use MobaXterm or a Python IDE. When someone tries to open within Brickman a Python script that is not executable maybe it would be helpful for Brickman to offer to make the file executable instead of just giving an error message? |
"When someone tries to open within Brickman a Python script that is not executable maybe it would be helpful for Brickman to offer to make the file executable instead of just giving an error message?" If it ended in ".py" it could also auto-add the shebang if needed. @ndward I am going to mark this one as closed since this isn't really an issue with the python library and 737 is open to track the Brickman side of things. |
This issue is closed but I'd like to reopen it but I don't see how to do that. Or should I start a new issue? For a long time I was unable to print or draw to the EV3 screen – I suppose I was using a too-old (cycle 9) version of the Ev3dev kernel or it had become corrupted or it had not upgraded properly. Since I flashed a recent nightly image I can draw and write to the screen and I've put some working sample code on https://sites.google.com/site/ev3python/learn_ev3_python/screen . I can draw simple shapes and print tiny text using 'text', but I still have some questions: |
I don't have easy answers for these, because I don't have much experience with pillow library either. But after reading their reference documentation, I've managed to do this: http://nbviewer.jupyter.org/gist/anonymous/a268bf8000d7be7f0f49c67c859f1070 Although I am not sure if the fonts will be available on the EV3. |
Thanks. I ran this
and got the following error: If I could just get multiline_text going that would be a step forwards.. |
from ev3dev.ev3 import * # Do I need this?**
from PIL import Image, ImageDraw, ImageFont, ImageOps You need both of these lines, but you can omit im = Image.new("1", (178, 124), "white") This is not necessary. In the example above I just created an image inside ipython notebook to use it as a test of pillow functionality. When you do this on the EV3 you need to replace the line with screen = Screen() and then replace
This is what I was afraid of when I said that font file may be unavailable. You can try to search for any ttf files on ev3 (from bash commandline) with find /usr/share -iname '*.ttf' May be @dlech knows if there a way to install some font files onto ev3? |
I guess pillow does some simplistic math to compute where to put the text, and |
Bitmap the pillow documentation refers to is not a bmp image, its a bitmask (where each pixel is a single bit). To load a bmp, simply use the example I provided, and replace |
Nah, I am afraid we've spilled the beans already; its out in the open now. Even if we delete our comments, github has already spammed the 18 people watching the repo with the know-how. |
It seems # Paste an image:
logo = Image.open('ev3dev_logo.png')
screen.draw.bitmap((130, 10), logo) EDIT: here is a more complete example: http://nbviewer.jupyter.org/gist/anonymous/bb174089699ae66443f5a212c5e37b66 |
Is there an easy way to do screen captures on the EV3? PS Denis, your English is really good. I see 4 possible explanations: PPS While working on EV3basic.com I exchanged emails with Андрей Степанов who could be an interesting contact for you (mailsea@yandex.ru). See http://karandashsamodelkin.blogspot.fr/ |
Here is an excerpt from irc log I found:
Its E) I've spent time in NL :). |
@ndward For taking screenshots, I actually have a Python script that I use for taking screenshots for documentation. It runs That script is here. |
Denis, dus spreek je ook mischien een beetje Nederlands? Ik ook, omdat ik was in Brussel van 2005 tot 2014. Brilliant. After an hour of trials I was finally able to display an image. First I put into a folder 'pics' within my 'robot' folder all 107 official Lego EV3 BMPs. These BMPs are monochrome, correctly dimensioned for the EV3 screen. The following script worked fine to display a BMP file 'Bomb.bmp':
What is the function of convert("L")? The three lines with comments all display the image but the middle one displays it in inverse colors. Therefore it seems to me the best option is the first. Do you agree? (Similarly, I moved the folder containing the fonts into my robot folder so that I can easily find them and back them up next time I need to reflash my card, and to make the path much simpler. There is no reason NOT to move the font folder in this way, is there?) |
That converts image to a different 'mode'. Modes are described here: http://pillow.readthedocs.io/en/3.3.x/handbook/concepts.html#modes. The image that is stored internally in Screen class uses "1" mode, so I would try that instead of "L".
Will
Not sure. But I guess those images are copyrighted by Lego, so I would take care. Also, I imagine that drawing an image file in paint and then putting it into robot screen would be even more fun for a kid :).
Move or copy? Are you talking about |
Yeah, those errors make sense; glad to see it works overall though! |
I thought I had the LCD nailed but I have a small problem. This script runs forever and if I start the script from Brickman I can't exit it properly with a long-press on the Back button ( the brick just starts toggling back and forth between Brickman and the graphic display). I have to a long press on Back and Enter to restart the brick.
|
Do you agree that the simplest way to do a screen capture is to run this at the command line? |
Yes. That's actually what my Python script does; it just goes a step further in recoloring and scaling it.
I'm not sure what's going on there, but I was able to repro it. I know that Brickman sends SIGTERM with |
My bad, should be |
Yes, when I changed #!/usr/bin/env python3
from ev3dev.ev3 import *
from time import sleep
from PIL import Image, ImageDraw, ImageFont, ImageOps
lcd = Screen()
logo = Image.open('pics/Bomb.bmp')
lcd.image.paste(logo, (0,0))
lcd.update()
sleep(6) # when running from Brickman, need time to admire image In fact the line |
I guess a good habit is to just import what is necessary. Here you only use |
... and you said in an earlier message that "you can omit Image from PIL imports. That is already imported by ev3dev.ev3." so the whole PIL import line can go, leaving
|
That accidentally works when you do Here Baseline: I would still import |
Is it possible to use
|
The following example works for me (from brickman): #!/usr/bin/env python3
import time
for i in range(30):
print('#' * 30)
time.sleep(5) Keep in mind that the default font is tiny and its possible to overlook small amount of text. |
Yes, that works fine, thank you, and so does the script that was failing for me previously - I don't know what was wrong. |
Ok, it looks like this may be closed now. Feel free to reopen if necessary. |
How do I input some coordinate values into the lego ev3 brick so that the robot and return to the x, y position that was provided as an input to it |
Me again, the webmaster of ev3python.com where I try to make it easier for beginners to make a start with ev3dev and ev3 Python.
I haven't been able to write text or graphics to the EV3 LCD screen using EV3 Python except by running the ridiculously complex code on http://www.ev3dev.org/docs/tutorials/using-ev3-lcd/ Thirty lines of code just to draw two lines and a circle?! There has to be a better way. And how do I display test, or an image file. Please help!
The text was updated successfully, but these errors were encountered: