Why Arduino when you can Pi?

Arduino
Arduino ProMini, Uno, and Nano on expansion board.

Why Arduino?

The greatest advantage to using the Arduino family of microcontrollers for DIY electronics projects, is that they are ubiquitous.  Since they are so available, they are inexpensive and you can find open-source software to get started.

If you’ve ever had the opportunity to work with an Arduino Uno microcontroller board, then you’ve probably executed the flashing LED example.  Going further, you might attach a button, or switch, to trigger the LED or to turn it off making the project interactive.  There are many sensors that could be connected to the Arduino Uno and setup to trigger events, such as the LED flashing, using threshold values that we would need to experiment with in order to figure out what settings work best for creating the effect we want.

While the examples that come with the Arduino software and the examples included with libraries are an excellent start to a project; the Arduino family of microcontrollers is often grossly underutilized in many projects.  Sure microcontrollers are limited in how many instructions they can run; hitting the program size limit doesn’t take very long when you want to control more than a few blinking LEDs.  Even with creative variable handling and custom libraries, eventually, there is a need for another microcontroller or to move to a larger one, even a Raspberry Pi.

In my Alien Invasion Slot Machine project, I tried to push the Arduino closer to its limits.

Time Management and state and trigger flagsf0zk2etiagml1az-medium

At its most basic, a microcontroller loops through a set of instructions handling each action with the focus of The Red Eye of Sauron from Lord of the Rings.  There are a few interrupts that can be configured should an event be so important to receive the full attention of the microcontroller.  Using some form of time management creates a state machine. If x amount of time has passed since x event, then do something and so on…

“The behavior of state machines can be observed in many devices in modern society that perform a predetermined sequence of actions depending on a sequence of events with which they are presented. Simple examples are vending machines, which dispense products when the proper combination of coins is deposited, elevators, whose sequence of stops is determined by the floors requested by riders, traffic lights, which change sequence when cars are waiting, and combination locks, which require the input of combination numbers in the proper order.” https://en.wikipedia.org/wiki/Finite-state_machine

There are rare instances where: RTOS, AI, neural networks exist on microcontrollers, but that’s best left to software-oriented systems such as a Raspberry Pi.

After trying many different timer and time management libraries I felt they were either too much or not enough of what I was wanting in my timers.  A set of timers that are easy to set, keep track of their own state, and each have their own trigger flags.

Button assumptions

buttons

Interacting with an electronics device such as a microcontroller or computer system is relatively easy and typically provided as an example for developers looking to use the device in their project.  Press a button and an LED illuminates. A button or switch may seem like a simple sensor input, but it’s not.

The device’s system resources are consumed waiting and watching for a button press. When we use a button in a project we typically think of it being activated when pressed.  Then what? What should happen if the user holds the button in the active position? Will the button be counted as pressed once, or is the program going to count each second, or x amount of time, as another button press?  Does the program need to know that the button has been released?

Hardware and wiring

wiring harness

Rather than using the Arduino Uno and a protoboard or breadboard for this project, I’m using the Arduino Nano on an expansion board.  Keep it simple using common wiring colors, keep it modular so connections can be made with ease, keep your project sustainable; a part can be replaced rather than the entire system.  The DuPont wire connectors that come with prototyping starter kits makes it easy to create your own custom wiring connections. The wires are easy to solder when a more permanent connection is needed.  I make custom wiring harnesses for neater, cleaner, and more easily connectable modules.

 

Raspberry Pipi3

The latest version of the Raspberry Pi v3 uses a Linux OS and is a computer that can do so much more than an Arduino Uno, why not just use it for everything?  While it is possible to do many of the same tasks as you would do with the Arduino Uno or variant, it’s not always best.  The Arduino Uno and variant microcontrollers are best for doing the same actions, over and over again, such as reading a sensor and doing something with the value.

As I mentioned previously, you can do a lot with a Raspberry Pi, and depending on how much you are doing, it won’t take too long before you discover it has limits.  When the Pi overheats, it will either freeze or shutdown, hopefully, the processor has a heatsink.

More Info:

Please share with friends and follow to receive a notification when I publish a new article.

Using a Raspberry Pi and USB Camera

You have a Raspberry Pi, or are comfortable with the idea of using one, and you want to use it to capture video or images using a USB camera.  Even though the Raspberry Pi has a port designed specifically for using a camera, it’s not as low-cost, nor as convenient as the USB corded camera.

CanaKit Raspberry Pi 3 B+ (B Plus) Starter Kit (32 GB EVO+ Edition, Premium Black Case)

