Recent

Author Topic: Feasibility? Raspberry Pi with PiFace and Lazarus as a controler  (Read 17308 times)

Blacksmith

  • Newbie
  • Posts: 3
Hi

I'm a newbie to this type of hardware and programming (but I do have deep knowledge in programming in general). So before I invest money into hardware and time into software please allow me this questions:

I want to realize a controller that will switch a valve on and off several times an hour.
The software will need to download a page from the web and analyze it. If certain condtions are met, a command needs to be sent to the PiFace (relay) to activate for a certain time. This will trigger a flow of water, that needs to be stopped under all conditions after 30-90 seconds. This system should run unattended.

I know how to program in Modula-2/Pascal, any dialect of Basic, PHP or C or C# if I really need to :-). I wan to avoid Assembly and other prorgamming languages...
My desktop PC is Win7-x64 with plenty of power, my tablet a Samsung 10.1 with Android 3.2 (about to upgrade to 4.x).

Questions
- does a library/samples exist how to download and store http-pages?
- are there timers (soft- or hardware) that can be handled by Lazarus/FreePascal?
- is there the possibility to trigger some kind of an 'is-the-Raspberry-still-alive' and to restart it in case it hangs?
- any other points I could stumle over?
- did I select a clever hard/software. Or do you know maybe much better much better solutions (hardware price, hardware power consumption, hardware versatility for future projects).


Outlook
My next project in this area will be a controller for my weekend-house. I just mention this for completness. It would be nice if I would not need restart from scratch and could maybe use hardware from the same family. It will need to have:
- a display and trigger buttons OR a touch display
- needs to measrue temperature and humidity
- control a fan, heating and 220V mains
- remote override

picstart

  • Full Member
  • ***
  • Posts: 236
Re: Feasibility? Raspberry Pi with PiFace and Lazarus as a controler
« Reply #1 on: August 09, 2013, 02:46:14 pm »
Well,
Lazarus will work on the pi but it mostly  only works with a specific version of Lazarus unless you want to waste days working through an obtuse set of instructions to recompile a later Lazarus version from sources.
 Lazarus needs a helper to talk to hardware,  for the pi there is wiring pi that gives access to the GPIO pins. Often this access is only granted when running in root mode.
 Lazarus is often only used for certain desk top environments. Sure it touts portability but it is never without pain. Portability to  Android is extremely obtuse and often unsuccessful. Windows mobile is better but between a Unix desktop and a Windows desktop Lazarus works and is feature rich for development.
 Lazarus will probably live out its days in the desktop world.
For real world control the field has been taken by dedicated MCU's Microchip Atmel ST etc. Rasp pi makes an attempt to bridge the gap with its GPIO port.
Sure, Desktops have ports ..LP RS232 USB but they were designed to get data in and out from other desktops or attached printers and not control water valves etc.
 To do things like control a water valve in a dedicated fashion you spend too much time defeating the security that desktops need for their interconnected neighborhood.
Rasp pi has this too.  Before a led attached to a GPIO pin flashes much of linux's protective code has to be tunneled under. With a dedicated PIC or Atmel MCU a few lines of code and your led flashes. MCU's  have TCPIP stacks USB etc interfaces.

Lazarus does work on the pi and will flash a LED but is really excels as a miniature desktop tasked to run  XBMC entertainment center, server ,wifi etc.
I'd suggest Python for the pi rather than Lazarus since Lazarus is mostly for desktop solutions.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Feasibility? Raspberry Pi with PiFace and Lazarus as a controler
« Reply #2 on: August 09, 2013, 03:01:13 pm »
@picstart:
I don't agree Lazarus is mostly for desktop solutions: you can write perfectly fine FPC daemons/web applications/console mode programs.

I don't really see the difference with Pyton except FPC is compiled, not interpreted and Python may have different (probably better) available libraries because it's a more common platform on the Pi.

No opinion about the rest of your post...

Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Blacksmith

  • Newbie
  • Posts: 3
Re: Feasibility? Raspberry Pi with PiFace and Lazarus as a controler
« Reply #3 on: August 09, 2013, 03:48:02 pm »
Thank you for this in depth answer. Seems I was correct to be concerned about feasibility.

I think you misunderstood me in one point: I did not think about using a Desktop or my Android to control the valve. This information was to show my environment. In fact I hoped to be able to develop the code on my desktop and to download it to the Raspberry Pi to execute.
Developing/Compiling the code on the target itself and using the desktop just as an terminal would be OK as well.

In particular I think desktops consume too much space and power for such an application and would be a tremendous overkill. Further I think they are too much prone to errors - I need a system that runs without troubles for month.

