Showing posts with label C programming. Show all posts
Showing posts with label C programming. 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

Thursday, August 21, 2014

Writing C code on Windows using Geany and GNU

I have to provide a simple instruction to install an IDE "Integrated Development Environment" for  my students to be able to work on the assignments on their computers.
After doing a lot of research I found two options, Monodevelop and Geany. They both work great on Ubuntu Linux and have no issues, but, to use them on Windows I started to deal with the unknown...

Working with Monodevelop: monodevelop
Monodevelop will install fine in windows under different name, the issue is it does not support C programming language. At least out of the box. However, I read some blogs stating that we can somehow get it to compile C...  So, this is not what I am looking for and I can not expect my students to waste their time with these hacks at this time.  NOT AN OPTION.
Note:
it works fine on Ubuntu Linux and Mac, so, you can use it fine if this is what you have for Personal Computer...


Working with Geany:  Geany
Geany is a great simple IDE that works on Ubuntu Linux and Windows, as well as Mac.  but it requires the GCC, GNU C Compiler which will need to be installed on Windows.
I came up with the following instructions to help simplify the process of doing that.

Here is a list of download links that will be needed:

  1. Geany download site  Please select"geany-1.24_setup.exe - Full Installer including GTK 2.16."
  2. MinGW "Minimalist GNU for Windows"  Please select "Looking for the latest version? Download mingw-get-setup.exe (86.5 kB)"
Now that you have all required downloads, run both and install by following the default installations.
You should have the following icons on your desktop now,






Now, we will need to setup and install the gcc compiler to be able to compile your C code programs.





  1. Start MinGW by clicking on MinGW Installer shown on your desktop.
  2. you will get the following screen and notice that your list has no items selected in green boxes like my screen shot
  3. Go a head and select the one I have selected, right click and select "Mark for Installation"


    1. mingw-developer-toolkit
    2. mingw32-base
    3. mingw32-gcc-objc
    4. msys-base
  4. Now go to the menu "Installation" , and click on "Update Catalogue"
  5. after the download of needed files and installing them is done, you now have all you need to work on Geany and write your applications, but we need to add the new MinGW to Windows Path...
  6. You will need to go to Control panel
  7. Select System
  8. On the right list click on Advanced System Settings
  9. Now Click on Environment Variables...
  10. You will get this dialog box
  11. find Path  in the System Variables and double click on it
  12. now click on the Variable Value
  13. make sure you are at the end of the text and add the following text  ";C:\MinGW\bin\"
  14. you will be adding everything inside the double quotes
  15. Now, Click on OK and OK again,
  16. when you start Geany and write your own program at this point everything should be all set to compile your new code.