\documentclass[12pt,oneside,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{fancyhdr}
\usepackage{graphics}
\usepackage{graphicx}
\usepackage{geometry}
\usepackage{multicol}
\usepackage{capt-of}
\usepackage[table]{xcolor}
\usepackage{hyperref} % for internal section links

% ONLY FOR DRAFT
\usepackage{draftwatermark}
\SetWatermarkText{PRELIMINARY}
\SetWatermarkScale{3}

% ONLY FOR TEMPLATE
\usepackage{blindtext}

%
% Sensor name definition 
%
\newcommand{\sensor}{IAQ01}

\pagestyle{fancy}
\fancyhf{}
%\fancyhead[LE,LO]{\includegraphics[scale=0.075]{./fig/VelesLabsLogo.png}}
%\fancyhead[RE,RO]{\sensor{}\\DATASHEET v. 1.0}
%\fancyfoot[LE,LO]{\leftmark}
%\fancyfoot[RE,RO]{\thepage}

\fancyhead[LO]{\includegraphics[height=1.0cm]{./fig/logo/PNGs/Long_Logo_One_Line_Text/veles_labs_logo_small_letters_transparent_600x185.png}}
\fancyhead[RO]{\sensor{}\\DATASHEET v. 1.0}
\fancyfoot[LO]{\leftmark}
\fancyfoot[RO]{\thepage}

\renewcommand{\headrulewidth}{2pt}
\renewcommand{\footrulewidth}{2pt}
\setlength{\headheight}{35pt}

\begin{document}
% TITLE PAGE
\begin{multicols*}{2}
\begin{center}
\includegraphics[width=0.45\textwidth]{./fig/iaq_wired_sensor.png}
\end{center}
\section*{Features}
\begin{itemize}
\setlength\itemsep{0cm}
\item Measures all important indoor air quality values: $\mathrm{CO_2}$, T, RH, VOC
\item Communicates via Modbus RTU (RS-485)
\item Wide input voltage range 5 - 30V
\item Indicates $\mathrm{CO_2}$ (carbon dioxide) level using LED for quick air quality assesment
\item Easy to setup using Raspberry Pi and open-source Veles Sensors python library
\item Carbon dioxide measurement range 0 - 40000 ppm 
\item Temperature range -40 - 125 °C
\item Relative humidity range 0 - 100 \%
\item VOC (volatile organic compounds) index range 1 - 500 VOC index points
\item Fully opensource
\end{itemize}
\vfill
\section*{Description}
\sensor{} is a wired indoor air quality sensor measuring temperature, relative humidity, carbon dioxide, and volatile organic compounds. Communication over RS-485 using Modbus RTU protocol makes it easy to interface with the sensor using PLC or any PC with RS-485 to USB converter. Open-source Python libraries are available to ease sensor configuration and readout using PC and embedded computers (e.g. Raspberry Pi).\\
\\
On-board RGB LED enables the user to quickly assess air quality with a single glance. Two quality-to-color schemes are available: continuous color change and tri-state (semaphore) mode. The thresholds for color change are user-configurable.\\
\\
A wide input voltage range makes it possible to integrate the sensor with many different systems, ranging from house-wide 12V bus to 5V USB connected to a local computer.\\
\\
The extended version of this sensor \sensor{}-PM adds the option of particulate matter (dust) measurement.\\
\\
Fully open-source ecosystem: sensor hardware, case, firmware, and connected Python libraries are open-sourced under permissive licensing.\\
%\\
%Can be used in many applications such as monitoring of home and office spaces, ventilation control or for smart greenhouse applications.
\end{multicols*}
\vfill
\pagebreak

\tableofcontents
\listoffigures
\listoftables

\pagebreak

\section{Specifications}
\subsection{Electrical Specifications}
\begin{table}[h]
\scriptsize
\begin{tabular}{|p{5cm}|p{2cm}|p{1cm}|p{1cm}|p{1cm}|p{1cm}|}
\hline
\rowcolor{lightgray}\textbf{Parameter}                       							& \textbf{Symbol} 	& \textbf{Min.} 	& \textbf{Typ.} 	& \textbf{Max.} 	& \textbf{Unit} 		\\ \hline
Input voltage                                 							& $\mathrm{V_{DD}}$        		& 5             		& 12            		& 24            			& V             			\\ \hline
Average supply current                        					& $\mathrm{I_{DD}}$        		&               		&             		&               		50	& mA            			\\ \hline
RS485 Single-Ended Output High                				& $\mathrm{V_{OH}}$        		& 2.2           		&               		&               			& V             			\\ \hline
RS485 Single-Ended Output Low                 				& $\mathrm{V_{OL}}$        		&               		&               		& 0.8           			& V             			\\ \hline
RS485 Differential Output                     					& $\mathrm{V_{OD}}$        		& 2.0           		&               		&               			& V             			\\ \hline
RS485 Receiver Differential Threshold Voltage 		& $\mathrm{V_{TH}}$        		& -200          		& -105          		& -10           			& mV            			\\ \hline
\end{tabular}
\normalsize
\caption{Electrical Specifications}
\label{tab:specifications_electrical}
\end{table}
\vfill
\subsection{Sensing Specifications}
\begin{table}[h]
\scriptsize
\begin{tabular}{|p{5cm}|p{3cm}|p{4.25cm}|}
\hline
\rowcolor{lightgray}\textbf{Parameter}                       							& \textbf{Conditions} 					& \textbf{Value} 										\\ \hline
CO$_2$ measurement range                              		& \multicolumn{1}{c|}{-}           	& 0 $\div$ 40000 ppm								\\ \hline
CO$_2$ measurement accuracy                        		&  400 ppm – 2000 ppm 	       		& ($\pm$50 ppm + 5\% of reading)          	\\ \hline
CO$_2$ measurement repeatability                          & Typical           		      					& $\pm$10 ppm											\\ \hline
T measurement range                								&  \multicolumn{1}{c|}{-}             &  –40 $\div$ +125 $^{\circ}$C       			\\ \hline
T measurement accuracy                 						&  Typical                         				& $\pm$0.2 $^{\circ}$C         					\\ \hline
T measurement repeatability                 					&  Typical                         				& $\pm$0.2 $^{\circ}$C         					\\ \hline
RH measurement range                    						&  \multicolumn{1}{c|}{-}             & 0 $\div$ 100 \%RH            						\\ \hline
RH measurement accuracy 									&  Typical        	          					& $\pm$1.8 \%RH           							\\ \hline
RH measurement repeatability 								&  \multicolumn{1}{c|}{-}        	    	& $\pm$0.08 \%RH           							\\ \hline
\end{tabular}
\normalsize
\caption{Sensing Specifications}
\label{tab:specifications_sensing}
\end{table}
\vfill

\subsection{Interface Specifications}
\begin{table}[h]
\scriptsize
\begin{tabular}{|p{3.75cm}|p{9cm}|}
\hline
\rowcolor{lightgray}\textbf{Parameter}                       							& \textbf{Value} 							\\ \hline
Used Protocol						                              		& Modbus RTU           					\\ \hline
Default Baudrate                        								&  19200 Baud 	       						\\ \hline
Usable  Baudrates                      								&  4800, 9600, 14400, 19200,  28800, 38400, 57600, 76800, 119200 Baud 	      \\ \hline
Data Bytes                          									& 8           		      							\\ \hline
Parity                														&  Even             								\\ \hline
Stop Bits                 												&  1                         						\\ \hline
\end{tabular}
\normalsize
\caption{Sensing Specifications}
\label{tab:specifications_interface}
\end{table}
\vfill
\pagebreak

\subsection{Connectors Pinout}
\subsubsection{Main Connector Pinout}
The main connector is the Sullins Connector Solutions SWR204-NRTN-D02-RA-GA connector. The matching connector for the cable is SWH204-NULN-D02-UU-WH with SWT204-UPTN-S01-UU-UU crimping pins.\\
The pinout can be seen in figure \ref{fig:connector_pinout} and table \ref{tab:connector_pinout}.
\begin{figure}[h]
\begin{minipage}[c]{0.5\linewidth}
	\centering
	\includegraphics[width=0.5\textwidth]{./fig/connector_pins.png}
	\caption{Main Connector Pinout}
	\label{fig:connector_pinout}
\end{minipage}
\begin{minipage}[c]{0.5\linewidth}
	\centering
		\scriptsize
	\begin{tabular}{|p{0.75cm}|p{1.25cm}|p{3cm}|}

		\hline
\rowcolor{lightgray}\textbf{Pin} & \textbf{Name} & \textbf{Description} \\ \hline
		1 & VDD & Supply Voltage \\ \hline
		2 & A & RS485 A+ \\ \hline
		3 & B & RS485 B- \\ \hline
		4 & GND & Ground \\ \hline
	\end{tabular}
	\captionof{table}{Main Connector Pinout}
	\label{tab:connector_pinout}
\end{minipage}
\end{figure}

\subsubsection{Programming Connector Pinout}
The sensor can be programmed through the Serial Wire Debug (SWD) interface using an ST-Link. ST-Link can be connected to the sensor using pads for spring-loaded pins in the bottom layer of the PCB. 
The pinout can be seen in table \ref{tab:swd_connector_pinout}. The first pin of the connector is marked with a square pad.
\begin{table}[h]
\scriptsize
	\centering
	\begin{tabular}{|p{0.75cm}|p{1.55cm}|p{3cm}|}
		\hline
\rowcolor{lightgray}		\textbf{Pin} & \textbf{Name} & \textbf{Description} \\ \hline
		1 & 3V3 & 3.3V Sensing \\ \hline
		2 & GND & Ground \\ \hline
		3 & SWDIO & SWD Data \\ \hline
		4 & SWCLK & SWD Clock \\ \hline
		5 & NRST & MCU Reset \\ \hline
	\end{tabular}
	\caption{Programming Connector Pinout}
	\label{tab:swd_connector_pinout}
\end{table}

\section{Communication Specification}

For the physical layer, RS-485 is used. This allows the communication to be robust and resistant to EMI (electro-magnetic interference). On top of the physical layer, Modbus RTU is used as a data link layer. This protocol is widely supported by the number of PLCs and other devices. To interface with a PC (or any computer with a USB port), a USB to RS485 converter may be used in conjunction with the Veles Sensors python library.

\subsection{Physical Layer - RS485}

RS-485 is a full-duplex serial bus, ideally suited for low-speed, noise-resistant communication over long distances (up to 1200 m - more if repeaters are used). Linear bus topology is preferable over star or ring configurations. To prevent signal reflections, each sensor is equipped with a 120 $\Omega$ termination resistor. Therefore, the optimal cable for connecting sensors to each other and to the master node is a twisted pair cable with 120 $\Omega$ characteristic impedance.

\subsection{Data Link Layer - Modbus RTU}

Modbus is a well-tested, openly-published, and royalty-free data communications protocol. Developed for industrial applications, it aims to be simple and robust. It is a client/server (master/slave) type protocol. The maximum number of client nodes on a Modbus bus is 247.

A limitation of Modbus-based buses is that there is no arbitration in case of address conflict. This means that nodes should be either added one by one or node addresses should be configured beforehand.

Address 0 can be used as a broadcast message (e.g. instructing all sensors to turn off LED). No slave response is generated.

\subsubsection{Modbus register space}

Modbus supports four types of registers:

\begin{table}[h]
\scriptsize
	\centering
	\begin{tabular}{|p{3cm}|p{3cm}|p{3cm}|p{3cm}|}
		\hline
		\rowcolor{lightgray}		\textbf{Object type} & \textbf{Access} & \textbf{Size} & \textbf{Address space} \\ \hline
		Coil             & read / write & 1 bit   & 00001 - 09999 \\ \hline
		Discrete input   & read         & 1 bit   & 10001 - 19999 \\ \hline
		Input register   & read         & 16 bits & 30001 - 39999 \\ \hline
		Holding register & read / write & 16-bits & 40001 - 49999 \\ \hline
	\end{tabular}
	\caption{Modbus register space}
	\label{tab:modbus_register_space}
\end{table}
\vfill

\pagebreak
\subsection{\sensor{} Modbus registers}

\subsubsection{Input registers}

Input registers contain measured values. They are read-only and 16-bit in size.

\begin{table}[h]
	\scriptsize
		\centering
		\begin{tabular}{|p{4cm}|p{2.5cm}|p{2cm}|p{3.6cm}|}
			\hline
		\rowcolor{lightgray}		\textbf{Register name} & \textbf{Register address} & \textbf{Unit} & \textbf{Note} \\ \hline
		Serial Number HI						& 30001 & - & \\ \hline
		Serial Number LO					& 30002 & - & \\ \hline
		Temperature                          & 30003 & °C     & \\ \hline
		Temperature                          & 30004 & °F            & \\ \hline
		Relative humidity                  & 30005 &  \%           & \\ \hline
		$\mathrm{CO_2}$ concentration           & 30006 & ppm           & \\ \hline
		VOC index                               & 30007 & VOC index     & see \hyperref[inputReg:note1]{Note 1} \\ \hline
		VOC ticks                                & 30008 & raw VOC ticks & raw value from VOC sensor \\ \hline
		PMC Mass 1.0						  & 30009 & TODO & if connected \\ \hline
		PMC Mass 2.5						  & 30010 & TODO & if connected \\ \hline
		PMC Mass 4.0						  & 30011 & TODO & if connected \\ \hline
		PMC Mass 10.0						  & 30012 & TODO & if connected \\ \hline
		PMC Number 0.5			    	  & 30013 & TODO & if connected \\ \hline
		PMC Number 1.0			    	  & 30014 & TODO & if connected \\ \hline
		PMC Number 2.5			    	  & 30015 & TODO & if connected \\ \hline
		PMC Number 4.0			    	  & 30016 & TODO & if connected\\ \hline
		PMC Number 10.0		    	  & 30017 & TODO & if connected \\ \hline
		Temperature from $\mathrm{CO_2}$ sensor & 30019 & °C            & \\ \hline
		Temperature from $\mathrm{CO_2}$ sensor & 30020 & °F            & \\ \hline
		RH from $\mathrm{CO_2}$ sensor          & 30021 & \%            & \\ \hline
		\end{tabular}
		\caption{Modbus input registers for \sensor{}}
		\label{tab:modbus_input_registers}
\end{table}

\paragraph{Note 1}
\label{inputReg:note1}
The VOC index has a range of 1-500 with 100 being the average. After sensor start-up, the VOC index is 0 until a sufficient amount of data has been measured.

\subsubsection{Holding registers}

The holding registers can be written to by the master node. Sensor \sensor{} offers the following configuration registers:

\begin{table}[h]
	\scriptsize
		\centering
		\begin{tabular}{|p{4cm}|p{2cm}|p{6.5cm}|}
			\hline
			\rowcolor{lightgray}		\textbf{Register name} & \textbf{Address} & \textbf{Note} \\ \hline
			Device Modbus address              & 40001 & see \hyperref[holdingReg:note2]{Note 4} \\ \hline
			Modbus baudrate                    & 40002 & see \hyperref[holdingReg:note2]{Note 5} \\ \hline
			LED on                             		& 40003 & set to 0 to turn off LED; set to 1 to turn LED on  \\ \hline
			LED brightness                    & 40004 & range from 0 (off) to 100 (full intensity)  \\ \hline
			LED smooth                         & 40005 & see \hyperref[holdingReg:note1]{Note 1}  \\ \hline
			$\mathrm{CO_2}$ alert limit 1      & 40006 & see \hyperref[holdingReg:note2]{Note 2} \\ \hline
			$\mathrm{CO_2}$ alert limit 2      & 40007 & see \hyperref[holdingReg:note2]{Note 2} \\ \hline
			$\mathrm{CO_2}$ temperature offset & 40008 & see \hyperref[holdingReg:note2]{Note 3} \\ \hline
			Reset device                       & 49999 & see \hyperref[holdingReg:note2]{Note 6} \\ \hline
		\end{tabular}
		\caption{Modbus holding registers for \sensor{}}
		\label{tab:modbus_holding_registers}
\end{table}

\paragraph{Note 1}
\label{holdingReg:note1}
Setting LED smooth register to 1 will turn on LED color interpolation, meaning the LED will have color in a continuous spectrum from green to red according to the $\mathrm{CO_2}$ level. Setting this register to 0 will turn off interpolation and set the LED to semaphore (tri-state) mode. Depending on $\mathrm{CO_2}$ level, the LED color will then be either green, yellow, or red.

\paragraph{Note 2}
\label{holdingReg:note2}
Registers $\mathrm{CO_2}$ alert the limit 1 and 2 set thresholds for LED color change (see \hyperref[holdingReg:note1]{Note 1}). Limit 1 is the threshold between green and yellow color; limit 2 is the threshold between yellow and red color.

\paragraph{Note 3}
\label{holdingReg:note3}
SCD41 is the $\mathrm{CO_2}$ sensing device used in the \sensor{} sensor. It is also able to measure temperature, however it may be subject to offset due to internal heating of SCD41. This register allows the user to compensate for this offset.

\paragraph{Note 4}
\label{holdingReg:note4}
Device Modbus address may be changed by writing to this register. The allowed values are in the range of 1 to 247. The device will start using a new address immediately and cease to respond at the previous address. Reset is not needed. It is the responsibility of the user to prevent address collisions on a bus.

\paragraph{Note 5}
\label{holdingReg:note5}
Modbus baudrate in bits/s. May be one of: 4800, 9600, 14400, 19200, 28800, 38400, 57600, 76800, 115200. Please be aware that lower baudrates are more reliable for long distance communication.

\paragraph{Note 6}
\label{holdingReg:note6}
Writing the magic constant 0xABCD to this device will instruct the device to soft-reset.
\vfill
\section{Mechanical Dimesions}
\includegraphics[scale=0.75]{./fig/IAQ_Sensor_Enclosure-Enclosure_TOP.pdf}
\pagebreak
\section{Schematic}
\includegraphics[angle=90,origin=c,scale=0.7]{./../../PCB/Project_Outputs/Schematic/iaq_wired_sensor.pdf}
\end{document}