![](/media/cache/profiles/Timo_01_DSC_4754_533x533.jpg.50x50_q85.jpg)
A concept design laboratory prototype for measuring ambient light value. The high levels typically mean that there is high rates of UVA and 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. Tested as well on ST L432KC.
Dependencies: Adafruit_SSD1331_Mbed Adafruit-GFX
Diff: main.cpp
- Revision:
- 1:fde67a85d481
- Parent:
- 0:87339e72a5eb
- Child:
- 2:0eed70300cb4
--- a/main.cpp Sun Apr 19 16:06:25 2020 +0000 +++ b/main.cpp Sat May 16 15:45:45 2020 +0000 @@ -1,18 +1,64 @@ /* 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. ST L432KC ( 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 L432KC - Pmod_OLEDrgb with lines: +* L432KC D13 - OLED 4 SCK hardware defined for the SPI +* L432KC D11 - OLED 2 MOSI hardware definef for the SPI +* L432KC D9 - OLED 1 CS or any other free +* L432KC D10 - OLED 7 DC or any other free +* L432KC D6 - 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 L432KC - PmodALS with lines: +* L432KC D13 - ALS 4 SCK hardware defined for the SPI +* L432KC D12 - ALS 3 MISO hardware defined for the SPI +* L432KC 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 16.05.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 +Adafruit_SSD1331 OLED(D9, D6, D10, D11, NC, D13); // cs, res, dc, mosi, (nc), sck -DigitalOut LED(LED2); -DigitalOut VCCEN(D6); +//DigitalOut LED(LED1); // LED1, LED2, LED3 and LED4 are the D13 PB_3 pin in this board and can not be used because of the SPI +DigitalOut VCCEN(D3); DigitalOut PMODEN(D5); // Definition of colors on the OLED display @@ -42,27 +88,29 @@ char Time[50],Date[50]; void getTime(); -int first(0); +int first = 0; int main() { // Showing with a LED that program has started - LED = 0; + // 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); - LED = 1; - wait_ms(2000); - LED = 0; + ThisThread::sleep_for(2000); + // LED = 1; + 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,24 +130,25 @@ 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) { @@ -109,9 +158,10 @@ } 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); }