Application Note AN 126: Arduino UART Interface to K 30 Sensor

Similar documents
Arduino Lesson 1. Blink

Work with Arduino Hardware

Arduino Lesson 5. The Serial Monitor

Intro to Intel Galileo - IoT Apps GERARDO CARMONA

LCD I 2 C/Serial RX Backpack. Data Sheet. LCD to I2C/Serial RX Backpack I2C or Serial RX communication with Standard 16 Pin LCD modules

Eric Mitchell April 2, 2012 Application Note: Control of a 180 Servo Motor with Arduino UNO Development Board

Instructions for Installing and Using the FOCUS DL-15 Data Transfer Software

IR Communication a learn.sparkfun.com tutorial

Yun Shield Quick Start Guide VERSION: 1.0 Version Description Date 1.0 Release 2014-Jul-08 Yun Shield Quick Start Guide 1 / 14

Sending Data from a computer to a microcontroller using a UART (Universal Asynchronous Receiver/Transmitter)

RECON-4 Portable Multi-gas Detector Software Manual

Connecting Arduino to Processing a

CAN-Bus Shield Hookup Guide

Arduino Lesson 16. Stepper Motors

Board also Supports MicroBridge

MeshBee Open Source ZigBee RF Module CookBook

Using a Laptop Computer with a USB or Serial Port Adapter to Communicate With the Eagle System

Omron I/O Driver (Series 2) Programmable Serial Interface Card

Arduino Lesson 13. DC Motors. Created by Simon Monk

TUTORIAL FOR INITIALIZING BLUETOOTH COMMUNICATION BETWEEN ANDROID AND ARDUINO

Windows XP.. ELITE Firmware Update procedures.. v1.41

Thermomark Roll - Driver Installation - Windows 7

#include <Gamer.h> Gamer gamer; void setup() { gamer.begin(); } void loop() {

A REST API for Arduino & the CC3000 WiFi Chip

Start A New Project with Keil Microcontroller Development Kit Version 5 and Freescale FRDM-KL25Z

All About Arduino Libraries

Practice Fusion API Client Installation Guide for Windows

SAPIP GUI INSTALLATION. Table of Contents

Using Xbee in Serial Communication

EARTH PEOPLE TECHNOLOGY SERIAL GRAPH TOOL FOR THE ARDUINO UNO USER MANUAL

Arduino Lesson 14. Servo Motors

PN532 NFC RFID Module User Guide

Develop a Dallas 1-Wire Master Using the Z8F1680 Series of MCUs

Adafruit's Raspberry Pi Lesson 5. Using a Console Cable

How to program a Zumo Robot with Simulink

Adafruit MCP9808 Precision I2C Temperature Sensor Guide

Bluetooth + USB 16 Servo Controller [RKI-1005 & RKI-1205]

Adafruit's Raspberry Pi Lesson 5. Using a Console Cable. Created by Simon Monk

GM862 Arduino Shield

SEC 4100 SYSTEM MONITOR Programmable Serial Interface Card Series 2

THERMOMARK CARD - Driver Installation - Windows XP

Waspmote. Quickstart Guide

Programing the Microprocessor in C Microprocessor System Design and Interfacing ECE 362

Using IDENT M System T with Modbus/TCP

Adafruit's Raspberry Pi Lesson 5. Using a Console Cable

Ultrasonic Distance Measurement Module

Application Note: AN00141 xcore-xa - Application Development

Arduino Wifi shield And reciever. 5V adapter. Connecting wifi module on shield: Make sure the wifi unit is connected the following way on the shield:

E-Blocks Easy Internet Bundle

RN-XV-RD2 Evaluation Board

Arduino ADK Back. For information on using the board with the Android OS, see Google's ADK documentation.

Example Connection between USB Host and Android

DS1307 Real Time Clock Breakout Board Kit

Contents Models 3500 / 3600 Software & Driver Installation... 1 Install Amplifier Control Panel... 2 Download and Install the Drivers...

Microcontroller Systems. ELET 3232 Topic 8: Slot Machine Example

How to setup a serial Bluetooth adapter Master Guide

Summer Project Report. Fingerprint Based Attendance System

Adafruit SHT31-D Temperature & Humidity Sensor Breakout

Yun Shield User Manual VERSION: 1.0. Yun Shield User Manual 1 / 22.

cs281: Introduction to Computer Systems Lab08 Interrupt Handling and Stepper Motor Controller

Set up and Blink - Simulink with Arduino

Lab 6 Introduction to Serial and Wireless Communication

Configuring IP to Serial with Auto Answer and Serial to IP

Microcontroller Programming Beginning with Arduino. Charlie Mooney

Arduino & Android. A How to on interfacing these two devices. Bryant Tram

MS830 / MS833 Barcode Reader v1.0 9-December-2014

Introduction to Dynamixel Motor Control Using the ArbotiX-M Robocontroller

Workshop Intel Galileo Board

INTRODUCTION TO SERIAL ARM

