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.









Monday, February 17, 2014

Biasing a Diode Semiconductors

To talk about a semiconductor, we need to talk about a conductor first.
Conductors: such as copper, silver, gold and iron are good materials that allow the flow of electrons through them.
Insulators: such as wood, plastic, rubber and glass are materials that do not allow electrons to flow through them.

Semiconductors such as silicon and germanium are neither good conductor nor good insulators.
A new material that is based on semiconductors is produced by combining two materials in a certain ratio that will have a controllable behavior different than conduct/insulate.

The Diode is the simplest device that makes use of semiconductors and are the base of a very complicated devices such as transistors, Integrated Circuits, Microprocessors.
The idea behind Diodes is that they can control the flow of electrons through them to one direction only.  This is achieved by process called biasing.


There are two types of diode biasing, forward and reverse.  Forward biasing allow the diode in a circuit to conduct and allow electrons to flow in one direction.
However, when the diode is reverse biased it will work as an insulator and prohibit electrons from flowing through it.

Reverse Biasing a Diode, No Current flow

Forward Biasing a Diode, Current Flows in Circuit


The behavior of a diode in a circuit is very similar to a one way valve placed to connect two water pipes.  The valve is a control system that will allow the flow of water through the pipes in one direction only.
This behavior reminds me with the valves in the human hart.  Human heart has four valves that allow the flow of blood ONLY in one direction and never the opposite direction.














References:
http://www.st-andrews.ac.uk/~www_pa/Scots_Guide/info/comp/passive/diode/diode.htm

http://www.allaboutcircuits.com/vol_3/chpt_3/1.html
http://www.chipshow.com/blog/?cat=1
http://www.youtube.com/watch?v=JBtEckh3L9Q

http://www.youtube.com/watch?v=W6QUEq0nUH8

Monday, November 11, 2013

Debian on ODROID-x2

Edit 12/7/2013:
Thanks to mdrjr Mr. Mauro Ribeiro work and help he was able to edit the kernel build and enable the SPI.

So, here are my notes on this work

OFFICIAL Debian Wheezy for X2

www.mdrjr.net/odroid/debian-wheezy

root/odroid
odroid/odroid

network is configured in
/etc/network/interfaces
####################################################
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
#your static IP
address 192.168.1.50
#your gateway IP
gateway 192.168.1.1
dns-domain example.com
dns-nameservers 192.168.11.1
netmask 255.255.255.0
#your network address "family"
network 192.168.1.0
broadcast 192.168.1.255
####################################################

You might need to add:
sudo apt-get install libncurses5-dev

Update Date on ODROID-X2 board
data -s "Dec 16 00:00:00 EST 2013"


I did the following steps:
  1. I created a folder in my root home
  2. got the web and get:
  3. wget --no-check-certificate https://github.com/hardkernel/linux/archive/odroid-3.8.y.zip
  4. 7z x -y odroid-3.8.y.zip
  5. cd odroid-3.8.y
  6. sync                    This will sync your SD card
  7. make mrproper
  8. make odroidx2_defconfig
  9. make menuconfig  >>>  this one needed to install sudo apt-get install libncurses5-dev  
  10. now which one I used? odroidx2_ubuntu_defconfig  odroidx2_defconfig
  11. had to install bc first, apt-get install bc
  12. make -j8
  13. sync
  14. make -j8 modules
  15. make  modules_install
  16. sync
  17. kernelversion=`cat ./include/config/kernel.release`
  18. sudo mkinitramfs -c gzip -o ./initramfs-$kernelversion $kernelversion
  19. mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 -n initramfs -d ./initramfs-$kernelversion ./uInitrd
  20. cp /boot/zImage /boot/zImage.prevc
  21. cp /boot/uInitrd /boot/uInitrd.prev
  22. cp uInitrd /boot
  23. cp arch/arm/boot/zImage /boot
  24. cp .config /boot/config-$kernelversion
  25. cp System.map /boot/System.map-$kernelversion
  26. sync
  27. shutdown -h 0

And it worked, I am running now using my built kernel...

Edit 12/15/2013:
After the last edit to the kernel to enable spidev1.0 I was able to build the kernel and booting to see the /dev/spidev1.0
the problem is the bottom 1/3 of the monitor is not showing that area and only showing garbage!



Reference:

If you need to use your Odroid as a WiFi Hotspot...
http://forum.odroid.com/viewtopic.php?f=52&t=6282


Sunday, September 22, 2013

Read and Write to ttyS0 serial ports in Linux


Two ways to interface to the ttyS0 serial port:

1)  via terminal command line:

echo "ABCDEF" > /dev/ttyS0
cat /dev/ttyS0


To configure the port:
stty -F /dev/ttyS0 speed 9600 cs8
stty -F /dev/ttyS0 speed 9600 cs8 -cstopb -parenb




2) via C Program: minicom
sudo apt-get install minicom
when done use
sudo minicom -s


3) By writing your own app in C++ or C# or any other preferred Programming language:
I will have some sample working programs here soon.

Saturday, September 14, 2013

Installing Eclipse from the website on Ubuntu 13.04

I found these instructions on one of the websites discussions:

If you've downloaded Eclipse from their official website, follow these steps for the installation.
  1. Extract the eclipse.XX.YY.tar.gz using
    tar -zxvf eclipse.XX.YY.tar.gz
    
  2. Become root.
    sudo -i
    
  3. Copy the extracted folder to /opt
    cp -r eclipse.XX.YY /opt
    
  4. Create a desktop file and install it:
    gedit eclipse.desktop
    
    and copy the following to the eclipse.desktop file.
    [Desktop Entry]
    Name=Eclipse 
    Type=Application
    Exec=eclipse
    Terminal=false
    Icon=eclipse
    Comment=Integrated Development Environment
    NoDisplay=false
    Categories=Development;IDE;
    Name[en]=Eclipse
    
    then execute the following command to automatically install it in the unity:
    desktop-file-install eclipse.desktop
    
  5. Create a symlink in /usr/local/bin using
    cd /usr/local/bin
    ln -s /opt/eclipse/eclipse
    
  6. For eclipse icon to be displayed in dash, eclipse icon can be added as
    cp /opt/eclipse/icon.xpm /usr/share/pixmaps/eclipse.xpm
Notice:
I found out that I need to install Java RTE or JDK from Java.com

I wanted to make sure I do not lose it again...

reference:
http://askubuntu.com/questions/26632/how-to-install-eclipse
http://www.eclipse.org/downloads/?osType=linux




Beaglebone Black angstrom

Status Update:
This is a list of working Not working items, so you do not get disappointed after reading the post.  This is  a work in progress...

Angstrom:
GPIO
ADC
I2C1
SPI almost, having some issues with CLK, and Data input output.

