I have a significant project that I want to accomplish this fall/winter. I would like to build a digital controller for my greenhouse. I have been a software engineer for 35 years so the programming will be easy. I don’t have any experience with microprocessors and need to learn so that I can do. What introductory and intermediate sources of information would people recommend? I am thinking about a BBB running Ubuntu but am open to suggestions.
You need to find and read sources about embedded Linux. Then, since your project could be done using any number of languages, you need to figure that out too. Past that, you’re going to have to figure out what hardware you’re going to use. Which will indicate if you’re using SPI. I2C, UART, onboard ADC’s or PWM’s etc.
In your shoes, I’d start off with and continue using these instructions: https://eewiki.net/display/linuxonarm/BeagleBone+Black. You can use either Debian or Ubuntu with these build instructions. I’ve been using these instructions since last year ( around 14 or slightly more months ), and they’re very consistent.
You could also start off with a premade Debian console image if you like.
You can definitely compile natively on the board, but if you plan on cross compiling, you’re going to need to understand the gcc toolchain thoroughly. For setup and use.
Why compile anything? For the proposed project (Greenhouse control)
speed is not any sort of priority so use an interpreted language, the
obvious choice on BBB is Python.
... and I am also a long in the tooth software engineer with maybe 30
years of experience writing C, but I'd still recommend going with
Python on this sort of project.
Why compile anything? For the proposed project (Greenhouse control) speed is not any sort of priority so use an interpreted language, the obvious choice on BBB is Python.
Well, the obvious choice to me is Nodejs, and am betting since this person has 35 years experience in related fields, that C is a possibility as well.
I’ve only been programming for 20 or so years . . . so what the hell do i know ?
You might like to take a look at node-RED (http://nodered.org) which is a browser based visual tool for ‘wiring the Internet of Things’ and I reckon a greenhouse counts as a Thing. It is written in Javascript, running in node.js, and runs fine on small embedded Linux machines like the Raspberry Pi and the BeagleBone Black. There are explicit ‘how to set up’ instructions for both these boards on the web site. You can start by ‘wiring up’ analogue & digital input pins to function blocks which make calculations and decisions, back to output pins, or to other things like Internet services. For example, you could make it send an alert to your phone (or an email, or a tweet) when the temperature goes over a limit.
You can write Javascript inside ‘function blocks’ for simple tasks, or if your task warrants it, extend the environment by writing your own ‘node’ - also in Javascript. It’s all open source so you can look under the hood & see how it works. There is an active, helpful developer community emerging around it.
I actually have done a similar control for aeroponics room setups. We are releasing it public in roughly a month once the boards come back and we finish testing on the new hardware run. Very easily can be adapted to greenhouse control as I am sure you’re after the same things, water, temp, humidity, vpd, ph, ppm, disolved oxygen, dew point, flood detection, co2, lumens/lux, uvb, darkness light leak detection and all the rest of the goodness for optimal environmental control. Even the cooling opener could be adjusted/adapted to fit to automate opening roof panels. Ours is all in python and php with darkhttpd as the webserver. I dispise nodejs, it reminds me of the cluster that ruby gems are.
Ours is all in python and php with darkhttpd as the webserver. I dispise nodejs, it reminds me of the cluster that ruby gems are.
And this is why there is no easy guide. At least from a programing aspect. No two people are going to agree on how it should be done, and what is used to get it done.
Nodejs does however get a bad rap I think. The stigma of javascript comes with it. Which is its self often misunderstood. Nothing is perfect however . . .
Ours is all in python and php with darkhttpd as the webserver. I dispise nodejs, it reminds me of the cluster that ruby gems are.
And this is why there is no easy guide. At least from a programing aspect. No two people are going to agree on how it should be done, and what is used to get it done.
Nodejs does however get a bad rap I think. The stigma of javascript comes with it. Which is its self often misunderstood. Nothing is perfect however . . .
I agree with you William; however, php and darkhttpd don’t scale very well, because it lacks asynchronous I/O capability. Also, the current spec’d Javascript is pretty close to the more perfect language compared to C, Java or Python. It also has the biggest user base of any language, by far and it is the only true language that works in all browsers and on the server. BTW, there are no bad parts, just bad programmers.
You’re preaching to the choir John. Except that I do not feel that JavaScript is the closest thing to a perfect anything. Again, there is no one perfect “tool” to rule them all.
However, I do feel that because of google’s V8 engine, and Nodejs, that javascript finally is something worth using for high level Rapid Application Development (RAD). Now, it is more like a Java, or dotNET done right. Performance wise, it is also very fast, and performs very close to native C.
In contrast, python and php are much slower. More so for Python which is one of the slowest languages around. So, I will agree that it is not always about what is faster, but n the case of an embedded device. Fast performance means better efficiency. Which could mean the difference between a battery lasting 2 hours, versus overnight.
Shrug Anyhow, I will not have anyone telling me what I can and cannot use, so I will try to return the favor.
You’re preaching to the choir John. Except that I do not feel that JavaScript is the closest thing to a perfect anything. Again, there is no one perfect “tool” to rule them all.
Take a look at Douglas Crockford presentations on Javascript and he will explain why Javascript is the closest we have to a functional more perfect language. He explains why JAVA is a horrible language. BTW, I’m a C programmer, so it took me a while to adjust to the way Javascript works. Remember, that the original Javascript was written in a few days by Brendan Erich and that work has plenty of problems and this is why Javascript gets a bad rap. However, after the work done by ECMAscript language standard, the language improved dramatically. You are right, the Google V8 engine made this language fast.
I know javascript well enough. Now try to write device driver code with it, or something else equally low level. Or even something mission critical such as engine timing monitoring/adjustment, airbag deployment, or missile/drone guidance.
I know other languages well enough too. C/C++, ASM C# VB.NET, and a few obscure scripting languages hardly worth mentioning. But the point is, you’ll never get away with using javscript for everything because somethings for some situations require specific languages. Missile guidance for example you’re most likely going to have to use ADA. Device drivers, either C, or ASM, and if you’re building a Microsoft web server service / backend you’re very likely to use C# / VB.NET with ASP.NET.
It’s not that things cant be done differently, it is that you’re most likely never going to get away with it in the field professionally. Not only that somethings are either close to impossible, or do not even come close to making sense.
I agree with William JS is far from a perfect language in all use cases. Nothing is, but hey Jon loves tooting from the only horse in world on stilts. It has its place just like everything else. Just because your experience has failed you for what I used/chose does not mean anything about my skill or the project Jon. You know nothing of the needs or demands of the project in which I stated. Nor do you actually even know the true demands of what he wants to actually control or monitor in his greenhouse. Just cause you like to gobble JS and nodes nuts, does not mean we needed that long of a rant in multiple posts while veering so far from what the OP actually asked. One rant of why you love JS for everything in this world and its red headed step child node would suffice. At least I was just trying to be helpful with hints about what works for me and 15 beta testers in a similar application, ie environmental control unit for aeroponics. Should he use exactly the languages I stated no, his choice his project. But nodejs is in my opinion is not the route to take, this also coming from a package maintainers perspective. You know say if he actually wanted to run a repo to pull updates from and deploy onto his devices so its properly handled and tracked through apt and making sure the dependencies installed were actually handled and tracked through the package manager vs. leaving a cluttered filesystem of untracked additions. If the OP shares what he would actually like to track & do in his greehouse I can point you to sensors and setups I have gone with for inspiration to help get you going. It is honestly nothing too major and endless examples are on the net already for just about anything you want to track or do in that type of environment.
I agree with William JS is far from a perfect language in all use cases. Nothing is, but hey Jon loves tooting from the only horse in world on stilts. It has its place just like everything else. Just because your experience has failed you for what I used/chose does not mean anything about my skill or the project Jon. You know nothing of the needs or demands of the project in which I stated. Nor do you actually even know the true demands of what he wants to actually control or monitor in his greenhouse. Just cause you like to gobble JS and nodes nuts, does not mean we needed that long of a rant in multiple posts while veering so far from what the OP actually asked. One rant of why you love JS for everything in this world and its red headed step child node would suffice.
At least I was just trying to be helpful with hints about what works for me and 15 beta testers in a VERY similar application, ie environmental control unit for aeroponics.
Should he use exactly the languages I stated no, his choice his project. But nodejs is in my opinion is not the route to take, this also coming from a package maintainers perspective. You know say if he actually wanted to run a repo to pull updates from and deploy onto his devices so its properly handled and tracked through apt and making sure the dependencies installed were actually handled and tracked through the package manager vs. leaving a cluttered filesystem of untracked additions.
If the OP shares what he would actually like to track & do in his greehouse I can point you to sensors and setups I have gone with for inspiration to help get you going. It is honestly nothing too major and endless examples are on the net already for just about anything you want to track or do in that type of environment.
Why do I bother. I was only responding to this statement:
"Ours is all in python and php with darkhttpd as the webserver. I dispise nodejs, it reminds me of the cluster that ruby gems are”
Which is clearly not valid. Nodejs is clearly the better solution in almost any application (better security, more responsive, scales better and is easier to support, etc) given two equally skilled programmers. Another thing, you and William are twisting my words. I never said Javascript was the perfect language. I said it was “the more perfect language”, which means it is better than others, but not any where near perfect. If you have a language whose syntax, style, structure, security, etc is considered to be better than Javascript, name one. We are talking about server side applications, so I don’t know where kernel device drivers popped into the discussion.
Oh, and BTW, we are only here to help so it doesn’t help to get either aggressive or defensive. We are here to share ideas and out experience. We all have something to learn.
The original question was one of hardware. I can figure out the software based on what I know and feel comfortable with. My question is: how do I control roughly 20 relays, some that I need to set and some that I need to ‘read’, ideally as an interrupt when they close? I also need to work with a couple of A/D inputs, mainly temperature. From the documentation that I have seen, no cape can support that many relays, so I need multiple capes. How do I do that? Can they be stacked? Can I use I2C to select the address to ‘write’ to in order to energise the relay coil? How do I organize them to allow I2C to select an address through multiple capes? How do I get the power to drive a relay? TTL logic can’t do that. These are my fundamental questions. Where can I go to get the answers? I really want to learn rather than be handed answers. I can deal with the software issues well enough, it is the hardware decisions that are stumping me.
Sounds like you need some EE courses with control theory ;>) Since you are controlling a greenhouse with a considerable amount of wiring, it sounds like your relays and A/D will be far from your main controller (BBB). Light to medium duty mechanical relays need 12VDC and a relay driver, heavy duty relays require 110VAC. If the controlled devices are far (more than a few feet) you have to worry about voltage drops across the wiring, especially if the control signals are bridging the distance (ie the relay is near the controlled device). Some sort of distributed control might be in order. By that I mean an Arduino like micro (there are a couple of small compatible boards out there) controlling one or several relays on command from the BBB and reporting status back, over serial (RS485 is multi-drop) or wireless like Zigbee. Relays are open loop type devices, there is no built-in feedback to know they have closed, usually one just assumes they closed within the time they specify. An interrupt on closing would have to be an added circuit, do you really need it? Hmm, you don’t say if you are using mechanical or Solid State relays. If there are Capes with relays, I would expect they would have an external power input. Make sure to pay attention to the power required to size your supply.
www.controlanything.com has been making relay control boards for years, starting with RS232 and migrating to USB, Zigbee, and now ethernet/wifi. They may not be what you want, but they have some good application and usage notes. If you are controlling heavy loads you have to worry about noise feedback.
I would start by making a block diagram of the setup, then listing all the devices controlled and monitored and their requirements (current, voltage, distance from the main controller, etc).
Don’t forget about enclosures. Greenhouses are pretty humid, damp and electronics does NOT like moisture. It sounds like you have an interesting and challenging project.
Don’t forget the USB!
You can always use USB X10 controller and X10 modules and your greenhouse electrical wiring to turn on / off devices.
That can control your high current / high voltage needs without using a cape.
That leaves sensors & feedback.