gertboard accessibility


17 posts
by portets » Mon Dec 19, 2011 2:36 am
first, sorry if this has been answered elsewhere. i\'ve looked everywhere i can think of and it seems like it should\'ve been asked already.

what language(s) will gertboard be accessible through?

i\'m really hoping it could be through python, due to simplicity and that the pi is being designed with python in mind. and also that my grandpa is a hobbyist robot builder and is very set in BASIC, so i think python would be easiest for him to move up to. r-pi plus a gertboard with python would be great for him.
Posts: 185
Joined: Sat Oct 29, 2011 6:24 am
by sylvan » Mon Dec 19, 2011 3:45 am
[quote][b]Quote from portets on December 19, 2011, 02:36[/b]
what language(s) will gertboard be accessible through?

i\'m really hoping it could be through python, due to simplicity...[/quote]

With near certainty it will be accessible thru \'C\'.

If it is accessible thru \'C\', it is a small task to create a library.

If a \'C\' library exists, it is a small task to create a python wrapper. (I prefer \'ctypes\' for most purposes. Much easier than SWIG.)

And all that might not be necessary, because likely it will be accessible using the fake files in /dev (or /sys or /proc) and python can play with files all day long.
Posts: 115
Joined: Sun Nov 27, 2011 8:39 pm
by abishur » Mon Dec 19, 2011 4:10 am
My understanding is that the gertboard will just be some interface options attached to the GPIO and... SPI? I might be wrong on the second one, but the point is you should be able to use any programming language you please to access these devices in theory. As Sylvan says C is most definitely a safe bet. From what we\'ve been told the GPIO will be accessible via the built in linux drivers which I would *guess* is written in C. But again, as sylvan said, you should be able to access it via a wrapper for python or whatever language you choose. Alternatively, you should be able to write your own interface options by writing a program in your language of choice to output high/low values to the GPIOs as opposed to using the built in drivers.
Dear forum: Play nice ;-)
User avatar
Forum Moderator
Forum Moderator
Posts: 4279
Joined: Thu Jul 28, 2011 4:10 am
Location: USA
by Gert van Loo » Mon Dec 19, 2011 12:37 pm
Linux does NOT allow user code to access hardware addresses directly. I am not too familiar with details but you need to \'map\' the real hardware addresses somewhere into your user space, from then on you can access the registers. This is normally done inside the drivers. Basically: you need Linux drivers to access the hardware.
Our SW guru has made a [i][b]temporary [/b][/i]solution where you can access the GPIO through file access. (open file, write file, read file). It may be a bit slow but the nice thing about that is that it should work in any language which supports files.
User avatar
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2054
Joined: Tue Aug 02, 2011 7:27 am
by abishur » Mon Dec 19, 2011 3:08 pm
Good to know, thanks for the correction Gert! :D
Dear forum: Play nice ;-)
User avatar
Forum Moderator
Forum Moderator
Posts: 4279
Joined: Thu Jul 28, 2011 4:10 am
Location: USA
by sylvan » Mon Dec 19, 2011 5:02 pm
[quote][b]Quote from Gert van Loo on December 19, 2011, 12:37[/b]
Linux does NOT allow user code to access hardware addresses directly. I am not too familiar with details but you need to \'map\' the real hardware addresses somewhere into your user space, from then on you can access the registers. This is normally done inside the drivers. Basically: you need Linux drivers to access the hardware.[/quote]

Yes, that\'s all true. However unless something is special about the R-Pi, a suitably privileged (running as \'root\') user space process can typically do that mapping (e.g. mmap() on /dev/mem, or ioperm(), etc.). The only thing that really doesn\'t work well this way is if you need to write an interrupt handler. For more details, see http://tldp.org/LDP/khg/HyperNews/get/devices/fake.html

[quote]
Our SW guru has made a [i][b]temporary [/b][/i]solution where you can access the GPIO through file access. (open file, write file, read file). It may be a bit slow but the nice thing about that is that it should work in any language which supports files.[/quote]

cool.
Posts: 115
Joined: Sun Nov 27, 2011 8:39 pm
by dom » Mon Dec 19, 2011 11:04 pm
[quote][b]Quote from Gert van Loo on December 19, 2011, 12:37[/b]
Our SW guru has made a [i][b]temporary [/b][/i]solution where you can access the GPIO through file access. (open file, write file, read file). It may be a bit slow but the nice thing about that is that it should work in any language which supports files.[/quote]

