Speeding Your IoT Design for Industrial Automation Solutions

作者:European Editors

投稿人:DigiKey 欧洲编辑

The development cycle of embedded microcontroller-based industrial automation equipment and controllers has changed very little until recently. Striving to embrace the commercial advantages that the Industrial Internet of Things (IIoT) offers has made many equipment manufacturers change their development approach. Unlike consumer markets, where typically production volumes can dictate a higher level of integration into the design to achieve lower BOM costs, the relatively low volumes of some industrial controllers and sensors have challenged design teams. Where possible, many manufacturers have established a platform approach to their embedded controller design in conjunction with a series of plug-in daughter boards to provide scalability of I/O functionality. While this suits the controller aspects of the design, meeting the connectivity demands of the army of sensors and actuators is difficult.

However, over the past five years or so we have experienced a huge growth in extremely compact embedded microcontroller devices. Driven initially from the maker community, these boards are now starting to become more established inside low volume industrial designs due to their ease of use and low price point. Not only are such boards extremely price competitive when compared to designing your own controller from scratch, but the most popular ones have a huge community of users offering access to informative hardware and software support along with code snippets and design ideas. In the last couple of years, the rate of adoption of embedded boards has ramped even more with the availability of cloud-based portals from some of the leaders in the enterprise IT and cloud computing markets. Offering scalable data storage, analysis and control infrastructure, these organizations are well positioned to rapidly respond to the gathering data storm coming from the millions of IIoT sensors. At the edge of the connected IIoT world, these sensors require little in the way of computing resources but need to be extremely compact and consume little power.

An example of an embedded microcontroller board that meets these criteria is the Adafruit Huzzah ESP8266 breakout board. This miniature host-less board, measuring just 38 x 25 x 5 mm without headers and weighing only 5 g, comprises an ESP8266 wireless microcontroller from Espress if running at 80 MHz. The Wi-Fi capability can operate in both client and access point modes, has 801.11 b/g/n compliance and CE and FCC certification. The 32-bit device is based around a Tensilica L106 3.3 V logic microcontroller with a 16-bit RISC and is ideal for IoT applications and wearable electronics due to its low power consumption and several sleep modes. Approximately 20% of the MCU resource is used for the Wi-Fi stack leaving the remainder for the user application. A short introductory video about the board can be found here.

Adafruit's Huzzah ESP8266 Breakout board (source Adafruit)

Figure 1: Adafruit Huzzah ESP8266

Supplied with headers for fast bread boarding, it can also be used without. Another similar variant, the Adafruit Feather Huzzah, has a convenient socket for connecting a 3.7 LiPo battery, making it ideal for any battery-powered design.

Block diagram of Adafruit's ESP8266 (source Espressif Systems)

Figure 2: ESP8266 block diagram

Figure 2 highlights the internal features of the ESP8266 wireless microcontroller device which features a deep sleep mode power consumption of less than 10 μA and power down mode to 5 μA or less. The Adafruit Huzzah board adds a reset and user buttons, an LED, UART level shifting, a 3.3 regulator together with two diode-protected power inputs. In terms of I/O, the board has 9 GPIO (3.3 V logic) pins that can also be used for I2C or SPI together with 2 x UART pins. The UART also has an ‘FTDI’ format pinout for using with a USB programming cable and/or debugging. The board can also be powered via this cable but removed once configured.

If the hardware capabilities of this board aren’t impressive enough, the software aspects are pretty comprehensive too. A TCP/IP stack with DNS support, a pre-loaded NodeMCU Lua interpreter and full Arduino IDE support provide everything you need to rapidly pull together an IoT design. Similar to Node.js, Lua is an event driven language, and programs can be stored and executed from the board’s Flash memory. A comprehensive set of documentation on using the Lua firmware can be found here.

Mentioned earlier, the community aspects of open source microcontroller boards can be a bonus for developers that get stuck with a problem they can’t quickly resolve. Suffice to say that the community forum at esp8266.com appears to be an extremely active resource for everyone from professional engineers to students.

Faced with implementing, for example, a Wi-Fi connected temperature sensor on an industrial robot, the Huzzah might be an ideal choice due to its compact size, low power and connectivity. Before we explore the cloud connectivity of the Huzzah, let’s take a quick look at downloading a simple LED blinking program to it via the Arduino IDE. Firstly, if you don’t have a working Arduino IDE on your computer you can download it from here. Next you need to install the ESP8266 board support package. Within the preferences options pane find the Additional Boards Manager URLs field and enter the following URL: Arduino Code. You then need to select the ‘Board manager’ from the Tools menu and install the board.

Once updated you should see the Adafruit HUZZAH ESP8266 in the list of boards from the Tools menu. Select this board and set the CPU frequency to 80 MHz and the upload speed to 115200. Select the appropriate COM port for the USB-Serial/FTDI cable you are using.