It would be a lot nicer if you had a web interface to access, view, and manage the content you’ve capture using the USB camera.  Learn to set up a LAMP (Linux, Apache, MySQL, PHP) stack on your Raspberry Pi and configure it to work as a web server and set up a basic website which you can access on any device on the same network as your Pi.  This is a link to a nice tutorial for setting-up a L.A.M.P. server on your Pi, the WordPress portion is optional, you can stop after installing PHP. 

Motion

Motion is the tool that you will want to use if you want to live stream, record video, capture motion, and grab a lot of snapshots.  More options means a lot more configuration options making setup more complex.

download and install:

  • sudo apt-get update
  • sudo apt-get upgrade
  • sudo apt-get install motion

usage:  See /etc/motion/ for configuration file(s).  The documentation for Motion is contained within the file motion_guide.html.

The offline version of this file is available in the doc/motion directory. The online version of the motion_guide.html file can be viewed here

growrm2

fswebcam

fswebcam is a simple tool for grabbing snapshots using a USB connected camera and  can be configured to execute routinely using the operating system’s cron job scheduler.

download and install:

  • sudo apt-get update
  • sudo apt-get upgrade
  • sudo apt-get install fswebcam

usage:  https://www.raspberrypi.org/documentation/usage/webcams/

Make a Touch Screen Kiosk

touch screen

Raspberry Pi 7″ Touchscreen Display

AND

SmartiPi Touch case for The Official Raspberry Pi 7″ Touchscreen Display – Adjustable Angle

 

Online Example:

https://coreconduit-device.dataplicity.io/hydroMazing/viewer/index

What is hydroMazing Smart Garden?

Control

The hydroMazing controller is designed to operate ventilation fans for air circulation, water pumps, occasionally a humidifier, heaters, or any other appliance that is necessary to maintain an ideal environment for plants to grow.  Typically, we DIY’ers would hook-up some relays to a microcontroller to achieve control.  However, with hydroMazing, the system uses remote controlled wireless AC outlets, ensuring safer control than traditional relays.  hydroMazing uses low-cost open-hardware modules and the ubiquitous microcontroller, the Atmega328, on an Arduino Nano*, offering the flexibility of customization and expansion. The sensor choices are endless, but I’ve narrowed it down to a few important and relatively inexpensive modules.  A temperature and relative-humidity sensor, moisture sensors for soil, liquid temperature probe for hydroponics, a simple photocell.  There are many other optional additions including the float switch or switches and flow-rate sensors.

The wirelessly controlled outlets proved to be a etekcity_outletsreliable method of controlling the fans using the Arduino to send the signals depending on the temperature sensor’s readings.  It didn’t take long for the source-code to evolve into a beast.  The Arduino family of microcontrollers is limited in how many instructions it can run and hitting the program size limit doesn’t take very long when you want to control more than a few blinking LEDs.  I have found that the size limitation has forced me to write better, more efficient code than I initially do.  Even with creative variable handling and custom libraries, eventually, there is a need for another microcontroller or to move to a larger one.

Wireless Monitoring w/o Internet

There are several ways that the microcontrollers can communicate with each other.  The least expensive wireless method I could find is the nRF24L01 wireless radio transceiver. The module is a low-power, lightweight variety of bluetooth giving hydroMazing the ability to communicate with a monitoring unit.fpzexmwi7vqs7mr-medium

I decided to add another Arduino Uno with an Liquid Crystal Display shield so that I could display what the sensors were reading, the state of appliances, and alerts with notifications.

frv8uq9i800wgat-medium

mmexport1472732631987

I made my own open and adaptable platform that can be custom tailored to a wide variety of gardening needs and conditions; yet, also a self-contained wireless system.  The open-architecture of the system allows for ease of integrating Internet connectivity and web services.

Internet Monitoring

Enter the Raspberry Pi connected with an nRF24L01 module.

I was able to modify much of  my Arduino Source code to listen for incoming transmissions and then write that data out to a few files.  First, a log file that captures all communications between the Pi and the hydroMazing Monitor.  Next, I have the program write out the current state of all sensor objects and a file for all of the appliance objects.  When an alert occurs the progrhydromazing-liveam will create a file containing that alert.

I then added a PHP script to read in the data object’s from their respective files and display live on the Pi’s Apache server.

hydromazing-alert

Next, I wrote a Python script to read the directory for the alerts file and if it exists, read the file, parse out the pertinent information and then email or through SMS text the user.  In addition to sending an email or text alert, the python script moves the alert file into position for the PHP script to read and display.

Using the log files that are created, I am able to import the data into a database.  Once the hydroMazing’s data is recorded into a database residing on the Raspberry Pi we can start performing analytics and generate some reports.

Monitoring and controlling the system is mostly done for us, but when the hydroMazing needs to alert us to a problem it can now by using the Raspberry Pi.

 

img_20161001_145206012

With the hydroMazing smart gardening system, you can grow healthy, happy plants anywhere!

Contact us today for more information!