Page 1 of 1

sensors

Posted: Mon Dec 02, 2013 6:48 am
by milkybar_ton
Hi folks,
I've got a Raspberry Pi and have started trying to learn Lisp as i hear it's good with AI. I'm having difficulty finding any info on how to get it to interface with say a temperature sensor. Am i barking up the wrong tree here and would be better following the heard with Python?
I am interested in learning to program for the learning side of it but most of my imagined projects would involve interfacing with 'stuff'
thanks

Re: sensors

Posted: Wed Dec 11, 2013 6:06 pm
by wvxvw
Not knowing what exactly the sensor is, I'd guess it is a combination of hardware and firmware. (I.e. the actual "metal" which does the sensing and some hard-wired program that operates this metal with perhaps some exchangeable parts).
I.e. you'd have:

[metal]
[bios]
[driver]
[kernel-space api]
[user-space api]

layers of abstraction. Where it is possible that user-space API doesn't exist... All of that is most likely written in C. Python has a way to interoperate with C programs, this is usually called "bindings" or "foreign function interface". If this is already available in Python, then it means that some other programmer studied either the driver API or the user-space API and had written a number of wrapper functions, which expose the original C code to the Python environment.

There probably isn't Common Lisp wrapper for the particular driver / user-space library you are talking about (because Raspberry Pi is quite new and it was designed with Python in mind, so it doesn't have much of the other language bindings yet). However, if you are bold! you can look into C code and write wrapper functions in Lisp. You would need to use CFFI library (C Foreign Function Interface). This is something typical to do in Lisp - quite often you find yourself needing a library that is only available in another language... but whether it is worth the effort is really up to you. You might find it to be a bit of extra work, and if your final goal is to program the hardware you are after, rather then to program in specific language, perhaps, writing the wrapper isn't worth the effort. I'd probably go for the wrapper because I'd minimize the effort I spend writing in the language I like, by trading off some time I spend on creating the infrastructure, but you may not have the same incentive ;)

Lisps have been traditionally associated with AI, and there are good reasons to use this family of languages in AI context, but Python, too, had been applied a lot in this area. In some ways these two languages are quite similar. Perhaps, if you are looking for a language that can get you employed, then Python would be the way to go, but Common Lisp is a better language to think, experiment and prototype due to its meta-programming abilities. It is also a larger language as a whole, but has less useful info for beginners, its community is rather small in numbers.

Re: sensors

Posted: Thu Dec 19, 2013 5:23 pm
by bayerf
I'm using Clozure Common Lisp on my Raspberry Pi to control living room lighting.
That is 10m of individually adressable LED strip (this one http://www.adafruit.com/products/306)
via the Raspberry's SPI port, a GPIO pin as main switch and an USB microphone for
capturing speech commands (and for spectrum analysis to control light effects)

The Lisp process is started when booting and starts Hunchentoot web server
to be controlled by a mobile phone browser via WLAN and a swank server for
remote development/debugging from an Ubuntu laptop, so no keyboard/mouse
or display is connected to the Raspberry and I access the Raspberry by ssh.

By using the WiringPi library http://wiringpi.com/ the IO pins can be accessed
as files, e.g. /dev/spidev0.0 to output data to the LED strip via SPI, or
/sys/class/gpio/gpio17/value to read the GPIO pin 17. This library also
allows running your Lisp process as a non-root user.

The project is still in progress, so I can't publish the entire code yet, but once it's
finished, I'll do so. Stay tuned...

Ciao, Fred

Re: sensors

Posted: Tue Jan 07, 2014 10:11 am
by milkybar_ton
Happy New Year one and all.
wvxvw - thanks for the info but it's a bit out of my depth i'm affraid.

bayerf/Fred - thanks this is exactly the type of info i am after. How did you install Clozure on your Pi? i did try a while back following somebody elses lead form their blog but never actually managed to get it working (maybe another case of Walk before you can run;)) Do you have a blog or website that you update at all?

anyway thanks for the replys
milky

Re: sensors

Posted: Mon Jan 27, 2014 10:18 am
by bayerf
Hi milky,

hm, I didn't do anything special besides the steps described in
http://lispm.dyndns.org/ccl
Of course I needed more Lisp libraries later in the project, but
downloading and installing them with quicklisp is straight forward.

Can you state your exact problem with installing CCL?

Sorry, no current blog.

Ciao, Fred

Re: sensors

Posted: Thu Jan 01, 2015 9:53 am
by prabuvenkat
Hi Fred/Milky,

any updates on this one ? I am keen to access GPIO (on my RPi) from CCL myself. Any help is appreciated!

@Fred: how did you get CCL to talk to WiringPi ?

do let me know, thanx!