Showing posts with label GPIO. Show all posts
Showing posts with label GPIO. Show all posts

Saturday, May 9, 2015

Raspberry Pi How to


Here is my work summery on the Raspberry Pi.  As I start working on it and put it all together, this efforts are made to collect all the information I need, it is wise to save all my work notes.

So, first of all you should have the following items on your desk to start working on the Raspberry Pi:
I like this image from Element 14 Community.






I am done writing all the drivers and some apps that use I2C, SPI, GPIO, and other resources on the board. so, I will be updating this page soon.

Setting up the RaspberryPi:
to start here is the ID and password for the default user
ID: pi
Password: raspberry




GPIO:
There are at least two options to work with GPIOs. One is mapping a pointer to the GPIO registers and using that to manipulate IOs. Two is to use file system by opening the proper file and manipulating that.

Note:
There is a change on Raspberry pi 2 that affected the addressing of GPIO address, originally the following mapping was used on the Raspberry pi
#define BCM2708_PERI_BASE        0x20000000   
#define GPIO_BASE                (BCM2708_PERI_BASE + 0x200000)  
/* GPIO controller */

the following change will be used to map to the new Raspberry pi 2
#define BCM2708_PERI_BASE        0x3F000000  
#define GPIO_BASE                (BCM2708_PERI_BASE + 0x200000) 
/* GPIO controller */


I2C:

Will need to install:
sudo apt-get install libi2c-dev
sudo apt-get install i2c-tools

Then you will be able to run:
sudo i2cdetect -y 1
i2cget
i2cset

Now, How to read/write to I2C:




SPI:
Great news, SPI is functioning now, I am working on learning more about the process and customizing the code to work with my need as a general SPI master that can communicate with different SPI resources.


Read and Write files on micro SD Card
You can read/write files on the SD card or on a mounted USB Flash drive.
to do, you need to know first the mount point for this device.



Sound:



How to sync time with NTP server on login:
We need to edit the NTP time server list.
well, the command is
ntpdate ntp_server_address
but, I found out on the Rasspberry pi I get this message
the NTP socket is in use, exiting
So, I need to do this
sudo service ntp stop
sudo ntpdate ntp_server_address
sudo service ntp start
and now it works just fine....
You can test to see if ntpd is running,
ntpd -p
Also, need to select your proper time zone:
need to remove the timezone file first
rm localtime
now link to the correct file for your time zone
cd /etc
ln -s /usr/share/zoneinfo/US/Eastern localtime
Now when you sync it will show the correct time for your zone.


Start App automatically on boot:

to be able to run a script automatically after login, we need to edit the following file
sudo nano /etc/profile
then add the executable at the end of this file such as the commands needed to automatically execute ntp sync at login
sudo service ntp stop
sudo ntpdate ntp_server_address
sudo service ntp start

There is also cron:
cron is a software utility that is time based to run scripts in a Linux like environment.
crontab is cron table that contains all these scripts
a link is provided to read more about cron on Wikipedia web site, very good information


Bluetooth management:
Some more details to be added here once I am finished with it...



Links to resources:



http://askubuntu.com/questions/244526/unable-to-synchronize-time-using-ntp

http://www.opentechguides.com/how-to/article/raspberry-pi/5/raspberry-pi-auto-start.html

http://en.wikipedia.org/wiki/Cron

How to configure your Raspberry pi WiFi and Bluetooth

Monday, May 20, 2013

Interfacing to the PandaBoard GPIO, SPI, etc...


Here is my experience/adventure with PandaBoard trying to use its SPI, GPIO interfaces.
This is a work in progress so, I am documenting as I progress.

GPIO are found @
/sys/class/gpio
and then need to export as root...
#echo "50" > export
# echo "39" > export
# echo "38" > export
# echo "37" > export
# echo "out" >  gpio51/direction
# echo "out" >  gpio50/direction
# echo "out" >  gpio39/direction
# echo "out" >  gpio38/direction
# echo "out" >  gpio37/direction

# echo "1" > gpio38/value
# echo "0" > gpio38/value
# echo "1" > gpio38/value
# echo "0" > gpio38/value
# echo "1" > gpio38/value
# echo "1" > gpio37/value
# echo "0" > gpio37/value


To read from GPIO that is set as Input:
# cat /sys/class/gpio/gpio34/value

I will need to use 
chmod 666 /sys/class/gpio/gpio38/value
OR
Change the rc.local  

Now, How do I do this from C program:
This file will show in details how to do all the above from C program.
Note: You will have to run this program using sudo ./Test_IO_1 until I find how to create the GPIO on boot and make it accessible to all users
Makefile
Test_IO_1.c
I included the Makefile so you can compile the C program.  I compiled the code natively, which is on the Pandaboard itself.

  1. Make a folder, Test_IO_1
  2. Copy these two files to the new folder
  3. run make
  4. you should have Test_IO_1.0 and Test_IO_1
  5. type sudo ./Test_IO_1
  6. monitor GPIO38 with a scope, multimeter or a LED

Use this image or PandaBoard datasheet to find the correct pin for GPIO38

Open a file-socket to read or write from /sys/class/gpio/gpio38/value

To Read:
rewind(fp);
fread(&read_value, sizeof(char), 1, fp);

To Write:
rewind(fp);
fwrite(&set_value, sizeof(char), 1, fp);



OK, How to modify device read/write permission on boot:
I found this tile /etc/mtab
is this the one?


Also, I found SPI stuff @
/sys/class/spi_master
There is spi1, spi2, spi3, spi4







References:
http://lxr.free-electrons.com/source/Documentation/gpio.txt
http://www.haifux.org/lectures/258/gpio_spi_i2c_userspace.pdf


https://www.kernel.org/doc/Documentation/spi/spi-summary






http://www.youtube.com/watch?v=fuEB0VCkslQ
http://comments.gmane.org/gmane.comp.embedded.pandaboard/9743
http://lxr.free-electrons.com/source/drivers/input/keyboard/gpio_keys.c


http://lxr.free-electrons.com/source/arch/arm/mach-u300/spi.c?v=2.6.34
http://elinux.org/BeagleBoard/SPI

http://www.egr.msu.edu/classes/ece480/capstone/fall12/group02/documents/Mark-Birdsall_App-Note.pdf