Main Restorations Software Audio/Jukebox/MP3 Everything Else Buy/Sell/Trade
Project Announcements Monitor/Video GroovyMAME Merit/JVL Touchscreen Meet Up Retail Vendors
Driving & Racing Woodworking Software Support Forums Consoles Project Arcade Reviews
Automated Projects Artwork Frontend Support Forums Pinball Forum Discussion Old Boards
Raspberry Pi & Dev Board controls.dat Linux Miscellaneous Arcade Wiki Discussion Old Archives
Lightguns Arcade1Up Try the site in https mode Site News

Unread posts | New Replies | Recent posts | Rules | Chatroom | Wiki | File Repository | RSS | Submit news

  

Author Topic: [SOLVED] Rotate screen by Button  (Read 5960 times)

0 Members and 1 Guest are viewing this topic.

Marcoqwerty

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 123
  • Last login:March 14, 2024, 02:46:08 pm
[SOLVED] Rotate screen by Button
« on: March 16, 2018, 09:15:31 am »
Hi guys

For my new project (vertical mini-cab based on ol ICADE) im looking for a easy but suitable way to switch from vertical to horizontal the monitor screen.

I need this because my project works as vertical (in the ICADE CONFIG) and stand alone like control panel to be connected in a regular widescreen tv.

The smart and amazing way would be buy a LCD mini screen who allow this hardware "flip" feature, but the one i have bought do not have it, and leave the software orientation HORIZONTAL.

Also im looking for a script to connect by button like this (i cosider that a good option):



thank you for any help  :notworthy:
« Last Edit: April 06, 2018, 07:08:12 pm by Marcoqwerty »

DaOld Man

  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 5139
  • Last login:December 13, 2023, 12:03:14 am
  • Wheres my coffee?
    • Skenny's Outpost
Re: Rotate screen by Button
« Reply #1 on: March 16, 2018, 04:45:51 pm »
I guess Im confused as to what you want. Do you want to automatically physically turn the monitor to vertical (monitor on its side) when a vertical game is selected?

Marcoqwerty

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 123
  • Last login:March 14, 2024, 02:46:08 pm
Re: Rotate screen by Button
« Reply #2 on: March 17, 2018, 06:53:15 am »
NO. i would'nt rotate the screen "per game", but always; only when push the button.

Rotate from 90 degrees (both vertical and horizontal game), exacly how it looks in the video.

DaOld Man

  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 5139
  • Last login:December 13, 2023, 12:03:14 am
  • Wheres my coffee?
    • Skenny's Outpost
Re: Rotate screen by Button
« Reply #3 on: March 17, 2018, 10:00:15 am »
To rotate the monitor you will need a mechanism consisting of a motor and some form of linkage between the motor and the center back of the monitor.
The control for this would be fairly simple. You can use a drive to power the motor, or relays.
The "smarts" that control the drive or relays could be a logic circuit, or the RPi itself, if you have the available GPIO.
I suggest you start by searching this entire site for rotating monitor. Many people on here have developed rotating monitors and freely shared their experiences.
You may also want to check out the forum on here called Automated Projects.

Marcoqwerty

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 123
  • Last login:March 14, 2024, 02:46:08 pm
Re: Rotate screen by Button
« Reply #4 on: March 17, 2018, 12:27:19 pm »
NOOOO i would only rotate the screen!!! the image...

but on the fly....with a button!

its only a software stuff...

DaOld Man

  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 5139
  • Last login:December 13, 2023, 12:03:14 am
  • Wheres my coffee?
    • Skenny's Outpost
Re: Rotate screen by Button
« Reply #5 on: March 17, 2018, 01:04:19 pm »
You should be able to do that in the mame.ini file.

### Mame CORE video options ###
norotate                0
ror                     0
rol                     0
autoror                 0
autorol                 0

Change autoror OR autorol to 1 (not both, try one, if it dont work, try the other.)

This would only be on the mame games, Im not sure if you can rotate the emulation station front end. You will have to switch back to horizontal when you go to ES frontend.
« Last Edit: March 17, 2018, 01:06:46 pm by DaOld Man »

Marcoqwerty

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 123
  • Last login:March 14, 2024, 02:46:08 pm
Re: Rotate screen by Button
« Reply #6 on: March 17, 2018, 01:35:14 pm »
Thank you...but i know exacly how rotate mame games trought .ini and trought raspberry config file...

but..

my aim is rotate the screen by button, like make a script who, everytime i press this button, retropie restart himself with  new screen configuration...all automatically.