S88XPressNetLI v1.0. Installation, user and reference manual KDesign Electronics, PCB design by RoSoft

Vmed QUICKSTART PC-DISPLAY INSTALLATION & PC-Display and Bluetooth Instructions

XConsole GUI setup communication manual September 2010.

Current Cost Data Cable User Guide. Installing and configuring the data cable

Getting started with the O Watch

Shearwater Research Dive Computer Software Manual

BIT COMMANDER. Serial RS232 / RS485 to Ethernet Converter

PC Base Adapter Daughter Card UART GPIO. Figure 1. ToolStick Development Platform Block Diagram

Creating a Project with PSoC Designer

The Answer to the 14 Most Frequently Asked Modbus Questions

Setting up a Local Interconnect Network (LIN) using dspace MicroAutoBox 1401/1501 Simulink Blocks

Instructions for downloading and installing the GPS Map update

Handheld LPC Data Retrieval Software for Windows. Operation Manual

Now you can compile and upload your code supporting highier buffered serial input data. */

PHYS 2P32 Project: MIDI for Arduino/ 8 Note Keyboard

Ethernet Interface Manual Thermal / Label Printer. Rev Metapace T-1. Metapace T-2 Metapace L-1 Metapace L-2

Table of Contents Appendix 4-9

Modern Robotics, Inc Core Device Discovery Utility. Modern Robotics Inc, 2015

RPLIDAR. Low Cost 360 degree 2D Laser Scanner (LIDAR) System Development Kit User Manual Rev.1

Arduino project. Arduino board. Serial transmission

Secure Held Print Jobs. Administrator's Guide

Copyright 2015 SolarWinds Worldwide, LLC. All rights reserved worldwide. No part of this document may be reproduced by any means nor modified,

An Introduction To Simple Scheduling (Primarily targeted at Arduino Platform)

How to add your Weebly website to a TotalCloud hosted Server

Quick Start Guide RIVA/Athena Sea-Doo ECU

Data Acquisition Module with I2C interface «I2C-FLEXEL» User s Guide

TSM for Windows Installation Instructions: Download the latest TSM Client Using the following link:

Unity Error Message: Your voic box is almost full

Step by Step. Use the Cloud Login Website

Centurion C4 Transfer Guide using C4 File Transfer Utility

Transcription:

Application Note AN 126: Arduino UART Interface to K 30 Sensor Introduction The Arduino Uno, Mega or Mega2560 are ideal microcontrollers for operating SenseAir s K 30 or K 33 CO2 sensors using an industry standard UART TXD RXD connection. Two examples are described: 1. Basic Software.Serial is a library built into the Arduino software that can read CO2 levels only. 2. kseries.h A CO2Meter developed library which gives greater control of the sensor like calibration. It also allows you to access additional outputs on SenseAir s K 33 series (ELG, BLG, ICB) of sensors that include temperature and %RH. If you are new to Arduino hardware, these low cost development boards are available from many sources. We recommend you start with authentic Arduino products and the Basic example below. Run the Blink Example The best way to become familiar with the Arduino Graphical User s Interface (GIU) is to verify your Arduino board is operating properly. Create an Arduino project and run the example Blink. This simple test program confirms that a number of connection details and that the GUI are working properly. Caution: Do not connect the Arduino board to the USB port until the Arduino software is installed. Otherwise Windows will install a generic driver and the Arduino will not operate. Step 1: Install Arduino software on your computer. From this page select the Windows Installer. https://www.arduino.cc/en/main/software Step 2: To run the Blink example follow these instructions: https://www.arduino.cc/en/tutorial/blink Note that the MEGA Arduinos have a LED on board. The Arduino UNO may require a LED and resistor be added as specified in the tutorial. Once Blink runs properly, you can connect the K 30 or K 33 sensor. 1

ConnectingtheK30Sensor RefertothewiringdiagrambelowfortheArduinoUno orarduinomega2560.theconnectionsfor ArduinoMEGAareidenticaltotheMega2560. Important:A6 9VDC,500maorgreater,external powersupplyishighlyrecommendedsincethek 30 draws300+mawhensampling.connectthepower supplyasshown. 2

Creating an Arduino Project Example 1: Basic This example uses the Software.Serial driver which is built into the Arduino software. This statement SoftwareSerial K_30_Serial(12,13) Sets up a virtual serial port using pin 12 for Rx and pin 13 for Tx on both the UNO and MEGA boards. Demo file download instructions 1. Click on the following link or copy this URL to download the example code: www.co2meters.com/documentation/appnotes/an126-k3x-sensor-arduino-uart.zip 2. Save the example code to your hard drive. Inside the.zip file, navigate to the K30_basic.ino file in the example folder. Extract it from the.zip file. 3. Double click the K30_basic.ino file to open it in the Arduino GUI. It will start and ask the following: 4. Click on OK. Observe the Arduino project code is displayed. 5. Click on Sketch >> Verify/Compile. The project should compile without errors. 6. Verify that your Arduino board is recognized correctly: a. Click on Tools. Set Board to Arduino Uno or MEGA. b. Confirm that Processor matches your Arduino: Uno, MEGA or MEGA 2560. 7. Click on Upload. When done uploading, your project is now running in the Arduino board. 3

