I would appreciate it if someone enlighten me on this. thanks in advance.
Connected Modules :
1. SSD1306 OLED Display Module 128x64 (Pins: PB6, PB7)
2. TM1638 8digit 7Seg Driver module (Pins: PB8, PB9, PB13)
3. SHT20 Temperature and Humidity Sensor Module (Pins: PB6, PB7)
Program (A simple test program to read temperature and humidity values from SHT20 and display them on both OLED and 7Segment Modules):
Code: Select all
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306_STM32.h>
#include <TM1638plus.h>
#include "DFRobot_SHT20.h"
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET 4
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(OLED_RESET);
#define STROBE_TM PB13
#define CLOCK_TM PB8
#define DIO_TM PB9
TM1638plus tm(STROBE_TM, CLOCK_TM , DIO_TM);
DFRobot_SHT20 sht20(&Wire, SHT20_I2C_ADDR);
float humd = 0.0;
float temp = 0.0;
void setup() {
tm.displayBegin();
display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
display.setTextColor(WHITE); // Draw white text
display.cp437(true);
display.clearDisplay();
tm.brightness(5);
sht20.initSHT20();
delay(100);
sht20.checkSHT20();
}
void loop(){
humd = sht20.readHumidity();
temp = sht20.readTemperature();
display.clearDisplay();
display.setTextSize(2);
display.setCursor(0,0);
display.print("Temp");
display.setCursor(64,0);
display.print("Humd");
display.setCursor(0,16);
display.print(temp, 1);
display.setCursor(64,16);
display.print(humd, 1);
display.print("%");
display.display();
disp(temp, humd);
delay(1000);
}
void disp(float temp, float humd){
char workStr[11];
uint8_t digit1, digit2, digit3 , digit4, digit5, digit6, digit7, digit8;
uint16_t tempint = temp * 100; // 1245
uint16_t humdint = humd * 100; // 1245
digit1 = (tempint / 1000) % 10;
digit2 = (tempint / 100) % 10;
digit3 = (tempint / 10) % 10;
digit4 = tempint % 10;
digit5 = (humdint / 1000) % 10;
digit6 = (humdint / 100) % 10;
digit7 = (humdint / 10) % 10;
digit8 = humdint % 10;
sprintf(workStr, "%d%d.%d%d%d%d.%d%d", digit1, digit2, digit3, digit4, digit5, digit6, digit7, digit8);
tm.displayText(workStr);
}
Sketch uses 30352 bytes (46%) of program storage space. Maximum is 65536 bytes.
Global variables use 2896 bytes (14%) of dynamic memory, leaving 17584 bytes for local variables. Maximum is 20480 bytes.
C:\Users\Babak\AppData\Local\Arduino15\packages\stm32duino\tools\stm32tools\2021.5.31/win/serial_upload.bat COM8 {upload.altID} {upload.usbID} C:\Users\Babak\AppData\Local\Temp\arduino_build_413246/sketch_mar07a_STM32.ino.bin
stm32flash 0.4
http://stm32flash.googlecode.com/
Using Parser : Raw BINARY
Interface serial_w32: 115200 8E1
Version : 0x22
Option 1 : 0x00
Option 2 : 0x00
Device ID : 0x0410 (Medium-density)
- RAM : 20KiB (512b reserved by bootloader)
- Flash : 128KiB (sector size: 4x1024)
- Option RAM : 16b
- System RAM : 2KiB
Write to memory
Erasing memory
Wrote address 0x08007690 (100.00%) Done.
Starting execution at address 0x08000000... done.