Now, using the Arduino IDE, create and save the sketch shown in Figure 3 with the ESP8266blinktest.ino code:

 

void setup() {

      pinMode(0, OUTPUT);

     

    }

    

    void loop() {

      digitalWrite(0, HIGH);

      delay(500);

      digitalWrite(0, LOW);

      delay(1500);

    }

Simple blink sketch to test operation of Adafruit's ESP8266 and upload 

Figure 3: Simple blink sketch to test operation of ESP8266 and upload

Once completed, connect your Huzzah board using your USB-serial cable and then put the board into the bootload mode. This is achieved by pressing and holding down the GPIO0 button (see Figure 4). When the red LED in front of it has turned on, press down and release the Reset button, followed by releasing the GPIO0 button. The red LED at the bottom of Figure 4 will then be lit dimly indicating it is ready for bootloading. There is no time-out for this process so you can now use the IDE to upload the blink test sketch. During transfer the blue LED at the front of the ESP8266 module will flash. Once completed you should see the red LED start to flash on and off.

Location of GPIO and Reset buttons

Figure 4:  Location of GPIO and Reset buttons

The next section of this article will now connect the Huzzah board to a cloud platform, in this case the IBM Watson and IBM Bluemix platforms. We’ll add a temperature sensor to our Huzzah board so that we can send some real data to them. Together these scalable robust cloud platforms provide an extremely convenient way to prototype and test IIoT/IoT designs and then deploy them worldwide. The IBM Watson platform provides a means to store and analyze your unstructured data while IBM Bluemix provides the connectivity mechanisms and applications to attach your devices. Both are free to use for up to twenty active devices and 100 MB of data transferred per month and the accounts are free to set up for a trial period. Specifically, within IBM Bluemix there is an application service called the IBM Internet of Things Foundation (IOTF) that provides a simple yet powerful application access to your IoT/IIoT devices. Connectivity to the IOTF uses the MQTT protocol to Publish events from a device, such as a temperature reading in our example, and for devices to subscribe to commands controlling them. Figure 5 shows the basic concepts of how this works. To get started you need to set up an IBM ID. The ID is common to both services and switching between them is seamless once you are signed in.

IBM Internet of Things Foundation Service on IBM Bluemix (source IBM Bluemix) 

Figure 5: IBM Internet of Things Foundation Service on IBM Bluemix

First, set up the IoTF service within IBM Bluemix so that you can talk to your device. Sign into IBM Bluemix and select Catalog from the top menu. Within the boilerplates section select the ‘Internet of Things Foundation Starter’ and then give it a name. Ours is called ‘IndustrialIoTProject’. Your screen should then look like that of Figure 6.

IBM Bluemix screen with IOTF service added

Figure 6: IBM Bluemix screen with IOTF service added

Then double-click on the IOTF service and you will see the Watson IoT Platform welcome screen as illustrated in Figure 7.

Welcome to the Watson IoT Platform

Figure 7: Welcome to the Watson IoT Platform

Click on the ‘Launch Dashboard’ button to start setting up the link to the device. This will take you to an overview screen. Select ‘Devices’ and you come to the device summary screen that should be similar to that in Figure 8. In this example our device has already been set up but your list should be blank.

Device summary screen

Figure 8: Device summary screen

Click on ‘Add device’ and follow the steps. The suggested device type can be ‘ESP8266’, and the device ID can be your own choice - ‘RobotXYCoolingFan’ in this example. When it comes to the Security option just click to the next screen, thereby accepting the default Auto-generated token method. At the end, you will receive a summary of all the information entered about your device. Print this out; it contains some vital device credentials that you will now need to use within the Huzzah application. See Figure 9 for the example created.

Device credentials summary – ensure you print this out

Figure 9: Device credentials summary – ensure you print this out

The cloud platform is now ready to accept data, so let’s set up the Huzzah ESP8266 to send some. For this simple example a simple temperature sensor is used and connected directly to the board’s analog input A0. The TMP36 from Analog Devices is a popular temperature sensor that can operate from a 3.3 VDC supply, available on the Huzzah board, and provides a linear temperature voltage relationship based on a 1 V output equating to 50°C. Note that the Huzzah’s analog input has a maximum voltage of 1.8 VDC. Figure 10 shows the Huzzah board mounted on a bread board with a TO92 packaged TMP36 connected with Pin 1 to +3 VDC supply, Pin 2 to A0 and Pin 3 to Ground.

Adafruit's Huzzah ESP8266 breakout board with ADI's TMP36 temperature sensor

Figure 10: Huzzah ESP8266 breakout board with TMP36 temperature sensor

