Using Bluetooth to build a wireless data logger for your industrial application -

Using Bluetooth to build a wireless data logger for your industrial application


Over the last five years, Bluetooth's growth has been undeniablyphenomenal. However, most consumers still think of Bluetooth as awireless communication medium for cellphones to talk to headsets.

Although this is still largely true, Bluetooth is finding its wayinto more routine forms of communication such as industrial data logging.

This article discusses the design of a Bluetooth data logger thattakes data from an AS1530 12bit ADC via an MCU and a Bluetooth link toa PC, which collects the data in a spreadsheet.

The trend in industrial process control has been toreduce the communications wiring across a plant with parallel data,paving the way for serial “Profibus” data. Thisdesign extrapolatesthat trend and completely removes the communications wiring.

The data logger circuit has an AS1530 ADCconnected to a PIC MCUthat communicates via an RS-232 cable to a BlueGigaWT12 Bluetoothmodule. This module transmits data over the Bluetooth link to asecondidentical BlueGiga WT12 module connected via an RS-232 cable to a PCrunning a Windows program written in Visual Basic Version 6 (Figure 1 below ). The Windows programloads the received data into an Excel spreadsheet for results to beanalyzed and graphed.

The data logger is powered from a 5V bench power supply. To ensuresafe operation of the MCU, the logger power supply is monitored using avery lowpower supervisor, the AS1904.

This device typically consumes 150 nA of supply current. The currentconsumption of the data logger circuit is measured at 16mA, and theaverage current consumption of the BlueGiga module is specified as44.7mA. So if the whole circuit has to be powered from a linear regulator, an AS13985150mA low dropout linear regulator would more than suffice.

Analog front-end
The analog front-end consists of a 12 bit successiveapproximation register(SAR)ADC such as the AS1230. If the input signal is less than the supplyvoltage of the ADC (in this case, 5V) and of suitably low sourceimpedance, it can be fed directly into the ADC's input.

The ADC's input circuit can be modeled as a simple RC circuit ,with R representing the source impedance of the signal and C thesampling capacitor of the ADC. An RC circuit under charge isrepresented by the equation:

where Vmax is the charging voltage and V is the voltageacross the capacitor. The sampling capacitor is 18pF and the samplingtime (t) is 390ns.

Now, the worst-case change in voltage that the ADC input has to dealwith is when one input channel is set at 0V, and the adjacent channelis set at 2.5V. In this case, the input capacitor has to charge to 2.5Vwithin an accuracy of half LSB in 390ns.

This yields a minimum source impedance of R = 2.4 kohms. Now, theinput impedance of the mux is 800 ohms, so the source impedance of thesignal has to be less than 1.6 kohms. If the source impedance of thesignal to be digitized is too high, it can be amplified and/or bufferedusing an op amp.

The PIC16F627 MCU reads datainto and out of the AS1530 using an SPI with a chip select (CSN),serial clock (SCLK), data input (Din) and data output (Dout). The CSNline frames the data, while data is clocked into and out of the deviceusing the rising edge of the SCLK line.

The data stream is made up of eight control bits that select theinput channel, the input range and the power mode, and 16 subsequentbits that contain the output data. Once the conversion is completed,the ADC goes into its programmed power mode (full power down, reducedpower or normal operation).

To achieve the desired accuracy, pay close attention to the boardlayout and decoupling of the supply pins to the chip and the reference.The analog and digital supplies must be kept separate, although bothsupplies can originate from the same source.

This is best achieved by routing two tracks from the main boardsupply, a thick track to the analog supply (pins VDD1 and VDD3) and thesame for the digital (pin VDD2). The current taken by the digitalsupply modulates a voltage onto the digital supply line.

If this also powers the analog supply to the chip, this voltagemodulation could corrupt the LSBs of the ADC. Providing separatesupplies eliminates this problem.

The ground supply to the AS1530 is just as important as the analogand digital supplies. A thick track running from the GND pin to themain board supply ground provides low impedance for the return currentand is essential for best performance.

Decoupling capacitors should be placed close to each of the analogand digital supply pins of the chip, with their ground connectionsclose to the GND pin of the AS1530. This ensures that the AC voltageseen across the power supply pins of the chip remains at zero.

A 10 microfarad tantalum capacitor in parallel with a 100nanofarad ceramic provides optimum broadband attenuation of any noise,which may appear on the line and provide a low impedance path for anycurrent surges that may be demanded by the AS1530.

This design uses the internal reference of the AS1530. If anexternal reference is desired, it needs to be decoupled with a locallow-impedance capacitor of 4.7 microfarads close to the REF pin. Theinput impedance to the reference pin of a SAR ADC changes with digitalcode due to it being connected directly to the R-2R ladder.

Figure1. The program replicates Microsoft HyperTerminal and handles thesearch, connection and disconnection of the link with the data logger.

Software end
At the data logger end, the MCU is a PIC16F627A. Its code is written inC using a Hi-Tech C compiler . The MCU's internal UART is set to a baud rate of115.2Kbps to match the default baud rate of the Bluetooth module. Datais sent over the RS-232 link via an industry standard (2Tx/2Rx) leveltranslator.

All communications to the Bluetooth modules are done over an RS-232interface. As with many things in life, the simple aspects can causethe most hardship, and RS-232 is no exception.

In the days when the RS-232 specification waswritten, computers were called terminals and they sometimes linked tocommunication devices like modems. Hence, it was decreed that two typesof equipment could be used to connect to each other using the RS-232standard.