If it is really true, that controlling the PiFace will be a headache, this is not the correct environment for me. I hoped there to be a library with calls to control the features of the PiFace. It is somehow hard for me to believe, this is really true. If really yes: Is this a problem of Lazarus/FPC or the Raspberry design?

I executed quick searches for ACU and Atmel. In this first attempt they mainly returned chips. To make this clear as well: I do not want to develop a circuit board for my home projects: I want them to run an something I purchase. I will be able to interface the valve correctly, maybe add some diodes or transistors (I once studied Electrical Engineering) – but I want to invest the major part of my time into the software.
So if someone has a good recommendation for an of the shelf purchase of my hardware I will gladly evaluate this.

If I finally end up with some other language than what I named to be my preferred ones: I could live with that. I have coded so much in my live, that a new language is just a variant of what I did in the past – so this would not be a barrier.
However what I surely want to avoid is an IDE that needs tons of tricks and prayers to generate code. Whatever I'll be using needs to work smooth.
In general I prefer compiled code over interpreted due to less unexpected errors at runtime. Anyway, I'll give Pyton a closer look.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Feasibility? Raspberry Pi with PiFace and Lazarus as a controler
« Reply #4 on: August 09, 2013, 04:29:33 pm »
Lazarus needs a helper to talk to hardware,  for the pi there is wiring pi that gives access to the GPIO pins.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

eny

  • Hero Member
  • *****
  • Posts: 1657
Re: Feasibility? Raspberry Pi with PiFace and Lazarus as a controler
« Reply #5 on: August 09, 2013, 09:24:33 pm »
- is there the possibility to trigger some kind of an 'is-the-Raspberry-still-alive' and to restart it in case it hangs?
Apparently the RasPi has a watchdog that you can use for this purpose:
http://www.megaleecher.net/Watchdog_for_Raspberry_Pi
(didn't try it myself though)
All posts based on: Win11; Lazarus 4_4  (x64) 12-02-2026 (unless specified otherwise...)

avra

  • Hero Member
  • *****
  • Posts: 2584
    • Additional info
Re: Feasibility? Raspberry Pi with PiFace and Lazarus as a controler
« Reply #6 on: August 09, 2013, 11:45:48 pm »
I don't see why Lazarus couldn't fit your needs. I also have a lot of microcontroller experience, but contrary to the one of previous comments I can say that since you will not work with nanoseconds precision RPi's GPIO will perfectly do the work you need. RPi and Lazarus will even perform much better with HTTP pages then any small ATMEL or MICROCHIP microcontroller. I haven't checked my self, but working with PiFace should be like working with any other GPIO stuff. You can use any of the libraries mentioned here: http://wiki.freepascal.org/Lazarus_on_Raspberry_Pi#Accessing_external_hardware

- does a library/samples exist how to download and store http-pages?
- are there timers (soft- or hardware) that can be handled by Lazarus/FreePascal?
- is there the possibility to trigger some kind of an 'is-the-Raspberry-still-alive' and to restart it in case it hangs?
- any other points I could stumle over?
- did I select a clever hard/software. Or do you know maybe much better much better solutions (hardware price, hardware power consumption, hardware versatility for future projects).
- yes
- yes
- yes, there is a watchdog in RPi which can serve to this purpose. If your process hangs and does not reset watchdog timer in time then RPi can reset it self.
- you need to get into linux a little, get into lazarus, decide if you will develop on RPi or cross compile, learn basic electronics, and learn a lot of other things on the way
- the only serious RPi competitor in that price range and with GPIO available is Beaglobone Black, but it does not have such a strong community as RPi has.

Quote
My next project in this area will be a controller for my weekend-house. I just mention this for completness. It would be nice if I would not need restart from scratch and could maybe use hardware from the same family. It will need to have:
- a display and trigger buttons OR a touch display
- needs to measrue temperature and humidity
- control a fan, heating and 220V mains
- remote override
- if you google a little you will find projects like this: http://pikiosk.tumblr.com/post/41042790814/capacitive-touchscreen-raspberry
- google around, there are many similar projects for RPi. If you want to do it from scratch, you must decide which sensors to use (like DS18B20, SHT11, or some other), then what interface to use to talk to it, see if you have it supported with your hardware and your libs, and learn about these interfaces (like SPI, I2C, 1wire...). This is not trivial at all.
- you need to learn how to interface these, and this has nothing to do with RPi. Your RPi has 3.3V outputs, so using most simple 5V solid state relay will not work, and you have to learn more to do use transistor and simple relay. Search the net, or even better buy some ready made board like http://zuzebox.wordpress.com/2012/09/07/minipiio-relay2-board-v0-10. You can also take a look at available boards list here: http://elinux.org/RPi_Expansion_Boards. I think that before making any other steps you need to learn enough to distinguish various boards and interfaces offered there and be confident in this area and in basic electronics too. Without that you will be lost at half way and blame others for your failure. For example, have you ever read datasheet for some chip, learn the protocol, wired device to some protoboard and talked to the device which actually replied providing valid data? This is not trivial and you should know what are you getting into. If that is not your area, maybe you should search for a kit which provides both hardware addon board(s) and source code examples in the same package.
- by remote override I do not know what do you mean? IR remote control or something else?
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

eny

  • Hero Member
  • *****
  • Posts: 1657
Re: Feasibility? Raspberry Pi with PiFace and Lazarus as a controler
« Reply #7 on: August 11, 2013, 01:30:57 am »
- google around, there are many similar projects for RPi. If you want to do it from scratch, you must decide which sensors to use (like DS18B20, SHT11, or some other), then what interface to use to talk to it, see if you have it supported with your hardware and your libs, and learn about these interfaces (like SPI, I2C, 1wire...).
Not to mention the fact that the timing for a 1-wire device like the DS18B20 has to be very precise (accuracy of a couple of micro seconds), hence the initiatives to develop daughter boards.
Although daughter boards often cost more than the RasPi itself :)
« Last Edit: August 11, 2013, 01:33:29 am by eny »
All posts based on: Win11; Lazarus 4_4  (x64) 12-02-2026 (unless specified otherwise...)

