My motivation

I was so curious about excellence of the image recognition with TensorFlow on Raspberry Pi. Also, the Jupyter notebook is very convenient to instantly code as a quick prototype. So, in terms of error rate of the image classification, Inception V3(3.46%) is more excellent than human(5.1%) whereas raspberry pi’s processing speed is very slow compare to my laptop.

Introduction

My motivation for PID Control For CPU Temperature of Raspberry Pi came for many reasons such as very hot CPU, very noisy fan’s sound and fast battery consumption because the hot CPU makes the system really unstable while using Raspberry Pi for a long time. So, I have optimized the failing by using PID node on Node-RED. It’s visually helpful for a trainee to understand the PID control system for an educational purpose.

This will cover the basic steps that you need to follow to get started with open sources like PID node, MQTT node in the Node-RED. Also, it’s really painful and hard to tune 3 gains like KP, KI, and KD as manual tuning(Trial and error) method. There are many tuning methods such as Manual tuning, Ziegler–Nichols, Tyreus Luyben, Cohen–Coon, Åström-Hägglund and Software tools such as Simulink in Matlab or Excel PID Simulator (enclosed). I’ve already provided my source codes in the Download List but If you use a different fan, you should tune PID gains because most physical fan’s characteristics are different. You can get more information from the linked web (PID controller).

MQTT(Message Queueing Telemetry Transport) is a Machine-To-Machine(M2M) or Internet of Things (IoT) connectivity protocol that was designed to be extremely lightweight and useful when low battery power consumption and low network bandwidth is at a premium. It was invented in 1999 by Dr. Andy Stanford-Clark and Arlen Nipper and is now an Oasis Standard. I’ve already published about how to approach the MQTT below the linked webs.

(7) Try dragging & dropping any node from the left-hand side to right-hand side. It’s really easy to code. ( You can conveniently use the visual editor offline as well as online. ) Download the ‘PID_Control_For_CPU_TEM_ver0.5.txt’ file. (1) Click the number (1) at the right-hand side corner shown in NodeRED on web-browser. (2) Click the Import button on the drop down menu. (3) Open the Clipboard shown in the above 1st picture. (4) Lastly, paste the given JSON format text of ‘PID_Control_For_CPU_TEM_ver0.5.txt’ in Import nodes editor.

Step 5: Setting up MQTT v3.1 on Raspberry Pi2

Setting up MQTT v3.1 on Raspberry Pi2

This message broker(Mosquitto) is supported by MQTT v3.1 and it is easily installed on the Raspberry Pi and somewhat less easy to configure. Next we step through installing and configuring the Mosquitto broker. We are going to install & test the MQTT “mosquitto” on terminal window.

curl -O http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key

sudo apt-key add mosquitto-repo.gpg.key

rm mosquitto-repo.gpg.key

cd /etc/apt/sources.list.d

sudo curl -O http://repo.mosquitto.org/debian/mosquitto-jessie.list

sudo apt-get update

Next install the broker and command line clients:

mosquitto – the MQTT broker (or in other words, a server)

mosquitto-clients – command line clients, very useful in debugging

python-mosquitto – the Python language bindings

sudo apt-get install mosquitto mosquitto-clients python-mosquitto

As is the case with most packages from Debian, the broker is immediately started. Since we have to configure it first, stop it.

sudo /etc/init.d/mosquitto stop

Now that the MQTT broker is installed on the Pi we will add some basic security.

Create a config file:

cd /etc/mosquitto/conf.d/
sudo nano mosquitto.conf

Let’s stop anonymous clients connecting to our broker by adding a few lines to your config file. To control client access to the broker we also need to define valid client names and passwords. Add the lines:

We will to use the mosquitto_passwd tool to create a password hash for user pi:

sudo mosquitto_passwd -c /etc/mosquitto/conf.d/passwd pi

You will be asked to enter your password twice. Enter the password you wish to use for the user you defined.

Testing Mosquitto on Raspberry Pi

Now that Mosquitto is installed we can perform a local test to see if it is working: Open three terminal windows. In one, make sure the Mosquitto broker is running:

mosquitto

In the next terminal, run the command line subscriber:

mosquitto_sub -v -t 'topic/test'

You should see the first terminal window echo that a new client is connected.In the next terminal, run the command line publisher:

mosquitto_pub -t 'topic/test' -m 'helloWorld'

You should see another message in the first terminal window saying another client is connected. You should also see this message in the subscriber terminal:

topic/test helloWorld