Now, let’s get the Huzzah sending some data. The example sketch used here (see readtempsend.ino code below) is based on one already available via the IBM developerWorks site to which has been added a few lines of code that read the analog pin to determine the temperature sensor’s voltage output.

readtempsend.ino code:

 

/**

 * Helloworld style, connect an ESP8266 to the IBM IoT Foundation

 *

 * Author: Ant Elder

 * License: Apache License v2

 */

 

// Temperature sensor example - Robert Huntley - 21 March 2016

 

 

#include <ESP8266WiFi.h>

#include <PubSubClient.h> 

//-------- Customise these values -----------

const char* ssid = "EuropeWAP";

const char* password = "5600096865";

 

#define ORG "2d1f1x"

#define DEVICE_TYPE "ESP8266"

#define DEVICE_ID "RobotXYCoolingFan"

#define TOKEN "sISHBQoJMY+7-o!cLv"

//-------- Customise the above values --------

 

char server[] = ORG ".messaging.internetofthings.ibmcloud.com";

char topic[] = "iot-2/evt/status/fmt/json";

char authMethod[] = "use-token-auth";

char token[] = TOKEN;

char clientId[] = "d:" ORG ":" DEVICE_TYPE ":" DEVICE_ID;

 

void callback(char* topic, byte* payload, unsigned int length) {

Serial.println("callback invoked");

 

}

 

WiFiClient wifiClient;

PubSubClient client(server, 1883, callback, wifiClient);

 

 

void setup() {

 Serial.begin(115200);

 Serial.println();

 

 Serial.print("Connecting to ");

 Serial.print(ssid);

 WiFi.begin(ssid, password);

 while (WiFi.status() != WL_CONNECTED) {

 delay(500);

 Serial.print(".");

 }

 Serial.println("");

 

 Serial.print("WiFi connected, IP address: ");

 Serial.println(WiFi.localIP());

}

 

int counter = 0;

 

void loop() {

 

 if (!!!client.connected()) {

 Serial.print("Reconnecting client to ");

 Serial.println(server);

 while (!!!client.connect(clientId, authMethod, token)) {

 Serial.print(".");

 delay(500);

 }

 Serial.println();

 }

 

   // read TMP36 temperature sensor   

     int reading = analogRead(A0);

  // read the temp sensor value

      int temp = (reading -500)/10;

      Serial.println("values - reading & temp ");

      Serial.println(reading);

      Serial.println(temp);

 

String payload = "{\"d\":{\"myName\":\"ESP8266.Test1\",\"counter\":";

 payload += temp;

 payload += "}}";

 

 Serial.print("Sending payload: ");

 Serial.println(payload);

 

 if (client.publish(topic, (char*) payload.c_str())) {

 Serial.println("Publish ok");

 } else {

 Serial.println("Publish failed");

 }

 

 ++counter;

 

 delay(10000);

}

 

Prior to using this example you need to install the PubSubClient.h library file from this GitHub repository. To do this simply download the .zip file, select the Sketch/Include library/Add Zip file in the Arduino IDE. This library provides the necessary routines to package up the data into an MQTT protocol format for communication with IBM Bluemix.

Figure 11 shows the first part of the Arduino sketch. Note the two include files, the Wi-Fi file is already part of the board support file that has been added and the MQTT protocol one you have just added above. Edit the example code and enter the SSID and password of the Wi-Fi access point you will connect to. See Figure 11.

Changing the Wi-Fi and IBM Bluemix values for your application

Figure 11: Changing the Wi-Fi and IBM Bluemix values for your application

You now need to enter in your device credentials from the summary page within IBM Bluemix. Carefully input the organization, device type, device ID and the security token. Note that the sketch makes full use of the serial monitor function for debug and process status while running.

First verify the sketch code then download to the Huzzah board using the same process as for the blinking LED example. On completion check that the serial monitor is connected to your Wi-Fi and is sending data.

After you have seen several ‘Publish ok’ messages in the serial monitor, log into your IBM Bluemix account and locate your device. You should now see a list of recent events starting to fill the screen and the most recent sensor value being displayed, as in Figure 12.

Device summary screen showing recent events and sensor values

Figure 12: Device summary screen showing recent events and sensor values

Within a relatively few steps we have taken the Huzzah ESP8266 wireless microcontroller board and connected it to the IBM Bluemix and Watson platforms. By adopting this low cost, 802.11 certified, extremely compact and versatile board it is possible to quickly develop and deploy sensor applications such as the one used in this example. The cost savings, particularly for low to medium volume sensor products, is significant when compared to having to design your own embedded microcontroller design and provision Wi-Fi connectivity.

免责声明:各个作者和/或论坛参与者在本网站发表的观点、看法和意见不代表 DigiKey 的观点、看法和意见,也不代表 DigiKey 官方政策。

关于此作者

European Editors

关于此出版商

DigiKey 欧洲编辑