avra

  • Hero Member
  • *****
  • Posts: 2584
    • Additional info
Re: Feasibility? Raspberry Pi with PiFace and Lazarus as a controler
« Reply #8 on: August 11, 2013, 04:57:33 pm »
timing for a 1-wire device like the DS18B20 has to be very precise (accuracy of a couple of micro seconds), hence the initiatives to develop daughter boards

Dallas 1wire software only kernel driver implementation for RPi is mentioned here:
http://blog.gegg.us/2013/03/4-different-methods-of-1-wire-access-on-raspberry-pi
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

Blacksmith

  • Newbie
  • Posts: 3
Re: Feasibility? Raspberry Pi with PiFace and Lazarus as a controler
« Reply #9 on: August 12, 2013, 10:48:46 am »
Thank you for those in depth answers. They will help me a lot selecting the correct hard-/software.

@ avra
Most of your answers confirm my original opinion, that RPi and Lazarus will be a good solution to me.

Quote
- the only serious RPi competitor in that price range and with GPIO available is Beaglobone Black, but it does not have such a strong community as RPi has.
I'm astonished you did not mention Arduino and SolderCore as alternative solutions here too!

Quote
- my ability to interface all this stuff...
I'm well aware of all the problems and pits such projects have - but I'm pretty confident I'll be able to solve those. I have pretty broad knowledge in hard- and software. In my life I developed as my daily business CPU-boards, compilers, debuggers, databases and .DLL. But I'm not so strong in UNIX and interfacing real-world – for that reason (and to keep the time for the project over seeable) I want to work with prebuilt components as much as possible.

Quote
- remote override
I meant by means of TCP/IP – so if my first controller will work, I can just copy the code to analyze the HTTP-pages.

picstart

  • Full Member
  • ***
  • Posts: 236
Re: Feasibility? Raspberry Pi with PiFace and Lazarus as a controler
« Reply #10 on: August 12, 2013, 11:07:15 am »
Well,
 I don't see the pi becoming a micro computer replacement. Microchips PIC Atmel etc. have predictable timing and interfaces that are specified according to engineering standards. For example a MSSP ( master slave serial port ) can be both a master and a slave. For I2C being a slave is useful since there can only be one master yet many slaves. You are statistically more likely to want to be a slave especially if there is an existing i2c bus. The pi can only be a master.
Doing things outside the interconnected neighborhoods of the desktop PC world in which coders live is never easy with existing desktop world systems and programming languages.
 The effort that is needed to flash a LED using Lazarus even on the pi pales when compared with the simplicity of one line of code for most micro's.
Largely the effort involves defeating ignoring and tunneling under the mountain of instructions the desktop world needs for its protection and security in it's world wide interconnections.
The Micro's  neighborhood is most often interconnected by wire traces or just wires. It is protected since you need to solder wires or splice wires to interconnect to a new device. Also the micro is often already hidden inside your car or washing machine.
Sure with pi you get a valued interface to the desk top world perhaps wifi or blue tooth but then there is the latency issue. The stacks required to get data packets initially into the air ( not so bad for the next packets in sequence) are notorious for code length. No problem for a human waiting for a web page to arrive but terrible for NAK ACK  microsecond handshake designs that dominate the real world of mechanical and electrical engineering.

avra

  • Hero Member
  • *****
  • Posts: 2584
    • Additional info
