A concept design laboratory prototype for measuring ambient light value. The high levels typically mean that there is high rates of UVA nad UVB radiation as well. A warning of this is displayed on a small screen. NXP FRDM-K64F, Digilent Pmod modules Pmod OLEDrgb and Pmod ALS.

Dependencies:   Adafruit_SSD1331_Mbed Adafruit-GFX

Files at this revision

API Documentation at this revision

Comitter:
timo_k2
Date:
Sat May 16 15:55:53 2020 +0000
Parent:
0:87339e72a5eb
Commit message:
Pmod OLEDrgb display and Pmod ALS sensor are tested with board NXP K64F. Both are using the SPI communication.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 87339e72a5eb -r 2f167213fd2d main.cpp
--- a/main.cpp	Sun Apr 19 16:06:25 2020 +0000
+++ b/main.cpp	Sat May 16 15:55:53 2020 +0000
@@ -1,13 +1,59 @@
 /* mbed Microcontroller Library
  * Copyright (c) 2019 ARM Limited
  * SPDX-License-Identifier: Apache-2.0
- */
+************************************************************************
+*
+* Test of the Pmod small OLED display and ambient light sensor
+*
+*************************************************************************
+* Description: Pmod_OLED_ALS1
+* The message "Test module Pmod Digilent Lextronic" will be display on OLEDrgb module
+* with different size and colors..... and sensor value as well.
+*
+* Material
+* 1. NXP FRDM-K64F  ( or some other micro controller board with SPI communication )
+* 2. Digilent Pmod OLEDrgb  and the libraries
+* Adafruit_SSD1331_Mbed
+* Adafruit-GFX
+* These libraries can be found with search on the page 
+* https://www.mbed.com/en/platform/mbed-os/
+* Please connect FRDM-K64F - Pmod_OLEDrgb with lines:
+* K64F D13 - OLED 4 SCK   hardware defined for the SPI
+* K64F D11 - OLED 2 MOSI  hardware definef for the SPI
+* K64F D8  - OLED 1 CS   or any other free
+* K64F D10 - OLED 7 DC   or any other free
+* K64F D7  - OLED 8 RES   or any other free
+*  VCC     - OLED 9 VCCEN  Enable - VCC
+*  VCC     - OLED10 PMODEN  Pmod Enable - VCC
+*  GND     - OLED 5 Ground
+*  VCC     - OLED 6 Power supply 3,3 V
+* 
+*************************************************************************
+* 3. Digilent Pmod ALS ambient light sensor
+* Please connect FRDM-K64F - PmodALS with lines:
+* K64F D13 - ALS 4 SCK   hardware defined for the SPI
+* K64F D12 - ALS 3 MISO  hardware defined for the SPI
+* K64F D4  - ALS 1 CS  or any other free
+*  GND     - ALS 5 GND
+*  Vcc     - ALS 6 Vcc
+
+ALS data on the SPI
+D15 ... D13 - three zeros
+D12 ... D04 - 8 bits of ambient light data
+D03 ... D00 - four zeros
+
+Details on the connection of ADC IC chip on ALS board are given
+http://www.ti.com/lit/ds/symlink/adc081s021.pdf
+* 
+* Timo Karppinen 24.04.2020
+**************************************************************/
+
 
 #include "mbed.h"
-#include "Adafruit_SSD1331.h"
-#include "Adafruit_GFX.h"
-
-
+#include "Adafruit_SSD1331.h"   // By using the Adafruit SSD1331 library and Adafruit GFX library
+#include "Adafruit_GFX.h"       // we will get similar code than in Arduino-boards working.
+                                // There are other SSD1331 libraries, too. https://os.mbed.com/search/?q=ssd1331
+                            
 // PmodOLEDrgb
 Adafruit_SSD1331 OLED(D8, D7, D10, D11, NC, D13); // cs, res, dc, mosi, (nc), sck  
 
@@ -42,7 +88,7 @@
 
 char Time[50],Date[50];
 void getTime();