We have shown that Mosquitto is configured correctly and we can both publish and subscribe to a topic.When you finish testing all, let’s set up below that.

sudo /etc/init.d/mosquitto start

Step 6: Checking your NodeRED codes with MQTT on Raspberry Pi2

When you will use the JSON format of the ‘PID_Control_For_CPU_TEM_ver0.5.txt‘ on Node-RED, it’s automatically set up & coded each data. I have already set up the each data in each node.

(1) Click each node.

(2) Check information inside each node has been prefilled.

(3) Please don’t change the set data. (The above can be customized for more advanced users.)

Step 7: Adding & Setting up PID node, Dashboard on Raspberry Pi2

Searching the Nodes

Node-RED comes with a core set of useful nodes, but there are a growing number of additional nodes available for installing from both the Node-RED project as well as the wider community. You can search for available nodes in the Node-RED library or on the npm repository.

For example, we are going to search ‘node-red-node-pidcontrol‘ at the npm web. Click here.

Then, we are going to install npm package, node-red-node-pidcontrol, node-red-dashboard on Raspberry Pi.

To add additional nodes you must first install the npm tool, as it is not included in the default installation. The following commands install npm and then upgrade it to the latest 2.x version.

sudo apt-get update

sudo apt-get install npm

sudo npm install -g npm@2.x

hash -r

cd /home/pi/.node-red

For example, ‘npm install node-red-{example node name}’

Copy the ‘npm install node-red-node-pidcontrol’ from the npm web. Paste it on a terminal window.

(7) The chart to display on the web browser is same as the gauge (1 – 9 steps).

Step 9: Tuning PID controller

There are many tuning methods such as manual tuning, Ziegler–Nichols, Tyreus Luyben, Cohen–Coon, Åström-Hägglund and software tools such as Simulink in Matlab or Excel PID Simulator(enclosed). I’ve used 2 tuning methods like manual tuning, Ziegler-Nichols method and software tools such as Matlab, Simulink, and Excel. (According to Wikipedia: PID Controller)

Manual Tuning(Trial and error)

How do the PID parameters affect system dynamics?

We are most interested in four major characteristics of the closed-loop step response. They are

– Rise Time: the time it takes for the plant output y to rise

– Overshoot: how much the peak level is higher than the steady state, normalized against the steady – state.– Settling Time: the time it takes for the system to converge to its steady state.

– Steady-state Error: the difference between the steady-state output and the desired output.

(NT: No definite trend. Minor change.)

How do we use the table?

Typical steps for designing a PID controller are Determine what characteristics of the system needs to be improved.

– Use KP to decrease the rise time.

– Use KD to reduce the overshoot and settling time.

– Use KI to eliminate the steady-state error.

– This works in many cases, but what would be a good starting point? What if the first parameters we choose are totally crappy? Can we find a good set of initial parameters easily and quickly?

Ziegler–Nichols method

– Ziegler and Nichols conducted numerous experiments and proposed rules for determining values of KP, KI, and KD based on the transient step response of a plant.

– They proposed more than one methods, but we will limit ourselves to what’s known as the first method of Ziegler-Nichols in this tutorial. It applies to plants with neither integrators nor dominant complex-conjugate poles, whose unit-step response resemble an S-shaped curve with no overshoot. This S-shaped curve is called the reaction curve. This S-shaped curve is called the reaction curve.

– The S-shaped reaction curve can be characterized by two constants, delay time L and time constant T, which are determined by drawing a tangent line at the inflection point of the curve and finding the intersections of the tangent line with the time axis and the steady-state level line.

– The Ziegler-Nichols Tuning Rule Table

Using the parameters L and T, we can set the values of KP, KI, and KDaccording to the formula shown in the table above.

These parameters will typically give you a response with an overshoot about 25% and good settling time. We may then start fine-tuning the controller using the basic rules that relate each parameter to the response characteristics. KP, KI, and KD based on the transient step response of a plant.

PID tuning software

– Matlab: PID Controller Tuning

– Simulink: PID Controller Tuning

– Excel PID simulator

– Etc

PID control VS On/Off control