Re: Feasibility? Raspberry Pi with PiFace and Lazarus as a controler
« Reply #11 on: August 12, 2013, 10:53:52 pm »
Quote
- the only serious RPi competitor in that price range and with GPIO available is Beaglobone Black, but it does not have such a strong community as RPi has.
I'm astonished you did not mention Arduino and SolderCore as alternative solutions here too!
Arduino is a low level solution. RPi is a high level solution. I compared RPi to something similar, and Arduino is not that. There are problems that are easier to solve on lower level and there are problems that are easier to solve on higher level. For example, if you need OpenCV then RPi or something even stronger will be the choice. Or if I need to bit bang some rare protocol to talk to some specific chip then it would be easier to do it with Arduino. And for example adding GSM/GPRS internet with mapping, navigation and some other stuff on top of some graphics intensive application is a job for a Linux based device, not for Arduino with just few KB of RAM. Although basic HTTP handling can be done with Arduino, you will have much more power with RPi, etc, etc...
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

picstart

  • Full Member
  • ***
  • Posts: 236
Re: Feasibility? Raspberry Pi with PiFace and Lazarus as a controler
« Reply #12 on: August 13, 2013, 12:28:13 am »
 The reason automobiles have many micro processing units ECU's is that they live in a real time world. If your piston reaches top dead center your response is time restricted. That's why auto's have the ECU's connected via a  CAN bus etc.
AFAIK no car is running unix or windows to control much of anything except may be the entertainment package. Same goes with most appliances. The desktop world is about helping people more than physical or electrical devices. Now could you take a PC and dedicate it to controlling fuel injection or deploying airbags. Sure anything has some probability of working. Yes you could bit bang an i2c slave onto a pi. You'd need interrupts since the master can call at anytime but that is hardly the point. For every desktop there are dozens of microprocessors. The pi has little electrical protection lacks watchdog timers. It is not that this is a flaw but the real world needs these things. The pi was designed so children could learn. Again it is for helping people where oodles of instruction cycles can be thrown at creating a nice visual experience. The pi lives in an in between world, it  can throw enough instructions at pleasing people but not as many as a desktop. For real time interfaces there are daughter boards for the pi.
Lazarus on the pi is another matter....Many report that after a week in a room trying to create Lazarus on the pi from sources they still have yet to succeed. Again it is not that it is impossible to succeed. Some will succeed in reaching age 105 but many won't. Realism suggests Lazarus excels mostly as a desktop solution.
« Last Edit: August 13, 2013, 09:02:34 am by picstart »

chrnobel

  • Sr. Member
  • ****
  • Posts: 283
Re: Feasibility? Raspberry Pi with PiFace and Lazarus as a controler
« Reply #13 on: August 13, 2013, 09:38:29 am »
The reason automobiles have many micro processing units ECU's is that they live in a real time world. If your piston reaches top dead center your response is time restricted.
You have to distinguish - what Blacksmith originally asked about was whether it is possible to use the RPi to control a valve, and have some remote capabilities, and in that game, as the RPi is born with networking etc., the RPi is absolutely a good choice.

And if we are speaking about opening a valve for water (or what ever), timing in milliseconds is not an issue.

Quote
The pi has little electrical protection lacks watchdog timers.
Wrong, the RPi does have a watchdog timer.

Quote
The pi was designed so children could learn.
And?
Does that mean that it is useless?

Quote
Lazarus on the pi is another matter....Many report that after a week in a room trying to create Lazarus on the pi from sources they still have yet to succeed.
FUD!
Yes, there are some obstacles, but if you follow the guidance I have linked to earlier, and take in account that the memory in the RPi is limited, then it is not that difficult.

Quote
  Again it is not that it is impossible to succeed. Some will succeed in reaching age 105 but many won't.
Come on, that is bullshit.

Quote
Realism suggests Lazarus excels mostly as a desktop solution.
Even more bullshit - I do a lot of webprogramming, which purely is FPC, but I do still have the advantage of Lazarus's IDE.
And after developing on my normal Linux computer, I do compile my projects (if that is the intention) on the RPi.

Paul Breneman

  • Sr. Member
  • ****
  • Posts: 290
    • Control Pascal
Re: Feasibility? Raspberry Pi with PiFace and Lazarus as a controler
« Reply #14 on: August 14, 2013, 01:31:49 am »
Your projects sound very interesting.  Here are various mini distributions of Free Pascal and the ARM Linux releases work on my RPi:
  http://www.turbocontrol.com/monitor.htm
  http://www.turbocontrol.com/easyfpgui.htm
  http://www.ctrlterm.com/

These are easy to download and compile on your RPi (nothing to install)!
Regards,
Paul Breneman
www.ControlPascal.com

 

TinyPortal © 2005-2018