That\'s the standard way that device drivers work under linux. I wouldn\'t call it a temporary solution. It\'s how all linux GPIO drivers work.
It\'s not particularly slow either. The files in /sys and /proc do not cause accesses to (sdcard) files. Accesses just cause kernel driver functions to be called.
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4030
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge
by smbjwright » Mon Jun 11, 2012 1:20 am
Where can one buy a Gertboard - I did not find them at Newark Electronics.
Posts: 3
Joined: Sat Jun 09, 2012 10:32 am
by gordon@drogon.net » Mon Jun 11, 2012 12:22 pm
Just catching up with some of the posts here - All the "watches" I set on the old forums didn't get carried over (due to some pretty good reasons, I'm sure!)

So in recent weeks, more people have been poking the GPIO, and waiting patiently for the Gerboard. I'm quite excited about it, from looking at the photos, reading and so on.. Meanwile, I've done lots of fiddling with the Pi and its GPIO, trying not to break it (too much!) - e.g. here is an SHT15 temperature/humidity sensor connected up, dispalying the temperature in binary:

Image

But back to the GPIO - The Pi is the first Linux box I've had which has had GPIO - well, not quite, but it's the first that's had the GPIO stuff in the kernel "proper". I've used embedded Linux boxes where you just poke memory mapped addresses to control hardware, but the designers never put anything in the kernel for it... So when I first saw Gerts code which had (I think) Dom's low-level mmap stuff in it, I poured over it with relish and wrote my own interpretation and produced a C library to play with it and hooked it into my BASIC - I also decided (rightly or wrongly) to mimic the Arduino way of doing things where there is a level of abstraction between the actual hardware pins and the names of the pins in the software. This has allowed people to make different Arduinos over the years, but you know that if your code uses "Pin 11", and you connect a wire into the socket on the board marked Pin 11, that it will work and any arduino-compatable board. You don't need to know that on a Arduino Uno with a 328p processor, pin 11 is Port B, bit 3.

There are 2 down-sides to this approach on the Pi - one is that you need to run your programs as root - and this exposes you to all sorts of issues - not the least being able to crash the hardware and scribble all over memory! But the other is the mapping of program "pins" to the GPIO pins to the physical location on the hardware.

However I'm happy with this for now - and I know a few others are. I also think this might encourage some people who're already in arduino-land to come to the Pi... Or at least give them something familiar to work with initially, and especially now knowing that the Gertboard has an ATmega chip on it - which I'm sure will attract Arduino fans to it too. I've done a lot of stuff (mostly for fun) connecting my Arduinos to my Pi via serial port - looking forward to having it on one nice board for experimentation.

But it's not the Linux/GPIO way I hear you cry!

And you're right, it's not, but hey, this is a Raspberry Pi, it's not a beagle/panda/random animal board, or any other ARM based system and if/when the Pi Rev C/D/E comes along and it has different GPIO pins brought out, then it's not going to be hard to augment the mapping to hopefully keep things sane.

But it's not the Linux/GPIO way I hear you cry! (again)

Yea, OK. So what I'm looking at now is offering it both ways and using both the mmap method (seriously fast), or the /sys/class/gpio/ way (dull, but shrewd) so in my code you'll be able to write to pin 1, or write to GPIO18.

In either case, you'll still need to be root to expose the GPIO pins to userland via writing the right stuff into the /sys/class/gpio/export control file. (Which I think I'll implement as a setuid type program - might well be the easiest way!)

-Gordon
--
Gordons projects: https://projects.drogon.net/
User avatar
Posts: 1530
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
by fulburncams » Mon Jun 11, 2012 1:05 pm
Hi
I have used the wiringPi code from gordon@drogon.net (see earlier posts) and hacked it to enable me to use Java and JNI ( if I can do it anyone can ). I now have boards working with Leds blinking and i2c chips talking. I have built two boards, first was stripboard and second is a PCB as the Gertboard will not do what I need so I needed to design my own.
Cheers
Steve
User avatar
Posts: 70
Joined: Wed Nov 30, 2011 8:29 pm
by animal » Fri Jul 06, 2012 1:50 pm
fulburncams wrote:Hi
I have used the wiringPi code from gordon@drogon.net (see earlier posts) and hacked it to enable me to use Java and JNI ( if I can do it anyone can ). I now have boards working with Leds blinking and i2c chips talking.


@Steve: I'm very interested in your 'hacks', can you tell a bit more about or even link to some code ?
Thanks
Gerd

