Skip to content

Raspberry Pi Gforth GPIO Library using C function wrappers

License

Notifications You must be signed in to change notification settings

osholt/Rpi_Gforth_GPIO

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

##################################################
This is a modified and extended version of the project published at https://github.com/harrypower/Rpi_Gforth_GPIO
For further library installation or modification help see the readme on the page linked above.

For basic installation instruction scroll down.

If you don't know what Forth is and want to learn more (even if you've never programmed before) see http://home.iae.nl/users/mhx/sf.html or pick up a physical copy of Starting Forth (it's out of print but I got mine very cheaply as an ex-library book).

The file gpio.fs contains all the word defintions which make using the GPIO pins on the Pi quite straight forward to use.
gpio.fs depends upon gpio_lib.fs which is imported automatically (if in the same folder) when gpio.fs is imported.

gpio.fs is well commented and self documenting for the most part; I recomend you have read through it.

Please note that the lookup table for GPIO (found in gpio.fs uses a nonstandard pin map for 0-16. It is summarised in the diagram below.

Raspberry Pi Rev 2 pinout 

gpio.fs #	Pin		__________	Pin		gpio.fs #
		3v3		| P1  P2 |	5v0		
8		GPIO02		| P3  P4 |	5v0
9		GPIO03		| P5  P6 |	GND
10		GPIO04		| P7  P8 |	GPIO14		0
				| P9  P10|	GPIO15		1
11		GPIO17		| P11 P12|	GPIO18		2
12		GPIO27		| P13 P14|
13		GPIO22		| P15 P16|	GPIO23		3
				| P17 P18|	GPIO24		4
14		GPIO10		| P19 P20|
15		GPIO09		| P21 P22|	GPIO25		5
16		GPIO11		| P23 P24|	GPIO08		6
				| P25 P26|	GPIO07		7

Hopefully it's obvious why I chose this non standard mapping. If not it was to allow sequential bit writing on the port starting at pin 2 and ending at pin 26 and for similar reasons on the other side.

If you dislike it you can change it by modifying the GPIO word in gpio.fs but it will break other words by doing so.

##################################################
INSTALLATION

If you do not already have Gforth installed install it using:
	$ sudo apt-get install gforth

You need to compile the C code and library and install it using:
	$ cd c_src
	$ sudo make 
	$ sudo make install
Now the library is installed.

Now go up a directory to whaere gpio_lib.fs and gpio.fs are located and open Gforth:
	$ cd ..
	$ sudo gforth	# note that gpio pins may not work correctly without root privileges.

Inside Gforth (or any file you wish to import into gforth that builds upon the words in gpio.fs) type:
	include gpio.fs

You can move gpio.fs and gpio_lib.fs anywhere as long as they remain in the same folder or you import the files into Gforth yourself.

##################################################
EXTRA

gpio_example.fs contains the original examples given by harrypower which I have built upon.

If 2 4 digit 7 segment bubble displays are connected correctly to the GPIO pins running:
 	$ sudo gforth clock.fs & will make you a nice digital clock to run in the background while you use your pi for other non-gpio related things.

The exact schematic is left as an exercise for the user given the documentation at https://learn.sparkfun.com/tutorials/bubble-display-hookup-guide and the defintion of 7time8 in gpio.fs.

About

Raspberry Pi Gforth GPIO Library using C function wrappers

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 61.5%
  • Forth 28.1%
  • C++ 6.5%
  • Makefile 3.9%