This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:iot-open:remotelab:ume:arancino [2019/10/01 16:01] – salvatdi | en:iot-open:remotelab:ume:arancino [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 5: | Line 5: | ||
| ==== Introduction ==== | ==== Introduction ==== | ||
| - | Its main goal is to provide a single-node testbed consisting of a next-generation “combo” board, a.k.a. Single-Board Computer (SBC) mainly focusing on smart environment monitoring scenarios. To this purpose, 1 node has been equipped and made available to students for practicing in these contexts. This node is a combo SBC which combines onto the same node a so-called “carrier board”, in this case an Arancino™ by smartme.IO, with an Arduino-like MCU (based on an ARM Cortex M0+ @48MHz) built-in, hosting a Raspberry Pi 3 Compute Module (CM3). In this section, we will focus on this Arancino node and its sensors/ | + | Its main goal is to provide a single-node testbed consisting of a next-generation “combo” board, a.k.a. Single-Board Computer (SBC) mainly focusing on smart environment monitoring scenarios. To this purpose, 1 node has been equipped and made available to students for practicing in these contexts. This node is a combo SBC which combines onto the same node a so-called “carrier board”, in this case, an Arancino(TM) by smartme.IO, with an Arduino-like MCU (based on an ARM Cortex M0+ @48MHz) built-in, hosting a Raspberry Pi 3 Compute Module (CM3). In this section, we will focus on this Arancino node and its sensors/ |
| ==== Prerequisites ==== | ==== Prerequisites ==== | ||
| Line 34: | Line 34: | ||
| The BME680 is a (combined) digital gas, humidity, pressure, and temperature sensor based on proven sensing principles. | The BME680 is a (combined) digital gas, humidity, pressure, and temperature sensor based on proven sensing principles. | ||
| The humidity sensor provides an extremely fast response time for fast context awareness applications and high overall accuracy over a wide temperature range. The pressure sensor is an absolute barometric pressure sensor with extremely high accuracy and resolution. | The humidity sensor provides an extremely fast response time for fast context awareness applications and high overall accuracy over a wide temperature range. The pressure sensor is an absolute barometric pressure sensor with extremely high accuracy and resolution. | ||
| - | The integrated temperature sensor has been optimized for lowest noise and highest resolution. Its output is used for temperature compensation of the pressure and humidity sensors and can also be used for estimation of the ambient temperature. | + | The integrated temperature sensor has been optimized for the lowest noise and highest resolution. Its output is used for temperature compensation of the pressure and humidity sensors and can also be used for estimation of the ambient temperature. |
| The gas sensor within the BME680 can detect a broad range of gases to measure indoor air quality for personal well being. Gases that can be detected by the BME680 include Volatile Organic Compounds (VOC) from paints (such as formaldehyde), | The gas sensor within the BME680 can detect a broad range of gases to measure indoor air quality for personal well being. Gases that can be detected by the BME680 include Volatile Organic Compounds (VOC) from paints (such as formaldehyde), | ||
| Line 58: | Line 58: | ||
| ==== Actuators ==== | ==== Actuators ==== | ||
| - | There are no mechanical actuators or displays in this laboratory. The node is nevertheless equipped with three LEDs, including an MCU-controlled one. By default, i.e., after MCU reset (which may be triggered by quick double-click on the corresponding button) the aforementioned LED starts “breathing”, | + | There are no mechanical actuators or displays in this laboratory. The node is nevertheless equipped with three LEDs, including an MCU-controlled one. By default, i.e., after MCU reset (which may be triggered by quick double-click on the corresponding button) the aforementioned LED starts “breathing”, |
| ==== Power supply ==== | ==== Power supply ==== | ||
| The node is powered by an external DC (5V) power supply over USB. | The node is powered by an external DC (5V) power supply over USB. | ||
| - | Software, libraries and externals | + | Software, libraries, and externals |
| The following libraries are required to run the example proposed below for the hands-on labs: | The following libraries are required to run the example proposed below for the hands-on labs: | ||
| * SPI | * SPI | ||
| Line 151: | Line 151: | ||
| The digital pins either give you 5V (when turned HIGH) or 0V (when turned LOW) and the output is a square wave signal. | The digital pins either give you 5V (when turned HIGH) or 0V (when turned LOW) and the output is a square wave signal. | ||
| PWM stands for Pulse Width Modulation and it is a technique used in controlling the brightness of the LED. The PWM pins are labelled with ~ sign. | PWM stands for Pulse Width Modulation and it is a technique used in controlling the brightness of the LED. The PWM pins are labelled with ~ sign. | ||
| - | The function analogWrite() can be used to generate a PWM signal in those digital pins that are labelled with ~ sign. The frequency of this generated signal for most pins will be about 490Hz and you can give the value from 0-255 using this function. | + | The function analogWrite() can be used to generate a PWM signal in those digital pins that are labelled with ~ sign. |
| - | analogWrite(0) means a signal of 0% duty cycle. | + | The frequency of this generated signal for most pins will be about 490Hz and you can give the value from 0-255 using this function. |
| - | analogWrite(127) means a signal of 50% duty cycle. | + | |
| - | analogWrite(255) means a signal of 100% duty cycle. | + | |
| + | | ||
| The function random() generates pseudo-random numbers. The syntax is random(max) or random(min, max), where min represents the lower bound of the random value, inclusive (optional); and max represents the upper bound of the random value, exclusive. The function returns a long random number between min and max-1. | The function random() generates pseudo-random numbers. The syntax is random(max) or random(min, max), where min represents the lower bound of the random value, inclusive (optional); and max represents the upper bound of the random value, exclusive. The function returns a long random number between min and max-1. | ||
| Line 164: | Line 165: | ||
| Initialize the LCD screen with the label “rand value”, then calculates a random value. If randomValue is lower than lowThreshold, | Initialize the LCD screen with the label “rand value”, then calculates a random value. If randomValue is lower than lowThreshold, | ||
| - | Result | + | |
| + | ==== Result | ||
| You should see the LED on or off for 1 second, a second if the value is greater or less than the predefined threshold values. Next, you should see the randomly calculated value between 0 and 255 on the LCD, at that point, the LED should assign a brightness associated with that value, and keep it for 3 seconds. | You should see the LED on or off for 1 second, a second if the value is greater or less than the predefined threshold values. Next, you should see the randomly calculated value between 0 and 255 on the LCD, at that point, the LED should assign a brightness associated with that value, and keep it for 3 seconds. | ||
| - | Start | + | |
| + | ==== Start ==== | ||
| There are no special steps to be performed. | There are no special steps to be performed. | ||
| - | Steps | + | ==== Steps ==== |
| - | Step 1 | + | |
| + | === Step 1 === | ||
| Include required libraries: | Include required libraries: | ||
| + | <code c> | ||
| #include < | #include < | ||
| #include < | #include < | ||
| Line 177: | Line 185: | ||
| #include < | #include < | ||
| #include < | #include < | ||
| - | + | </ | |
| and define a number of directives: | and define a number of directives: | ||
| + | |||
| + | <code c> | ||
| #define DEBUG true // enable debug | #define DEBUG true // enable debug | ||
| #define BME_SCK 13 | #define BME_SCK 13 | ||
| Line 184: | Line 195: | ||
| #define BME_MOSI 11 | #define BME_MOSI 11 | ||
| #define BME_CS 10 | #define BME_CS 10 | ||
| - | |||
| #define SEALEVELPRESSURE_HPA (1013.25) | #define SEALEVELPRESSURE_HPA (1013.25) | ||
| - | + | </ | |
| Declare the sensor(s) object, a number of useful vars and constants, and assign them (e.g., initial) values when required: | Declare the sensor(s) object, a number of useful vars and constants, and assign them (e.g., initial) values when required: | ||
| - | Adafruit_BME680 bme680_sensor; | + | |
| - | + | <code c> | |
| + | Adafruit_BME680 bme680_sensor; | ||
| // Used here to set a pin number: | // Used here to set a pin number: | ||
| - | const int ledPin = LED_BUILTIN; | + | const int ledPin = LED_BUILTIN; |
| - | + | int ledState = LOW; // ledState used to set the LED | |
| - | int ledState = LOW; // ledState used to set the LED | + | unsigned long previousMillis = 0; // will store last time LED was updated |
| - | + | ||
| - | unsigned long previousMillis = 0; // will store last time LED was | + | |
| - | //updated | + | |
| unsigned long currentMill=0; | unsigned long currentMill=0; | ||
| - | + | const long interval = 150; // interval at which to blink (milliseconds) | |
| - | const long interval = 150; // interval at which to blink | + | |
| - | // | + | |
| - | + | ||
| float humidity_read; | float humidity_read; | ||
| float temperature_read; | float temperature_read; | ||
| - | float pressure_read; | + | float pressure_read; |
| - | + | unsigned long previousMillisTemp = 0; // environment reading interval | |
| - | unsigned long previousMillisTemp = 0; // environment reading | + | const long intervalTemp = 400; // interval at which to blink(milliseconds) |
| - | // interval | + | </ |
| - | const long intervalTemp = 400; // interval at which to blink | + | |
| - | // | + | |
| Functions declarations cannot be omitted (when using .cpp extension instead of .ino one): | Functions declarations cannot be omitted (when using .cpp extension instead of .ino one): | ||
| + | |||
| + | <code c> | ||
| void bme680_begin(); | void bme680_begin(); | ||
| void bme680_read(); | void bme680_read(); | ||
| void blink_status(); | void blink_status(); | ||
| + | </ | ||
| - | Step 2 | + | === Step 2 === |
| - | Functions definitions for: BME680 sensor initialization and settings configuration (bme680_begin()); | + | |
| + | Functions definitions for: BME680 sensor initialization and settings configuration ('' | ||
| + | |||
| + | <code c> | ||
| void bme680_begin(){ | void bme680_begin(){ | ||
| if(!bme680_sensor.begin()) { | if(!bme680_sensor.begin()) { | ||
| Line 223: | Line 233: | ||
| while (1); | while (1); | ||
| } | } | ||
| - | |||
| // Set up oversampling and filter initialization | // Set up oversampling and filter initialization | ||
| bme680_sensor.setTemperatureOversampling(BME680_OS_8X); | bme680_sensor.setTemperatureOversampling(BME680_OS_8X); | ||
| Line 261: | Line 270: | ||
| } | } | ||
| } | } | ||
| + | </ | ||
| - | | + | === Step 3 === |
| - | Initialize the Redis structures (Arancino.begin()), | + | Initialize the Redis structures (Arancino.begin()), |
| + | <code c> | ||
| void setup(void) | void setup(void) | ||
| { | { | ||
| Line 276: | Line 286: | ||
| pinMode(ledPin, | pinMode(ledPin, | ||
| } | } | ||
| + | </ | ||
| - | + | === Step 4 === | |
| - | Step 4 | + | |
| - | Implement loop() to do in the order: | + | Implement |
| - | perform the readings (see Step 2 for more details); | + | |
| - | blink the led (see Step 2 for more details). | + | |
| + | <code c> | ||
| void loop() | void loop() | ||
| { | { | ||
| Line 289: | Line 301: | ||
| blink_status(); | blink_status(); | ||
| } | } | ||
| + | </ | ||
| + | |||
| + | ==== Result validation ==== | ||
| - | Result validation | ||
| Observe the state of the LED for 1 second, this status will depend on the random number calculated and the threshold values that have been set. Observe the random value calculated on the display monitor. Observe how the random value affects the LED brightness for 3 seconds. | Observe the state of the LED for 1 second, this status will depend on the random number calculated and the threshold values that have been set. Observe the random value calculated on the display monitor. Observe how the random value affects the LED brightness for 3 seconds. | ||
| - | Platformio.ini | + | ==== Platformio.ini |
| + | <code c> | ||
| [env:uno] | [env:uno] | ||
| platform = atmelsam | platform = atmelsam | ||
| Line 312: | Line 326: | ||
| -Wno-reorder | -Wno-reorder | ||
| -Wno-return-type | -Wno-return-type | ||
| + | </ | ||
| + | ==== aran.cpp ==== | ||
| - | aran.cpp | + | <code c> |
| #include < | #include < | ||
| #include < | #include < | ||
| Line 416: | Line 431: | ||
| blink_status(); | blink_status(); | ||
| } | } | ||
| + | </ | ||