This example has simple code for reading temperature from a thermocouple click board and also an application that sends temperature data to Initial State.
Plug the click board into the mikroBUS header on the Fieldbus Gateway. This example code uses the hardware.spiBCAD peripheral exposed by the mikroBUS header.
Please note: This example code can be modified for use with a different imp by simply changing the spi configuration. MOSI is not necessary to read the thermocouple.
This example shows how to read temperature from a thermocouple click board and log the result. It shows how to configure the SPI and has one function readThermoCoupleTemp(), which will return the temperature as an integer. The thermocouple runs on 3.3v. The range of the thermocouple is -270 to 1372 degrees celsius.
This example has side device code only.
- Navigate to the Electric Imp IDE
- Copy and paste the BasicUsageThermocoupleExample.device.nut file into the divice code window in the IDE
- Hit Build and Run to start the code
This example sends temperature data read from a thermocouple click board to the cloud service Initial State.
The device code builds on the Basic Usage example to create a Thermocouple class. It uses the FiedbusGateway HAL (Hardware Abstraction Layer) to configure the hardware. The example then uses an Application class to read temperature from the Thermocouple and send it to the agent in a loop. The application also sets up a listener that recieves a blink message from the agent that will blink one of the LEDs on the Fielbus Gateway.
The Agent code listens for temperature readings from the device. When a reading is received the temperature is checked to see if it is above a threshold. Then both the tempertature and temperatureAlert are sent to Initial State. When the data is received by Initial State a blink message is then sent to the device.
- Navigate to the Electric Imp IDE
- Copy and paste the SimpleApplicationThermocouleExample.device.nut file into the divice code window in the IDE
- Copy and paste the SimpleApplicationThermocouleExample.agent.nut file into the agent code window in the IDE
- Sign into Initial State
- Find your Streaming Access Key on the My Account page
- Navigate to back to the Electric Imp IDE
- In the Agent code enter your Initial State Streaming Access Key into the Application class static STREAMING_ACCESS_KEY variable
- Hit Build and Run to start the code