ArchLinux:
:-(



First Using angstrom distribution:
opkg is the app-get for angstrom....

Linux beaglebone 3.8.11 #1 SMP Wed May 8 07:34:27 CEST 2013 armv7l GNU/Linux

after opkg update, opkg upgrade
Linux beaglebone 3.8.13 #1 SMP Thu Sep 5 16:35:35 CEST 2013 armv7l GNU/Linux


Install Sudo
opkg install sudo

Network settings:
This post here is great source for setting Static IP
http://derekmolloy.ie/set-ip-address-to-be-static-on-the-beaglebone-black/

add user:
su
useradd xyz-user
passwd xyz-user

Update Time and Time Zone:
rm /etc/localtime
ln  /usr/share/zoneinfo/EST /etc/localtime
/usr/bin/ntpdate-sync 
nano default/ntpdate     to set / enable sync server
date             to check your new time


Using GPIO:
#echo 44 > /sys/class/gpio/export

Reference:
http://www.phys-x.org/rbots/index.php?option=com_content&view=article&id=104:lesson-1-beaglebone-black-blink-led&catid=46:beaglebone-black&Itemid=81
http://www.auctoris.co.uk/2012/08/23/gpio-with-sysfs-on-raspberry-pi-part-2/


Using the I2C:
i2cdetect -y -r 1
root@beaglebone:~# i2cdetect -y -r 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- UU UU UU UU -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --   

i2cdump -y 1 0x50 w     or
i2cdump -y 1 0x50 b

Link....
http://minix-i2c.blogspot.com/2013/07/using-i2c-tools-with-angstrom-linux-on.html



Using the SPI:
I found the required files in /lib/firmware/ BB-SPIDEV*
all I did finally, is echo this line

root@beaglebone:/lib/firmware# echo BB-SPIDEV0 >  /sys/devices/bone_capemgr.9/slots

Then ls /dev/spi* and here is what I got...

Now what is next? the question is what is really here that works?



Using Analog Inputs:


sh-4.2# echo cape-bone-iio > /sys/devices/bone_capemgr.*/slots
sh-4.2# find /sys/ -name '*AIN*'
/sys/devices/ocp.2/helper.14/AIN0
/sys/devices/ocp.2/helper.14/AIN1
/sys/devices/ocp.2/helper.14/AIN2
/sys/devices/ocp.2/helper.14/AIN3
/sys/devices/ocp.2/helper.14/AIN4
/sys/devices/ocp.2/helper.14/AIN5
/sys/devices/ocp.2/helper.14/AIN6
/sys/devices/ocp.2/helper.14/AIN7
sh-4.2# cat /sys/devices/ocp.2/helper.14/AIN1
OR  
sh-4.2# cat /sys/devices/ocp.2/helper.14/AIN*



References:
http://www.gigamegablog.com/2012/01/29/beaglebone-linux-101-configuring-angstrom-linux/
http://beaglebone.cameon.net/home/reading-the-analog-inputs-adc
http://www.gigamegablog.com/2012/01/22/beaglebone-coding-101-using-the-serial-and-analog-pins/


BeagleBone Black Updating the Software
Getting Started with BeagleBone Black
============================================================
Now, I am trying arch Linux to see if it works better:

http://archlinuxarm.org/platforms/armv7/ti/beaglebone-black


Steps I used:

  1. pacman -Syu
  2. passwd
  3. pacman -S sudo adduser gcc make
  4. adduser username
  5. EDITOR=nano visudo
  6. copy my files




To Setup eth0 configuration Static:
systemctl disable netctl-ifplugd@eth0
cp /etc/netctl/examples/ethernet-static /etc/netctl/ethernet-static
nano /etc/netctl/ethernet-static #edit to you liking
Use /24 for  255.255.255.0
Use /16 for 255.255.0.0
netctl enable ethernet-static
reboot.







References:
http://hipstercircuits.com/enable-spi-1-0-and-1-1-with-device-tre-overlays-on-beaglebone/




References & Commands:
How to auto mount drive at boot...            /etc/fstab   http://www-rohan.sdsu.edu/doc/debian/ch-disks.html
Debian Tutorial http://www-rohan.sdsu.edu/doc/debian/



Thursday, September 5, 2013

Adding GPIO SPI and I2C options to your Arch Linux Kernel

Edit 12/07/2013:
Thanks to Mr. Mauro Ribeiro, I was able to get the SPI on my ODROID-X2 board and, now I will be working on the actual development of the main project, which is, Controlling the world via SPI bus...
Mr. Mauro Ribeiro modified the kernel on https://github.com/hardkernel/linux/tree/odroid-3.8.y
and now we can build kernels with SPI1 enabled.


First lets put some list of GPIOs I used on this board:
105, 102, 110, 117
GPIO are found @
/sys/class/gpio
and then need to export as root...
#echo "105" > export
# echo "102" > export
# echo "110" > export
# echo "117" > export
# echo "out" >  gpio105/direction
# echo "out" >  gpio102/direction
# echo "out" >  gpio110/direction
# echo "out" >  gpio117/direction


# echo "1" > gpio105/value
# echo "0" > gpio105/value
# echo "1" > gpio102/value
# echo "0" > gpio102/value
# echo "1" > gpio102/value
# echo "1" > gpio105/value
# echo "0" > gpio105/value


To read from GPIO that is set as Input:
# echo "in" >  gpio105/direction
# cat /sys/class/gpio/gpio105/value



So, I had to build my Kernel to be able to enable the SPI "I hope that it is going to work..."
Make sure you have at least large SD drive, I used 8 GB and did not work.  So, 16 GB is recommended...

Edit:
OK, my 8GB SD card was not fully used, I had to use gparted and resize the partition to use the full SD card size.

1. Get the source code from the link below, I had to get linux-odroid-3.8.y.zip as others did not have my odroidx2_ubuntu_defconfig configuration file.
https://github.com/hardkernel/linux

2. Now you will have to unzip the file, so crate a folder in your home directory and save the downloaded zip file to it then use
unzip linux-odroid-3.8.y.zip
I installed 7z by using
pacman -S p7zip
Then
7z x -y zip.file.name
You will also need to get
pacman -S base-devel

Also you will need:
pacman -S gcc  make


3. make sure you work from the new created folder, linux-odroid-3.8.y
cd linux-odroid-3.8.y

zcat /proc/config.gz > .config

for Latest SPI enabled configuration, I used the following
make odroidx2_defconfig

4. Run make oldconfig
4. Now, run make menuconfig,  this will allow you to go and enable other options before you build the new kernel

5. make sure you exit and save changes when you are done,  now you should have a .config file in the current folder

6. To start build Run
make -j8
-j8 will allow the make to run up to 8 simultaneous jobs
This part will take a long time so do not set and wait for it to finish

7. Now, Run,
make -j8 modules
sudo make modules_installmake zImage

8.  Rename the current zImage to zImage.prev and copy the new zImage to /boot

kernelversion=`cat ./include/config/kernel.release`
sudo cp /boot/zImage /boot/zImage.prev
sudo cp /boot/uInitrd /boot/uInitrd.prev
sudo cp arch/arm/boot/zImage /boot
sudo cp .config /boot/config-$kernelversion


I used the steps from this location
http://odroid.us/mediawiki/index.php?title=Kernel_compiling
http://forum.odroid.com/viewtopic.php?f=52&t=81

Make sure your time is set to the correct time:
Time-Date set and check
sudo timedatectl set-time "2013-08-14 14:52:00"
timedatectl status
timedatectl set-timezone America/New_York



Warning: you may need to install module-init-tools

Now, Adding more notes about Device Tree overlay:
Install  sudo pacman -S  dtc-overlay
I need to find out where to find the correct dtc files to compile on the Odroid-x2


New Board found:
http://www.variscite.com/products/system-on-module-som/cortex-a9/dart-4460-cpu-ti-omap-4-omap4460?gclid=CJbkwpP3_roCFdF_Qgod0kMAtw

http://armbedded.eu/node/318


resources:
https://github.com/hardkernel/linux
http://archlinuxarm.org/developers/building-kernels
https://wiki.archlinux.org/index.php/Kernel_Compilation#Compilation
http://odroid.us/mediawiki/index.php?title=Kernel_compiling

This is my link to ODROID Forum question:
http://forum.odroid.com/viewtopic.php?f=17&t=1085

Good Links to building kernel:
http://docs.kali.org/development/custom-odroid-kernel-image
https://wiki.archlinux.org/index.php/Kernels/Compilation/Traditional


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