These were the data terminal equipment (DTE) and data communicationequipment (DCE). It was not surprising that computers (or terminals)were configured as DTE, and most devices that connect to them wereconfigured as DCE (like modems).

They were mostly connected using a standard nine-way RS-232 cable,with each pin at one end connected through its associated pin at theother end. No wires cross over inside the cable.

Now, DTE sends data out on pin 3 and receives it on pin 2. On theother end, DCE receives data on pin 3 and transmits on pin 2. There aretwo other signals used in 90 percent of the RS-232 applications: readyto send (RTS) and clear to send (CTS).

Putting Bluetooth to work
Both devices at each end of the cable have an RTS and a CTS signal. TheRTS at one end connects directly to the CTS at the other end and viceversa. The RTS is an outgoing signal, while the CTS is an incomingsignal.

Before any data is sent, both ends set their RTS lines (as they areboth free to send and receive data). If the transmitter asserts RTS,this in turn asserts the CTS line at the receiver since they aredirectly connected.

When the transmitting device starts to send data, it de-asserts itsRTS line, hence de-asserting the CTS of the receiver. De-asserting theCTS tells the receiver that it is not clear to send data. This tellsthe receiver to hold off transmitting any information.

If the transmitter sends too much information (and overloads thereceiver), the receiver is free to de-assert its RTS line (de-assertingthe CTS line of the transmitter) to indicate the transmitter to stop.

The Bluetooth module is configured as DCE, so the MCU at the AS1530end is configured as DTE. Thus, it transmits its data on pin 3 andreceives it on pin 2. It also uses RTS/CTS handshaking, transmits RTSon pin 7 and receives CTS on pin 8 of the nine-way connector.

It should be noted that if the MCU is to be connected toHyperTerminal on the PC (for testing), the Tx and Rx lines need to beswapped over, as do the RTS and CTS lines. This converts the MCU fromDTE to DCE.

A standard RS-232 level translator was used to interface the MCUwith the RS-232 data line. It should also be noted that a carriagereturn is needed at the end of every command sent to the Bluetoothmodule.

This simple instruction is overlooked when typing on a keypad. If itis not sent, the designer will have hours of undeserved diagnostics asto why the module is not behaving itself.

Programming the Bluetoothmodule
The Bluetooth module has the facility to be programmed with a”friendly” name, allowing other Bluetooth devices to identify it bysomething other than its 12- digit hex address. When the data loggerpowers up, the 16F627A programs the Bluetooth module at the data loggerend to have a “friendly” name of AMS_ADC.

The Windows program was written in Visual Basic Version6. The program replicates Microsoft HyperTerminal and handles thesearch, connection and disconnection of the link with the data logger. Figure 1 earlier shows the Windowsscreen.

The text screen in Figure 1 shows the message from the Bluetooth module once it has been reset. Onthe left are the controls needed to communicate with the Bluetoothmodule. After reset, the user clicks the Inquiry button, which tellsthe Bluetooth module to send out an inquiry looking for all localBluetooth devices (Figure 2 below ).

Figure2. After reset, the user clicks the Inquiry button, which tells theBluetooth module to send out an inquiry looking for all local Bluetoothdevices.

Clicking the Inquiry button writes the text “INQUIRY 10 NAME” to theBluetooth module, telling it to wait for 10s before timing out andinquiring for all the “friendly” names of the local Bluetooth devices.

The Bluetooth module then echoes back how many devices are found,their 12-digit hex address and friendly names. It can be seen that thedevice AMS_ADC has an address 00:07:80:80:c2:11.

The user highlights this address and copies it to the Address:window. By clicking the Call button, the Windows program sends out aCALL command to this address, and this is shown by the line: CALL00:07:80:80:c2:11 1 RFCOMM.

The Bluetooth device echoes back with a CALL 0 statement, tellingthe user that a CALL has been initiated. Once communication with theremote logger has been established, a CONNECT statement is returned.

Once a connection is established, all future text is generated bythe data logger and not the Bluetooth module. The data logger thensends out the text “LOGGER CONNECTED” to show that communication hasbeen established with the AS1530. The Windows program also opens a filecalled C:AMS_ADC.xls and loads the received data into it.

The user then clicks the Start Logging button to clear the screenand switch the program to receive data and not text. All future datareceived is loaded into the C:AMS_ADC.xls file.

The Windows program also allows the users to override the commandbuttons and enter their own text. The Clear Window button is clicked toclear the text screen. Entering text in the text screen and thenclicking the Manual Text Entry button downloads all the text on thetext screen to the Bluetooth module.

Clicking the Close Link button sends the command “+++” to theBluetooth module, telling it to terminate the link. The Bluetoothmodule then drops the link and returns a message telling the user thelink has been lost.

Figure3. The data logger circuit has an AS1530 ADC connected to a PIC MCUthat communicates via an RS-232 cable to a BlueGiga WT12 Bluetoothmodule.

Figure 3 above shows thecircuit diagram of the data logger end. The PC end is simply a BlueGigaWT12 evaluation kit connected to the PC via an RS 232 cable.

The software has been written in a way that enables easy expansionof the system to allow the user to interrogate multiple data loggers.

The software in the data logger can be improved to enable it tobetter handle commands from the host PC. Thus, it enables the PC to setthe friendly name, and the user to poll and/or reset the system.

Simon Bramble is austriamicrosystems NorthEuropean Applications Engineer. For a PDF version of this story, go to “Datalogging goes wireless.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.