-int first(0);
+int first = 0;
 
 int main()
 {
@@ -50,19 +96,21 @@
         LED = 0;
         VCCEN = 1;    // if you did not connect VCCEN permanently to Vcc
         PMODEN = 1;   // if you did not connect PMODEN permanently to Vcc
-        wait_ms(2000);
+        ThisThread::sleep_for(2000);
         LED = 1;
-        wait_ms(2000);
+        ThisThread::sleep_for(2000);
         LED = 0;
   // Initalize the PmodOLEDrgb    
-        OLED.begin(); // initialization of display objcet
+        OLED.begin(); // initialization of display object
         
 // SPI for the ALS      
         alsCS = 1;
         // Setup the spi for 8 bit data, high steady state clock,
         // second edge capture, with a 12MHz clock rate
         spi.format(8,0);           
-        spi.frequency(12000000);   
+        spi.frequency(12000000);
+        
+        OLED.clearScreen();   
 
     while (true) {
         while(first < 3)
@@ -72,7 +120,7 @@
                 OLED.setTextColor(Cyan); // color of text in cyan
                 OLED.setCursor(0,0); // cursor is in x=0 and y=15
                 OLED.printf("Test module Pmod"); // display text
-                wait_ms(500); // wait 500 ms
+                ThisThread::sleep_for(500); // wait 500 ms
                 OLED.setCursor(0,15); // cursor is in x=0 and y=15
                 OLED.setTextSize(2); // size of text
                 OLED.setTextColor(Red); // text in red color
@@ -82,36 +130,38 @@
                 OLED.setTextColor(Green); // text in green color
                 OLED.printf("LEXTRONIC"); // display text
                 OLED.drawFastHLine(1, 60, OLED.width()-1, Blue); // blue line x=1 to screen width-1 and y=60
-                wait_ms(2000); // wait 2 s
+                ThisThread::sleep_for(2000); // wait 2 s
                 OLED.fillScreen(Black); // background display in black (erase display)
                 OLED.fillRoundRect(5, 5, 30, 40, 1, Blue); // French flag bleu blanc rouge
                 OLED.fillRoundRect(35, 5, 30, 40, 1, White);
                 OLED.fillRoundRect(65, 5, 30, 40, 1, Red);
                 OLED.fillCircle(90, 55, 5, Yellow); // yellow circle with radius=5 in x=90 and y=55
-                wait_ms(2000); // wait 2 s
+                ThisThread::sleep_for(2000); // wait 2 s
             }
 
         getTime();
+        OLED.clearScreen();
         OLED.fillScreen(Black); // background screen in black
         OLED.setTextColor(Cyan); // color of text in cyan
-        wait_ms(300);
+        ThisThread::sleep_for(300);
         OLED.setCursor(0,0); // cursor is in x=0 and y=0
-        OLED.printf("Rec '%s' \r\n",Time);
+        OLED.printf("Rec '%s' \n",Time);
         
         getALS(); 
-        OLED.printf("LUX = '%0.1f' \r\n",alsScaledF);
+        OLED.printf("LUX = '%0.1f' \n",alsScaledF);
 
         if (alsScaledF > 100)
         { 
             OLED.setTextColor(Yellow);
-            OLED.printf("Be aware of high UV radiation!");
+            OLED.printf("Be aware of high UV radiation! \n\n");
             OLED.fillRoundRect(10, 35, 50, 3 , 1, Yellow);
         }
-        OLED.setCursor(0,40); // cursor is in x=0 and y=0
+        //OLED.setCursor(0,40); // cursor is in x=0 and y=0
         OLED.printf("Test completed");
+        OLED.drawFastHLine(1, 60, OLED.width()-1, Blue); // blue line x=1 to screen width-1 and y=60
         printf("printed on OLED");
         
-        wait(1);
+        ThisThread::sleep_for(3000);
 }
 }
 
@@ -142,6 +192,6 @@
                                                 // Conversions to 32 bit floating point of type float.
     printf("Ambient light raw 8 bit 0...255 =  '%d' \r\n",alsRaw);
     printf("Ambient light scaled to LUX =  '%0.1f' \r\n",alsScaledF);
-    wait_ms(100);
+    ThisThread::sleep_for(100);
 }