ElectricBill

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 11
  • Last login:May 15, 2018, 05:04:59 pm
  • I want to build my own arcade controls!
Re: Rotate screen by Button
« Reply #7 on: March 23, 2018, 08:52:13 am »
If you use Attract Mode for EmulationStation I think it can be done with a controller or GPIO button.
I don't use it myself as I don't have a vertical screen (yet), so here's someone else to explain:

"Set up two layouts and a layout change button. Put all the vertical games on one and horizontal on the other. There are plenty of AM themes that are "Horizontal vertical" (as in they're vertically aligned on screen resolutions that are landscape) which means you don't have to change the pis internal orientation. Then just set your emulators to not rotate vertical games.

Downside: If you bring up any menus while in vertical mode, the menus will be flipped."


So, it's just like changing the theme. You press a button and it'll load between the two versions, either horizontal or vertical. You just need to make sure you install games in the right folder   :D

Marcoqwerty

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 123
  • Last login:March 14, 2024, 02:46:08 pm
Re: Rotate screen by Button
« Reply #8 on: March 29, 2018, 04:03:31 am »
Then just set your emulators to not rotate vertical games.


This part is not clear...so... i cant see all the game oriented vertical (i mean the horizontal also) and viceversa?

I can only show the game on their native orientation?

For the front-end there are no problem.

Basically im interested to a script who change the /boot/config.txt

Code: [Select]
display_rotate=1
and reboot...

If i press again it change again the script to

Code: [Select]
display_rotate=0

DaOld Man

  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 5139
  • Last login:December 13, 2023, 12:03:14 am
  • Wheres my coffee?
    • Skenny's Outpost
Re: Rotate screen by Button
« Reply #9 on: March 29, 2018, 10:59:52 am »
You might could do this with a python script that gets called when you press the button. (This is for an RPi, right?)
The button would have to be wired back to the GPIO pins. If the button is now wired to your monitor, you could use a DPST button (Electrically 2 buttons in one)

The script would run on bootup and wait to see the input from your button.
On seeing the input, it would change the config file to read opposite what it currently is, then reboot the RPi.

Am I still out in the weeds on this?

Marcoqwerty

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 123
  • Last login:March 14, 2024, 02:46:08 pm
Re: Rotate screen by Button
« Reply #10 on: March 29, 2018, 11:10:57 am »
PERFECT DaOld Man THIS IS EXACLY WHAT I SHOULD DO!

(yes it is for RPi)

but...im totally noob on the pithon script...

i have found this:

https://raspberrypi.stackexchange.com/questions/37972/configure-monitor-to-allow-rotation/62147#62147

and a pair of GPIO base script to configure GPIO output, but i need a bit of help to put all togheter.

can you point me on a right way? maybe some example (where place the script and how load it at startup)....

and...

can i use a regular button like this?

Thank you for the help i really need this script for my project!  :notworthy:

DaOld Man

  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 5139
  • Last login:December 13, 2023, 12:03:14 am
  • Wheres my coffee?
    • Skenny's Outpost
Re: Rotate screen by Button
« Reply #11 on: March 29, 2018, 11:21:00 am »
That looks like a SPDT button, which is one common with a normally closed contact and a normally open contact.
If your button needs to go to your monitor box, then you will probably need to keep that circuit isolated from the RPi circuit.

Something similar to this:
http://www.bgmicro.com/dpdtmomentarypushbuttonwithblackkeycap.aspx

(That link is to a very small button that is DPDT, which stands for Double Pole Double Throw. A DPST, Double Pole Single Throw, would work too. I am not suggesting that button, just giving an example.)

But, in your first picture, it looks like a toggle switch. Does it need to be a toggle switch instead of a pushbutton?
You will have to go with whatever your monitor is requiring now. Or is that switch tied into the Rpi now?

DaOld Man

  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 5139
  • Last login:December 13, 2023, 12:03:14 am
  • Wheres my coffee?
    • Skenny's Outpost
Re: Rotate screen by Button
« Reply #12 on: March 29, 2018, 11:26:42 am »
I just re-read your first post. (Im starting to come out of the weeds I think).

Is that switch tied to your RPi now? (If it is, you already have what you need electrically).

What GPIO pins did you tie it to?

And what script do you have running now that monitors that input? (You can probably modify that script to do what you want.)

DaOld Man

  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 5139
  • Last login:December 13, 2023, 12:03:14 am
  • Wheres my coffee?
    • Skenny's Outpost