(not that Gert from the board)
Posts: 10
Joined: Fri Jul 06, 2012 1:46 pm
by fulburncams » Fri Jul 06, 2012 6:36 pm
Hi
Yes sure, I used my own board see www.fulburncams.gb.net. In outline steps were
- download the wiringPi code
- created JNI files etc using netbeans and the javah tools
- created some modified version of wiringPi functions with the JNI naming conventions in C
- compiled and loaded the as libraries ( .so files)
- then called these from a java command line program.
I will write a more detailed page plus attach the code listing on my wordpress blog , which I guess is http://fulburncams.wordpress.com/, but I am writing it now so give me a couple of hours.
Cheers
Steve
User avatar
Posts: 70
Joined: Wed Nov 30, 2011 8:29 pm
by animal » Mon Jul 09, 2012 7:07 am
@Steve: Thanks !
Will follow your blog !

Regards
Gerd
Posts: 10
Joined: Fri Jul 06, 2012 1:46 pm
by gordon@drogon.net » Mon Jul 09, 2012 9:48 am
fulburncams wrote:Hi
Yes sure, I used my own board see http://www.fulburncams.gb.net. In outline steps were
- download the wiringPi code
- created JNI files etc using netbeans and the javah tools
- created some modified version of wiringPi functions with the JNI naming conventions in C
- compiled and loaded the as libraries ( .so files)
- then called these from a java command line program.
I will write a more detailed page plus attach the code listing on my wordpress blog , which I guess is http://fulburncams.wordpress.com/, but I am writing it now so give me a couple of hours.
Cheers
Steve


Hi Steve,

Drop me an email when your blog is live and I'll put a link to it. I'm starting to link to others who're using wiringPi in other projects - so-far have people maintaining Ruby and Python wrappers for it!

-Gordon
--
Gordons projects: https://projects.drogon.net/
User avatar
Posts: 1530
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
by edyb » Wed Jul 11, 2012 3:08 am
Thanks to the help from folks on the forum, TheMagPi and other online links I managed to get the simple GPIO access through Python.

I've posted it on my blog here:

http://doctorbraun.blogspot.com

What I was wondering was how to implement the same thing in C. I am more familiar with C/C++ and Java.

I heard WiringPi can do this. Do I need to install a C/C++ compiler? What would be the equivalent setup code and includes needed do the same thing as my Python script on the blog?

I would like to blog about doing the same thing in C but not sure to start. Thanks!
Posts: 29
Joined: Thu May 24, 2012 3:11 am
by gordon@drogon.net » Wed Jul 11, 2012 7:04 am
edyb wrote:Thanks to the help from folks on the forum, TheMagPi and other online links I managed to get the simple GPIO access through Python.

I've posted it on my blog here:

http://doctorbraun.blogspot.com

What I was wondering was how to implement the same thing in C. I am more familiar with C/C++ and Java.

I heard WiringPi can do this. Do I need to install a C/C++ compiler? What would be the equivalent setup code and includes needed do the same thing as my Python script on the blog?

I would like to blog about doing the same thing in C but not sure to start. Thanks!


Hi,

Your Pi should have a C compler installed as standard, so to install wiringPi, just follow the instructions on the site which are essentially:

Code: Select all
  cd /tmp
  wget http://project-downloads.drogon.net/files/wiringPi.tgz
  tar xfz wiringPi.tgz
  cd wiringPi/wiringPi
  make
  sudo make install

(this bit optional)
  cd ../gpio
  make
  sudo make install


That will install the library which you can use in your own programs and (optionally, but recommended) the command-line 'gpio' program which has handy for testing and to allow exporting of the /sys/class/gpio files so you can subsequently access the GPIO from user programs without using sudo. (type man gpio for details)

A simple 'blink' program:

Code: Select all
#include <wiringPi.h>
main ()
{
  if (wiringPiSetupGpio () != 0)
    return 0 ;
  pinMode (18, OUTPUT) ;
  for (;;)
  {
    digitalWrite (18, HIGH) ;
    delay (500) ;
    digitalWrite (18, LOW) ;
    delay (500) ;
  }
}


compile with:

cc -o blink blink.c -lwiringPi

run with

sudo ./blink

and off you go!

More stuff on: https://projects.drogon.net/raspberry-pi/wiringpi/

-Gordon
--
Gordons projects: https://projects.drogon.net/
User avatar
Posts: 1530
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
by Snipez » Thu Jul 19, 2012 7:10 pm
Arduino meets its prodigy, interesting. That means you can use the dacs on the arduino for all sorts of things. I've never used i2c (shamefully as I own multiple arduinos a pi and an a8 cortex). Post your findings.
Posts: 23
Joined: Mon Jul 09, 2012 3:12 pm