– On/Off control: An on-off controller is the simplest form of temperature control device. The output from the device is either on or off, with no middle state. An on-off controller will switch the output only when the temperature crosses the setpoint. For heating control, the output is on when the temperature is below the setpoint, and off above setpoint. Since the temperature crosses the setpoint to change the output state, the process temperature will be cycling continually, going from below setpoint to above, and back below. In cases where this cycling occurs rapidly, and to prevent damage to contactors and valves, an on-off differential, or “hysteresis,” is added to the controller operations. This differential requires that the temperature exceeds setpoint by a certain amount before the output will turn off or on again. On-off differential prevents the output from “chattering” or making fast, continual switches if the cycling above and below the setpoint occurs very rapidly. On-off control is usually used where a precise control is not necessary, in systems which cannot handle having the energy turned on and off frequently, where the mass of the system is so great that temperatures change extremely slowly, or for a temperature alarm. One special type of on-off control used for alarm is a limit controller. This controller uses a latching relay, which must be manually reset, and is used to shut down a process when a certain temperature is reached.

– PID control: This controller provides proportional with integral and derivative control, or PID. This controller combines proportional control with two additional adjustments, which helps the unit automatically compensate for changes in the system. These adjustments, integral and derivative, are expressed in time-based units; they are also referred to by their reciprocals, RESET, and RATE, respectively. The proportional, integral and derivative terms must be individually adjusted or “tuned” to a particular system using trial and error. It provides the most accurate and stable control of the three controller types, and is best used in systems which have a relatively small mass, those which react quickly to changes in the energy added to the process. It is recommended in systems where the load changes often and the controller is expected to compensate automatically due to frequent changes in setpoint, the amount of energy available, or the mass to be controlled.

The single-board computer has all the components mashed onto a tiny circuit board. It can be used to develop gadgets, wearables, home automation products, industrial equipment and other Internet of Things products.

Developers could also use the computer to hook up sensors for temperature, light, sound, weather and distance to devices.

The developer board is now available from Mouser Electronics. It will also be available from Avnet, according to Intel.

Intel is targeting companies developing IoT devices and the community of do-it-yourself hardware makers with the new board. These boards typically provide a cheap way to prototype electronics or to make fun devices. Intel is following Atmel, SparkFun, and other vendors that develop inexpensive boards.

This board can’t be compared to a high-powered board computer like Raspberry Pi 3, which can double as a PC. The Intel board is smaller, consumes much less power and has a much slower CPU.

Intel has shown examples of how such developer boards can be used. Its Curie board was used on snowboards at X Games to capture and provide real-time information on speed, the height of a jump, and other statistics to viewers and athletes.

Intel has been partnering with well-known products and TV shows to establish its brand recognition with makers, but the core community hasn’t warmed up to the chip maker’s products yet. Developer boards are mostly ARM-based, but the $15 board could provide Intel a breakthrough in the maker community.

The new developer board has the Quark D2000 microcontroller, which operates at a speed of 32MHz, the same frequency as the Quark chip on the button-sized Curie board.

The Intel board has a six-axis accelerometer, a magnetometer with a temperature sensor, and one USB 2.0 port. It also has a coin cell battery slot and a 5-volt power input.

The board is compatible with the hardware specifications of Arduino Uno, a popular software development tool with makers. A development kit called Intel System Studio for Microcontrollers, which is based on the Eclipse integrated development environment, is also included in the kit.

Arduino Wiring

Once you’ve gotten the GPS module tested with direct wiring, we can go forward and wire it up to a microcontroller. We’ll be using an Arduino but you can adapt our code to any other microcontroller that can receive TTL serial at 9600 baud. Arduino Wiring

Connect VIN to +5V, GND to Ground, RX to digital 2 and TX to digital 3.

Next up, download the Adafruit GPS library. This library does a lot of the ‘heavy lifting’ required for receiving data from GPS modules, such as reading the streaming data in a background interrupt and auto-magically parsing it. To download it, visit the GitHub repository or just click below

Move Adafruit_GPS to your Arduino/Libraries folder and restart the Arduino IDE. Library installation is a frequent stumbling block…if you need assistance, our All About Arduino Libraries guide spells it out in detail!

Leonardo & Micro Users: We have special example sketches in the Adafruit_GPS library that work with the Micro/Leo!

Open up the File→Examples→Adafruit_GPS→echo sketch and upload it to the Arduino. Then open up the serial monitor. This sketch simply reads data from the software serial port (pins 2&3) and outputs that to the hardware serial port connected to USB.

Open up the Arduino IDE Serial Console and make sure to set the Serial baud rate to 115200

You can configure the GPS output you see by commenting/uncommenting lines in the setup() procedure. For example, we can ask the GPS to send different sentences, and change how often it sends data. 10 Hz (10 times a second) is the max speed, and is a lot of data. You may not be able to output “all data” at that speed because the 9600 baud rate is not fast enough.

