Just some useful codes and some I have written or installed for my Raspberry Pi.
When the raspberry pi boots without HDMI connected it automatically sets itself up to send video through composite, I wanted to change this as I only use a HDMI monitor so all I had to do was edit the config file.
sudo nano /boot/config.txt
and uncomment the following lines
# uncomment if hdmi display is not detected and composite is being output
hdmi_force_hotplug=1
# uncomment to force a specific HDMI mode (this will force VGA)
hdmi_group=1
hdmi_mode=5
# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
hdmi_drive=2
I changed hdmi_mode=5 to force 1080, you can change the resolution by referring to the documentation at RaspberryPi.org
This code will safely power down your Raspberry Pi using a momentary switch.
Plug the momentary switch into GPIO 7, Pin 26 and GND, Pin 25
Before we get into the code you will need to make sure you have the latest software installed by running the following scripts:
sudo apt-get update
sudo apt-get upgrade
Next you will need to create the shutdown scrypt, first open the editor:
sudo nano shutdown.py
Next paste the shutdown.py scrypt into the file. Press Ctrl + C, Y, and enter to save the scrypt.
Next we want to run the file at start up by running
sudo nano /etc/rc.local
and pasting the following code before 'exit 0'
sudo python /home/pi/shutdown.py &
Press Ctrl + C, Y, and enter to save the scrypt.
Reboot your Pi and everything should work.
sudo shutdown -r now
These codes are written to test a four channel relay with a Raspberry Pi.
- VCC to 5v
- IN1 to GPIO(2)
- IN2 to GPIO(3)
- IN3 to GPIO(4)
- IN4 to GPIO(17)
- GND to GND
You can increase or decrease the speed of each of these programs by changing the following line to the number of seconds you want before each step:
SleepTimeL = *
The first file will count through each of the relays one by one, before turning them off and exiting.
The second file will run through the relays turning them on and off one by one, to exit the program hold 'Ctrl + C'
The last file will turn the relays on and off together, to exit the program hold 'Ctrl + C'
Edit lightdm
sudo nano /etc/lightdm/lightdm.conf
Look for the line starts “xserver-command” and modify as below:
xserver-command=X -s 0 -dpms
Reboot the system.
sudo reboot
Update the code in the link above using:
sudo nano ~/voice-recognizer-raspi/src/action.py
Restart the voice recogniser service:
sudo systemctl restart voice-recognizer.service
To see the pin out of your Raspberry Pi
pinout
By default, if stdout is a console that supports color, ANSI codes will be used to produce color output. Output can be forced to be monochrome:
pinout --monochrome
To manually specify the revision of Pi you want to query, use --revision
. To find the revision code you need you can click here:
pinout -r 000d
To clear the terminal history:
history -c