8. To view program operation, click on Tools >> Serial Monitor. 9. Observe the following: Note Appendix A contains the.txt version of Ardunio code. It is also available in the AN126 K3x sensorarduino uart.zip file. Example 2: kseries.h CO2Meter has written the kseries.h library to enable additional features beyond simply reading the current CO2 levels from the K 30 and K 33 series sensors. This library includes useful functions such as getco2(char format) gettemp(), getrh() chksensortype(), chkk33(), chkascii() Note that not all sensor functionality is implemented in this library. It is only used as an example of the most common functions. However, using this model, you can easily discover how to implement additional functions specific to each sensor by referring to the particular sensor s documentation on the CO2Meter.com website. Installing the Arduino library Like other Arduino libraries, this one is distributed as a folder in a.zip file. The name of the folder Kseries folder is the name of the library. Inside the folder will be.cpp (C++) files,.h file files, a keywords.txt file, and examples in the \example folder. Starting with Arduino version 1.0.5, this allows you to install our libraries in the IDE. 1. Click on the following link or copy this URL to download the example code: www.co2meters.com/documentation/appnotes/an126-k3x-sensor-arduino-uart.zip 4

Do not unzip the downloaded library, leave it as is. 2. Open the Arduino IDE, navigate to Sketch > Include Library. At the top of the drop down list, select the option to "Add.ZIP Library''. 3. Navigate to your Download directory and click on the AN126 K3x sensor arduino uart.zip file. The IDE will install the.h files, the.ccp files and additional necessary files. 4. From the zip file s \examples\k30_example_2 folder, double click K30example_2.ino to open it in the Arduino GUI. 5. The GUI will ask you to create a project folder. Click OK. Observe the Arduino project code is displayed. 6. Click on Sketch >> Verify/Compile. The project should compile without errors. 7. Verify that your Arduino board is recognized correctly: 1. Click on Tools. Set Board to Arduino Uno or MEGA. 2. Confirm that Processor matches your Arduino: Uno, MEGA or MEGA 2560. 8. Click on Upload. When done uploading, your project is now running in the Arduino board. 9. To view program operation, click on Tools >> Serial Monitor. Observe the output as follows: 5

Appendix: Example 1 K30_basic.ino // AN-126 Demo of K-30 using Software Serial #include <SoftwareSerial.h> /* Basic Arduino example for K-Series sensor Created by Jason Berger Co2meter.com */ #include "SoftwareSerial.h" SoftwareSerial K_30_Serial(12,13); //Sets up a virtual serial port //Using pin 12 for Rx and pin 13 for Tx byte readco2[] = 0xFE, 0X44, 0X00, 0X08, 0X02, 0X9F, 0X25; //Command packet to read Co2 (see app note) byte response[] = 0,0,0,0,0,0,0; //create an array to store the response //multiplier for value. default is 1. set to 3 for K-30 3% and 10 for K-33 ICB int valmultiplier = 1; void setup() // put your setup code here, to run once: Serial.begin(9600); //Opens the main serial port to communicate with the computer K_30_Serial.begin(9600); //Opens the virtual serial port with a baud of 9600 Serial.println(" Demo of AN-126 Software Serial and K-40 Sensor"); void loop() sendrequest(readco2); unsigned long valco2 = getvalue(response); Serial.print("Co2 ppm = "); Serial.println(valCO2); delay(2000); void sendrequest(byte packet[]) while(!k_30_serial.available()) //keep sending request until we start to get a response K_30_Serial.write(readCO2,7); delay(50); 6

int timeout=0; //set a timeout counter while(k_30_serial.available() < 7 ) //Wait to get a 7 byte response timeout++; if(timeout > 10) //if it takes too long there was probably an error while(k_30_serial.available()) //flush whatever we have K_30_Serial.read(); break; //exit and try again delay(50); for (int i=0; i < 7; i++) response[i] = K_30_Serial.read(); unsigned long getvalue(byte packet[]) int high = packet[3]; //high byte for value is 4th byte in packet in the packet int low = packet[4]; //low byte for value is 5th byte in the packet unsigned long val = high*256 + low; //Combine high byte and low byte with this formula to get value return val* valmultiplier; 7

Appendix: Example 2 K30_example_2.ino /* AN-126 Example 2 uses kseries.h Reports values from a K-series sensor back to the computer written by Jason Berger Co2Meter.com */ #include "kseries.h" //include kseries Library kseries K_30(12,13); //Initialize a kseries Sensor with pin 12 as Rx and 13 as Tx void setup() Serial.begin(9600); //start a serial port to communicate with the computer Serial.println("Serial Up!"); void loop() double co2 = K_30.getCO2('p'); //returns co2 value in ppm ('p') or percent ('%') Serial.print("Co2 ppm = "); Serial.println(co2); //print value delay(1500); //wait 1.5 seconds 8