This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:iot-open:remotelab:itt:remotelights [2018/11/14 16:43] – rim.puks | en:iot-open:remotelab:itt:remotelights [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== RGB LED module | + | ===== ITT RGB LED module ===== |
| - | Laboratory | + | This laboratory |
| - | Introduction | + | ==== Introduction |
| - | Here provide some general idea of the laboratory. Do not use very complicated phrases. It is to be understood by people with limited understanding of the technology. Photos, schematic and drawings may be attached | + | This laboratory consists |
| - | Prerequisites | + | {{: |
| - | Describe prerequisite readings, software, | + | |
| - | Technical details | + | ==== Prerequisites ==== |
| - | Provide technical details on the construction | + | General knowledge |
| - | Sensors | + | ==== Technical details ==== |
| - | Describe sensors (if any). Provide details on measured values, connection details, accuracy, protocols, its relation to the physical/ | + | This laboratory conisists |
| - | Actuators | + | === Actuators |
| - | Describe actuators, their impact on the physical/ | + | This laboratory |
| - | Software, libraries and externals | + | === Specifications === |
| - | Provide a list of software, software libraries and external resources (i.e. files) necessary during code development. Please note, write here only common for all hands-on-labs scenarios (there is a relevant section in scenario template. Remove this section if empty. | + | |
| - | Communication | + | * LED size: 5050 |
| - | Describe communication if it is implemented and sealed (not intended to be implemented by students, or provided i.e. as default code). Present data flow. Describe protocols and details i.e. key-value pairs, etc. Provide how exceptions are handled. | + | * Colors: 16777216 |
| - | Limits | + | === Electrical connection === |
| - | Provide information about limits on usage, i.e. need for maintenance/ | + | |
| - | Hands-on labs | + | Connected to port GPIO4. |
| - | List study scenarios (hands-on labs), linking | + | |
| + | === Software, libraries and externals === | ||
| + | To control WS2812B RGB LED the following libraries are used: | ||
| + | * ITTIoT libary | ||
| + | * Adafruit NeoPixel libary | ||
| + | |||
| + | === Communication === | ||
| + | The user can connect to this controller using the Distancelab environment. | ||
| + | |||
| + | === Limits === | ||
| + | At the same time, one user can program the controller. But all users connected | ||
| + | |||
| + | ==== Hands-on labs ==== | ||
| + | |||
| + | === Example code === | ||
| + | <code c> | ||
| + | #include <Arduino.h> | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | #define PIN D2 | ||
| + | |||
| + | // When we setup the NeoPixel library, we tell it how many pixels, | ||
| + | // and which pin to use to send signals. | ||
| + | // Note that for older NeoPixel strips you might need to change | ||
| + | // the third parameter--see the strandtest | ||
| + | // example for more information on possible values. | ||
| + | Adafruit_NeoPixel pixels = Adafruit_NeoPixel(1, | ||
| + | |||
| + | // https:// | ||
| + | String getValue(String data, char separator, int index) | ||
| + | { | ||
| + | int found = 0; | ||
| + | int strIndex[] = {0, -1}; | ||
| + | int maxIndex = data.length()-1; | ||
| + | |||
| + | for(int | ||
| + | { | ||
| + | if(data.charAt(i)==separator || i==maxIndex) | ||
| + | { | ||
| + | found++; | ||
| + | strIndex[0] = strIndex[1]+1; | ||
| + | strIndex[1] = (i == maxIndex) ? i+1 : i; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | return found> | ||
| + | } | ||
| + | |||
| + | // Change RGB LED color | ||
| + | // mosquitto_pub -u test -P test -t " | ||
| + | void iot_received(String topic, String msg) | ||
| + | { | ||
| + | Serial.print(" | ||
| + | Serial.print(topic); | ||
| + | Serial.print(" | ||
| + | Serial.println(msg); | ||
| + | |||
| + | String r = getValue(msg,';', | ||
| + | String g = getValue(msg,';', | ||
| + | String b = getValue(msg,';', | ||
| + | |||
| + | Serial.print(" | ||
| + | Serial.println(r); | ||
| + | |||
| + | Serial.print(" | ||
| + | Serial.println(g); | ||
| + | |||
| + | Serial.print(" | ||
| + | Serial.println(b); | ||
| + | // Moderately bright green color. | ||
| + | pixels.setPixelColor(0, | ||
| + | |||
| + | pixels.show(); | ||
| + | } | ||
| + | |||
| + | void iot_connected() | ||
| + | { | ||
| + | Serial.println(" | ||
| + | iot.subscribe(" | ||
| + | iot.log(" | ||
| + | } | ||
| + | |||
| + | void setup() | ||
| + | { | ||
| + | Serial.begin(115200); | ||
| + | Serial.println(" | ||
| + | |||
| + | iot.printConfig(); | ||
| + | iot.setup(); | ||
| + | |||
| + | pixels.begin(); | ||
| + | } | ||
| + | |||
| + | void loop() | ||
| + | { | ||
| + | iot.handle(); | ||
| + | delay(200); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ==== Support ==== | ||
| + | info@ittgroup.ee | ||
| - | * Beginners: Elementary operations on the Arduino 2x16 LCD screen. | ||
| - | * Undergraduates: | ||
| - | * Masters: Using power saving states to limit power consumption. | ||
| - | Support | ||
| - | Give some information on how to access help, how to get support in case of the trouble etc. | ||