// You can adjust which sentences to have the module emit, below
// uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
// uncomment this line to turn on only the "minimum recommended" data for high update rates!
//GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
// uncomment this line to turn on all the available data - for 9600 baud you'll want 1 Hz rate
//GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_ALLDATA);
// Set the update rate
// 1 Hz update rate
//GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
// 5 Hz update rate- for 9600 baud you'll have to set the output to RMC or RMCGGA only (see above)
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_5HZ);
// 10 Hz update rate - for 9600 baud you'll have to set the output to RMC only (see above)
//GPS.sendCommand(PMTK_SET_NMEA_UPDATE_10HZ);

In general, we find that most projects only need the RMC and GGA NMEA’s so you don’t need ALLDATA unless you have some need to know satellite locations.

YOLO-Powered_Robot_Vision

Introduction

This is a Pi-based robot to implement visual recognition(by YOLO). The YOLO-Powered vision can recognize many objects such as people, car, bus, fruits, and so on.

Hardware: Raspberry-Pi2, Sony PS3 Eye Camera

(Available to use Logitech C270 USB camera with Raspberry Pi)

Software: YOLO(v2), Jupyter-Notebook

My motivation

I was so interested in performance of the image recognition with YOLO-2 on Raspberry Pi. In addition, the Jupyter notebook is really convenient to instantly code as a quick prototype. According to paper, I realised that YOLO is a fast, accurate visual detector, making it ideal for computer vision system. We connect YOLO to a webcam and verify that it maintains real-time performance. So, the Raspberry pi’s processing speed is very slow compare to my laptop.

RNNLIB-RNNLIB is a recurrent neural network library for sequence learning problems. Applicable to most types of spatiotemporal data, it has proven particularly effective for speech and handwriting recognition.

The LUSH programming language and development environment, which is used @ NYU for deep convolutional networks

Eblearn.lsh is a LUSH-based machine learning library for doing Energy-Based Learning. It includes code for “Predictive Sparse Decomposition” and other sparse auto-encoder methods for unsupervised learning. Koray Kavukcuoglu provides Eblearn code for several deep learning papers on this page.

MShadow – MShadow is a lightweight CPU/GPU Matrix/Tensor Template Library in C++/CUDA. The goal of mshadow is to support efficient, device invariant and simple tensor library for machine learning project that aims for both simplicity and performance. Supports CPU/GPU/Multi-GPU and distributed system.

CXXNET – CXXNET is fast, concise, distributed deep learning framework based on MShadow. It is a lightweight and easy extensible C++/CUDA neural network toolkit with friendly Python/Matlab interface for training and prediction.

Nengo-Nengo is a graphical and scripting based software package for simulating large-scale neural systems.

cudamat is a GPU-based matrix library for Python. Example code for training Neural Networks and Restricted Boltzmann Machines is included.

Gnumpy is a Python module that interfaces in a way almost identical to numpy, but does its computations on your computer’s GPU. It runs on top of cudamat.

The CUV Library (github link) is a C++ framework with python bindings for easy use of Nvidia CUDA functions on matrices. It contains an RBM implementation, as well as annealed importance sampling code and code to calculate the partition function exactly (from AIS lab at University of Bonn).

Apache Singa is an open source deep learning library that provides a flexible architecture for scalable distributed training. It is extensible to run over a wide range of hardware, and has a focus on health-care applications.

Lightnet is a lightweight, versatile and purely Matlab-based deep learning framework. The aim of the design is to provide an easy-to-understand, easy-to-use and efficient computational platform for deep learning research.

Build your own block chain in 15 minutes on Node-RED using Node.js, JavaScript, Cloudant/CouchDB on a free IBM Cloud account… Note: To do the tutorial you need a free Bluemix (IBM PaaS Cloud) account. You can obtain one here and the raw file (JSON) for this NodeRED flow is here. Tutorial Objective In this exercise […]

Enabling PWM output on GPIO pins.

Available PINS

The following object depicts available pins for all revisions of raspberry-pi, the key is the actual number of the physical pin header on the board,the value is the GPIO pin number assigned by the OS, for the pins with changes between board revisions, the value contains the variations of GPIO pin number assignment between them (eg.rev1, rev2, rev3).

You should just be concerned with the key (number of the physical pin header on the board), Cylon.JS takes care of the board revision and GPIO pin numbers for you, this full list is for reference only.