Showing posts with label video. Show all posts
Showing posts with label video. Show all posts

Monday, January 30, 2017

Controlling screen brightness on pi-topCEED on Raspbian Jessie with guizero app and keyboard shortcut

I backed the pi-topCEED during the crowd funding campaign and have used it a lot since.

pi-topCEED

My kids also use it for homework and general Minecraft playing.
As I like to make things I have a number of microSD which means I regularly use it with Raspbian Jessie.

There are a couple of drawback to using Raspbian on the pi-topCEED.  The pi-topHUB doesn't shutdown the power completely leaving the backlight on and the Raspberry Pi in kind of a suspecd mode. The red LED is still on.  Also, there is no way to control the screen brightness.

Doing the usual Google to see if there was a way around this I came across this GitHub repository that looked like it would do the job.  https://github.com/rricharz/pi-top-install
It includes code to shutdown the pi-topHUB which also completely shuts down power to the display and to the Pi as well as provide a program called 'brightness' to control the screen brightness.

After following the instructions in the README.md I had the pi-topHUB shutting down correctly and if from the terminal I type brightness increase the screen brightness would go up and vice versa brightness decrease did what you'd expect.

All very good, but not very user friendly if you're running the GUI which is where I spend most of my time. 

With that in mind and having recently heard good thing about guizero (https://github.com/lawsie/guizero) which is based on tkinter and is said to make building GUI apps  in Python easier.

It looked to me like a simple app with 2 buttons [Darker] [Brighter] is all I needed so I read up a little on guizero.  Using the App using grid layout example (https://lawsie.github.io/guizero/app/) I soon has a small app that did exactly what I wanted.
Code available on Git Hub (https://github.com/winkleink/pi-top-brightness)

The program itself is quite short. Code below.  This makes 2 buttons.  Button1 and Button2.  When you press them they run the relevant system comment to change the brightness. 


from guizero import *
from subprocess import call

def brighter():
    call(["brightness", "increase"])

    
def darker():
    call(["brightness", "decrease"])
    
    
app = App(title="pi-top", height=50, width=145, layout="grid", bgcolor=None)

button1 = PushButton(app, brighter, text="Brighter", grid=[0,1])
button2 = PushButton(app, darker, text="Darker", grid=[0,0])
app.display()


Here is a video showing it working.


After a quick chmod +x  pi-top-brightness-gui.py the program was executable and so I could run it directly.

Then I added the program to the main menu under the System Tools section.
In the video you can see I have a pi-top icon.  This I took from their Twitter account (https://twitter.com/GetPiTop)  I expect they'll be OK with that as I'm adding even more branding to my pi-topCEED.
I explained in a recent post on backing up Minecraft Worlds how to add a program to the menu (http://www.winkleink.com/2016/07/minecraft-pi-backup-worlds-on-exit.html)

It's great to have a little gui app to change the brightness of the screen and even better to learn a new skill with guizero.

One thing I didn't mention is that when I rebooted the Raspberry Pi the first time after installing the programs the screen brightness was far lower than I wanted it be by default.

To fix this I added a single line cronjob.  Crontab with cronjobs is a way to schedule when programs run automatically with one of the options being to run at boot up. It's a simple way to get something running each time you login. It's the system used by people who lets say want to check their network connection every hour.  Just setup a cronjob to run every hour and it will take care of it for you.   I used this previously to enable the Bluetooth keyboard and trackpad or the NexDock. (http://www.winkleink.com/2016/10/nexdock-thoughts.html)

So, I used crontab to set the brightness of the screen to 8 on startup.

In the terminal type:

crontab -e

If this is your first time it asks which editor you want to use.  I do [2] for nano.
Then the crontab file is opened where you put the jobs you want to run.
There are some comments in the file to help you get started, but if you want to do serious scheduled jobs then it's worth 

Go to the bottom of the file and type

@reboot brightness 8

Then the usual nano [CTRL]-[x] to save and close.  Answering [y] to save the file with the same name

Now when I start up the pi-topCEED the default brightness is '8' which suits me.


Finally, finally, the rricharz GitHub explains how to set the keyboard shortcuts for the pi-top laptop so the brightness keys work.  All good if I had a pi-top laptop, but I have a pi-topCEED where it's bring your own keyboard and the one I'm using doesn't have any fancy keys.
So, I looked up how to add keyboard shortcuts.  Again, it ends out to be not too hard.  Just added a couple of entries into a config file.

First thing I had to do is decide what key combination I wanted to use. I settled on:
[Shift]-[Windows Key]-[Up Arrow] for brighter
[Shift]-[Windows Key]-[Down Arrow] for darker

To do this you need to edit the lxde-pi-rc.xml file.
The file is a in a hidden folder in your home folder. If using the default user pi then the following command will open it 

nano /home/pi/.config/openbox/lxde-pi-rc.xml

As the file is in the home folder it doesn't need sudo to edit it

Then scroll down to the keyboard section and add the following to the end.
Easiest way is in nano find the </keyboard> text using the command [Ctrl]-[w] to do a Where is

Make sure you use spaces for the indent and get the <keybind> to line up with the other <keybind> entries

    <keybind key="S-W-Up">
      <action name="Execute">
        <command>brightness increase</command>
      </action>
    </keybind>
    <keybind key="S-W-Down">
      <action name="Execute">
        <command>brightness decrease</command>
      </action>
    </keybind>

To finish like above use [Ctr]-[x] to save and close.

To test select [shutdown] in the drop down menu and then [logout].
No need to reboot to enable the keyboard shortcuts.
Once you log back in the lxde-pi-rc.xml setting will be re-enabled and the 2 new key bindings will be active giving you the ability to change the brightness of your pi-top/pi-topCEED using [Shift]-[Windows Key]-[Up Arrow] and [Shift]-[Windows key]-[Down Arrow]

This has been a fun little project to improve the use of the pi-topCEED.
I like the work rricharz has done getting the pi-topHUB to turn off completely and to control the brightness as well as Laura Sach has done to make guizero so easy to use.

With the help of other peoples effort I now have the pi-topCEED completely shutdown as well as the Raspberry Pi and the ability to change the screen brightness using either a little gui app or with the keyboard.  Not a bad result for a couple of hours.

If you have any questions let me know in the comments.


Tuesday, February 9, 2016

Raspberry P i 2 OpenGL Experimental support released

The latest version of Raspbian Jessie (2016-02-03) includes a some great software updates that you can read on the blog post.

The one that caught my eye was the inclusion of experimental OpenGL hardware accelerated support.
For gaming and other computer graphics programs this is a big thing and means more games will work well on the Pi2.

At the moment it is still experimental which is why in the video below when showing the OpenGL demo a section at the bottom of the screen is greyed out.  No ide a why (yet) as all works perfectly without OpenGL support enabled.  This is a VGA monitor using an HDMI-VGA adapter where the config works perfectly without OpenGL enabled.

Below is a short video of the glxgears demo. First without OpenGL support and then with.
It's an amazing improvement.
With soft-OpenGL support it's really slow and there is a lot of flashing. With OpenGL enabled it looks great.






Tuesday, October 14, 2014

Raspberry Pi model B+ composite/RCA video/audio adapter

With the release of the Raspberry Pi model B+ the previous arrangement from the A/B of having a 3.5mm stereo audio jack and an RCA for video has been changed to a single 3.5mm jack that includes stereo audio and the composite video.

I kept reading online that the arrangement was the same and the iPod and also the Zune so there are loads of cheap cables and adapters out there that work.

After lots of searching I found a number of cables that looked like they would work, but since they were all cheap no specifications for the wiring were listed.

From the Schematic (http://www.raspberrypi.org/documentation/hardware/raspberrypi/schematics/Raspberry-Pi-B-Plus-V1.2-Schematics.pdf) the arrangement needed from tip to base is.

Tip - Audio Left
Band 1 - Audio Right
Band 2 - Ground
Base - Composite Video

It doesn't really matter if the audio connections are reversed as you could just swap the leads, but getting the ground or the composite in the wrong position means no video would be output and in the case of ground no audio also.

So, I went mad and took the plunge to buy a £2.00 adapter from eBay and see if it works.


Here it is plugged into the Raspberry Pi Model B+


RCA/Composite video adapter for Raspberry Pi B+

It covers the HDMI port which isn't a problem. As, when I'm using composite I'm not using HDMI.

I am delighted to say it works perfectly. The wiring is correct. I plugged it into a television and up popped the display from my RetroPie install. Playing Double Dragon on the big screen.

Double Dragon played over composite with stereo audio
The price was only for the adapter, but I had an RCA cable from my kids Karaoke machine, but if you don't have one handy then this one for £1.99 also from eBay would work.

Meaning for £4.00 all in you  have an adaptor for B+ to connect to composite and analogue audio as well as the required connecting cable.

I like that it is a 2 piece configuration as a composite cable can have other uses.  I spliced one before to work with an Arduino and the TV-out Library.

Gathering more bits.





Thursday, July 3, 2014

Paper Marble Run - something different no electronics

I'm a big fan of encouraging creativity with low cost resources. I previously hacked a £6.00 remote control car to control it from a Raspberry Pi using Scratch and used a low cost eBay robot vehicle deck and wheels with a clone Arduino Pro Mini (all in for <£15.00).

Well some people aren't that into electronics and programming but are still looking for creative solutions.

I came across Marble Runs/Roller Coasters that you can buy and did a search online and found you can make you own from copper wire and also from stiff paper (200gsm). Never one to miss a chance to try something new I looked at the videos and made up templates for the paper marble run sections and began construction


After a fair few iterations and a lot of really small pieces of tape to put the bits together I finally had a set of templates that can be used to make a paper marble run.

This is the first video of the marble run. I really like the funnel and also that the marble comes off the end just below the funnel and because the moment is right it drops into the next channel/track section.


There is a fair bit of work in getting it stable and modifying the length of the straights and the curves so they work.  This is real tinkerer construction as the parts are not perfect and the design is evolving so regularly pieces need to be shortened, or bits added or the angle of the track needs to be modified to make it work.
Great fun going through all of this and learning about the properties of the paper, how strong the tape is and how to keep the marble going.

I then extended the run another bit. I like this view. There is something pleasing to me about the curves on the left section.


Finally I added a bumpy track and also a 'ladder' (no idea if that's it's name but it's the name I use) and more curves. This made the whole think a lot taller and works well. It does kind of unbalance the look and style of the overall marble run, so I think it is less pleasing to the eye than the earlier version.  Feels like when a skyscraper adds a large antenna to the top to officially be taller.

Here's the final video of the current Marble Run.




Overall I'm happy with the results and plan to make more runs.  A nice way to spend an afternoon/evening being creative.