Ever want your Raspberry pi project to have a script that interfaces with I2C to start automatically after a power cycle? Would you like the vnc session to start at power up as well?
This instructable will show how to make a perl script that interfaces with the I2C ports to autostart along with an VNC server so you can log in after every power cycle or use the PERL script without any manual commands. There are several ways to do this, the goal for this method was to do so without opening up the permissions on the I2C ports for everyone. This will help prevent accidental writes to the ports by scripts from other owners.
Step 1: Check your version of the operating system for compatiblity
Check your operating system version, this example is for the Debian, Weezy version. If you have this version you can verify by typing cat /etc/os-release as shown in the photo above. This may work for other versions as well, but hasnât been tested.
Make sure your device is configured to start with a desktop for the user, the default user is âpiâ. That is the assumption for the instruction.
Step 2: Check the permissions on the IO ports
Check the permissions on the I2C ports. The ports need to be set up as shown in the photo above. To check the permissions cd to /dev. Type ls -l | grep I2C. The permissions need to be set as shown in the photo. Change the permissions with chmod if they are not correct. There is a lot of literature on the net for chmod if you have not used this command before. We keep the restrictions as tight as possible as the part or you system can possibly be damage by incorrect I2C.
Step 3: Set up the VNC server
Install your vnc server, follow one the many instructions on the web. This will place a .vnc folder in your home directory. Modify your xstartup file in the .vnc folder to make the session look the way you want. Also start the vnc session a first time while you are logged in, as the first time it will ask you to set the password. To do this type âvncserverâ when you are in your home directory. The password for the vnc session doesnât have to match the login for the user. If you fail to do this password step you will not be able to log in after the first power up. If you have completed this step there will be a passwd file in the .vnc folder in your home directory. Make sure to write down the password somewhere so you can get in later.
If for some reason you forget the password you can delete the passwd file in the .vnc directory and restart the vnc session it will ask you for a new password.
Step 4: Now for the fun autostart part
For this project we will use the autostart folder for both the vnc session and later to start the Perl script that will access the I2C ports. Autostart scripts in this folder will be executed at power up. To find this folder type âcd ~/.config/autostartâ
For more detail:Â Raspberry PI auto-boot