Re: Rotate screen by Button
« Reply #13 on: March 29, 2018, 11:36:32 am »
Or am I way out in the weeds?

The video you posted was someone else setup?
If so that would completely explain my confusion.
I was thinking that video was what you currently have.

 :banghead:

Marcoqwerty

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 123
  • Last login:March 14, 2024, 02:46:08 pm
Re: Rotate screen by Button
« Reply #14 on: March 29, 2018, 11:43:59 am »
I just re-read your first post. (Im starting to come out of the weeds I think).

Is that switch tied to your RPi now? (If it is, you already have what you need electrically).

Actually no...but i know how tie at the raspberry (i praticted myself with tie a "pushbutton for the shoutdown)

Ah sorry for the continuing mistache, already i have a pushbutton with only 2 contacts, like how i attach at this post (i think is not useable for this pourpose)

What GPIO pins did you tie it to?

No worry about this, every pins are welcome (feel fre to take what you like)

And what script do you have running now that monitors that input? (You can probably modify that script to do what you want.)

mmm i have no script on autostart...only the shoutdown script; just load Retropie and the screen is identified automatically.

I use Retropie with Attract mode.


Or am I way out in the weeds?

The video you posted was someone else setup?
If so that would completely explain my confusion.
I was thinking that video was what you currently have.

 :banghead:

 ;D ;D ;D Nooo this video was an example taken from youtube, but it is exacly what i would like to have for my project! (the owner of this video never realease any code or info about his project)



DaOld Man

  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 5139
  • Last login:December 13, 2023, 12:03:14 am
  • Wheres my coffee?
    • Skenny's Outpost
Re: Rotate screen by Button
« Reply #15 on: March 29, 2018, 11:53:26 am »
Well either of those buttons should work.
You will only need one button, unless you want to keep the button you have now to reboot the RPi without rotating the display, if so you will need to add another button. A SPST normally open button should work fine.

Marcoqwerty

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 123
  • Last login:March 14, 2024, 02:46:08 pm
Re: Rotate screen by Button
« Reply #16 on: March 29, 2018, 12:02:27 pm »
Good...

yes i would use two button, one for the shoutdown and the other for change the screen orientation.

DaOld Man

  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 5139
  • Last login:December 13, 2023, 12:03:14 am
  • Wheres my coffee?
    • Skenny's Outpost
Re: Rotate screen by Button
« Reply #17 on: March 29, 2018, 12:07:46 pm »
Here is how I would wire the pushbutton to the RPi.

In the drawing, I use a 500 ohm resistor (can be 100-500 ohms).
This is purely optional, I use it just in case a program sets that pin Im using as an output and turns it on, if that happens pressing the button will put a direct short on that output and possible fry the RPi.
Its strictly for safety reasons and anyone who knows me knows Im OCD about protecting things, LOL

In this drawing I anm using pins 18 and 20 to connect to the pushbutton. Pressing the button shorts pins 18 and 20 together.

Pin 18 is GPIO24, pin 20 is GND (Ground)

Now give me some time to come up with the python script you will need. But if you want you can go ahead and throw that circuit together.

DaOld Man

  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 5139
  • Last login:December 13, 2023, 12:03:14 am
  • Wheres my coffee?
    • Skenny's Outpost
Re: Rotate screen by Button
« Reply #18 on: March 29, 2018, 12:20:20 pm »
You might want to go ahead and make a backup copy of your sdcard.
Since you will be screwing with the config file, if something goes wrong and the RPi refuses to boot up,you may need to re do the sdcard.

If you have windows on another PC you can use win32diskimager to make a backup copy of the sdcard to your PC,
you can then use the win32diskimager to re-write the card and start from where you made the backup, if that is ever needed.

Trust me, if you are new to python and RPi, it pays to have a current backup.
If you use Mac, there are ways to back it up on that to, but I dont have a mac so you will have to google how to do it.

Here is the free download link to win32diskimager:

https://sourceforge.net/projects/win32diskimager/

You will also need a card reader that allows you to connect the sdcard to the PC or mac.

marcoqwerty78

  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 3
  • Last login:March 11, 2024, 07:11:29 am
  • I want to build my own arcade controls!
Rotate screen by Button
« Reply #19 on: March 29, 2018, 01:05:11 pm »
Yes yes go ahead i alredy made my own sd card with all my custom setup...how i told you before im totally noob for the script parts and where put the code, for the other things im fine!  The only thing i do is to understand how to proceed....if i should make two separate configs ( one for the Horizontal and one for Vertical ) or follow another way.

I read a lot and i start to understand how GIPO works and how can read it at the startup ( i follow the shoutdown example ).

Thank you for the tip of the resistor, i didnt set any GIPO before ( only one for the shoutdown button ) so i think all are set as inputs.


Inviato dal mio iPad utilizzando Tapatalk
« Last Edit: March 29, 2018, 01:07:03 pm by marcoqwerty78 »

DaOld Man

  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 5139
  • Last login:December 13, 2023, 12:03:14 am
  • Wheres my coffee?
    • Skenny's Outpost
Re: Rotate screen by Button
« Reply #20 on: March 29, 2018, 03:57:42 pm »
Ive got the script written and it passes my preliminary tests, but before I make it write to the config file, I need to pick up another SD card, install an image on it, then test it for real.
I dont want to take a chance of screwing up the SD card I am currently working with.

Do you know what version of os (raspbian) you have? I will try to download the same version so we are on same page.


Marcoqwerty

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 123
  • Last login:March 14, 2024, 02:46:08 pm
Re: Rotate screen by Button
« Reply #21 on: March 29, 2018, 04:13:37 pm »
I start from this image:

http://forum.attractmode.org/index.php?topic=705.0

and i update all from the last version, installed roms for mame  and all the artwork needed.

If you are interested to a clean version of Attract mode with all configured (no pre-download iso, i usually make all by myself) just tell me, i send to you an SD with my backup...just for say thanks to your aweasome work.  :notworthy:


DaOld Man

  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 5139
  • Last login:December 13, 2023, 12:03:14 am
  • Wheres my coffee?
    • Skenny's Outpost
Re: Rotate screen by Button
« Reply #22 on: March 31, 2018, 12:33:56 pm »
Ok, I think I have a working copy for you.
I downloaded the image you linked to and tested it on that image, and it is working for me.

First, download the attached file rotate_screen.rar and unzip it to rotate_screen.py
Place rotate_screen.py in your /home/pi/ folder on the RPi.

If you are running in startx mode, exit the GUI without rebooting, or to prompt.
You can also use terminal from startx, or remotely using putty
You should now be in terminal mode, or black screen with $ prompt.

Now locate your config.txt file located in /boot/
Type following command then hit enter
cd /boot
you should now be in the boot folder. Type ls and enter to confirm config.txt is listed.

Now make a backup copy of config.txt just in case something happens.
sudo cp config.txt /home/pi/config.bu
This places a copy in the home/pi folder and renames in config.bu.
To recover the file, from home/pi enter sudo cp config.bu /boot/config.txt
Go to /home/pi and use ls (LS) to make sure the file did copy.
now go back to boot folder. cd /boot

Now open up config.txt for editing by
sudo nano config.txt

The screen should fill up with the commands in the config.txt file.
cursor through and see if display_rotate=1 (or 0).
If it is not, at very bottom, on a new line, add display_rotate=0

I added this to my config.txt file:

# position screen based on display_rotate=0 for horizontal
# display_rotate=1 for vertical, top to right (90)
# display_rotate=2 for horizontal, flip (180)
# display=3 or vertical, top to left (270)
display_rotate=0

the lines with # in front are for info only and are ignored, you dont have to put those in if you  dont want to.
Once you are happy with it, hit CTRL and x to exit nano. It will ask you if you want to save, type y and enter.
also if the display_rotate= is already in there, you dont have to do anything, just exit by ctrl + x
Right now, teh script can only handle 0 and 90, let me know if you need 270 and 180 and I can modify the script for that.

Now go back to /home/pi/ by cd /home/pi and enter

I set the script up to use pin 18 for the button, if you are using a different pin, open the rotate_screen.py using sudo nano rotate_screen.py
Find inpin=18 and change the 18 to whatever pin number you are tying the button to.
If you change anything you will need to save when you exit nano.

now test it to make sure it works.
sudo python rotate_screen.py

Press your rotate button and the screen should reboot in the opposite orientation.

If it works, enter sudo python rotate_screen.py to reboot with screen back to where its easier to work with.
If you Pi dont start in the home/pi folder, you will have to go to that folder first.

Now,  if you are happy, lets make rotate_screen.py run automatically on boot up.

Go to /etc folder
cd /etc
use ls to see if rc.local is in the list.
If so we need to edit it by using sudo nano rc.local.
Scroll to very bottom of the file, and right above exit 0
enter this line:
python '/home/pi/rotate_screen.py' &

The & sign lets the script run in the background.

Here is what I have in my rc.local file:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
python '/home/pi/rotate_screen.py' &

exit 0

Yours may be different because your setup is doing a lot more than mine.
Just make sure your new line is above exit 0.

Exit nano and save it.
reboot your pi. (sudo reboot)

See what happens.

Disclaimer: There are no guarantees with using this script.
I highly suggest you make a backup copy of the sdcard before trying this.
If you have a current copy you can always start all over again from where you were before trying this.
Use extreme caution when connecting things to your GPIO header.
Incorrect connections can fry the Pi.
Power Pi down and remove power supply before attaching or removing anything from the GPIO header.
Always double check your wiring before powering back up.
Better safe than sorry.


If you see any bugs or this dont do what you want, let me know, i will try to fix them.
« Last Edit: March 31, 2018, 03:02:59 pm by DaOld Man »

DaOld Man

  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 5139
  • Last login:December 13, 2023, 12:03:14 am
  • Wheres my coffee?
    • Skenny's Outpost
Re: Rotate screen by Button
« Reply #23 on: March 31, 2018, 03:06:17 pm »
Oops! first file I posted was a work in progress, in other words, wrong file. I have uploaded the correct finished one and it should be ok now.
The unzipped file name should be rotate_screen.py. (underscore between screen and rotate).
If you downloaded the first one, delete it and re-download this one.

Sorry about that. The first one would not have harmed anything but it would not work correctly.
If you ran it, look in /home/pi and see if there is a config.txt or config.tmp files, if so you can delete those. (Make sure you are in /home/pi folder before deleting them.)
« Last Edit: March 31, 2018, 03:10:32 pm by DaOld Man »

marcoqwerty78

  • Trade Count: (0)
  • Jr. Member
  • **
  • Offline Offline
  • Posts: 3
  • Last login:March 11, 2024, 07:11:29 am
  • I want to build my own arcade controls!
Re: Rotate screen by Button
« Reply #24 on: March 31, 2018, 05:46:00 pm »
Ehi thank you dude!  Actually im out for work so i cant test your script till next weekend....so you have all the time to check if all its working.
For the moment i say an huge thank you, and cant wait to test it on my system...
Ah im waiting ( if you do not replied yet )some news about the storage question.

Cheers


Inviato dal mio iPad utilizzando Tapatalk

DaOld Man

  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 5139
  • Last login:December 13, 2023, 12:03:14 am
  • Wheres my coffee?
    • Skenny's Outpost
Re: Rotate screen by Button
« Reply #25 on: March 31, 2018, 05:54:40 pm »
Sounds good my friend, about the storage.
I am through testing, I think. Real test will be when you try it out.

Marcoqwerty

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 123
  • Last login:March 14, 2024, 02:46:08 pm
Re: [SOLVED] Rotate screen by Button
« Reply #26 on: April 06, 2018, 07:13:06 pm »
NO WORDS....

IT WORKS PERFECTLY !!!!

 :notworthy: You dude save my life, you cant imagine how i search this feature installed on the monitor, now i can go ahead to my project.  :notworthy:

PS:

Can i share this code and the script to my blog project page? obliviously i give to you all the credits!

http://supercoin.blogspot.it

DaOld Man

  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 5139
  • Last login:December 13, 2023, 12:03:14 am
  • Wheres my coffee?
    • Skenny's Outpost
Re: [SOLVED] Rotate screen by Button
« Reply #27 on: April 06, 2018, 07:51:30 pm »
NO WORDS....

IT WORKS PERFECTLY !!!!

 :notworthy: You dude save my life, you cant imagine how i search this feature installed on the monitor, now i can go ahead to my project.  :notworthy:

PS:

Can i share this code and the script to my blog project page? obliviously i give to you all the credits!

http://supercoin.blogspot.it

Hey! Thats good news! Im glad it worked. Of course you can share it.

DaOld Man

  • Trade Count: (+4)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 5139
  • Last login:December 13, 2023, 12:03:14 am
  • Wheres my coffee?
    • Skenny's Outpost
Re: [SOLVED] Rotate screen by Button
« Reply #28 on: April 06, 2018, 07:53:21 pm »
Your site looks good. Need a translator though LOl.
Why dont you post your project on here? Under Project Announcements.
« Last Edit: July 03, 2018, 07:21:31 am by DaOld Man »