[DFRobot Skylark Weather Meter Review] Arduino Wireless Intelligent Air Monitoring System Construction-04 Full-color OLED Display to Obtain Data
[Copy link]
This post was last edited by eew_TKwwQ7 on 2023-12-3 23:09
1. Functionality
Connect the DFRobot Skylark weather meter to the Arduino development board to display the data collected by the Skylark weather meter in real time. The hardware required is:
The module uses SPI interface and can be driven by Arduino corresponding Adafruit_SSD1331 and SPI library. The module resolution is 96*64, which is enough for personalized display data. In order to facilitate operation, OLED is directly inserted into the development board, and the microcontroller is directly driven and powered (the working current is less than 30mA, which can be directly driven and powered)
Serial number |
Pinout |
name |
ARDUINO PINOUT |
1 |
GND |
Power Ground |
/ |
2 |
VCC |
Power positive |
Pin13 |
3 |
SCX |
Clock Line |
Pin12 |
4 |
SDA |
Data cable |
Pin11 |
5 |
RES |
Reset line |
Pin10 |
6 |
DC |
Data/Command |
Pin9 |
7 |
CS |
Chip Select |
Pin8 |
2. Program Code
#include "DFRobot_LarkWeatherStation.h"
#include <Wire.h>
#include <Arduino.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1331.h>
#include <SPI.h>
#define DEVICE_ADDR 0x42
#define MODESWITCH /*UART:*/0 /*I2C: 0*/
#define sclk 12//SCL
#define mosi 11//SDA
#define cs 8// CS
#define rst 10//RES
#define dc 9//DC
// Color definitions
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Adafruit_SSD1331 display = Adafruit_SSD1331(cs, dc, mosi, sclk, rst);
DFRobot_LarkWeatherStation_I2C atm(DEVICE_ADDR,&Wire);
void setup(void){
Serial.begin(115200);
atm.begin();
pinMode(13, OUTPUT);//OLED供电
digitalWrite(13,HIGH);//OLED供电
display.begin();//OLED初始化
display.fillScreen(BLACK);//OLED清屏
}
void loop(void){
Serial.println("----------------------------");
Serial.print(atm.getValue("Temp"));
Serial.println(atm.getUnit("Temp"));
Serial.print(atm.getValue("Humi"));
Serial.println(atm.getUnit("Humi"));
Serial.print(atm.getValue("Speed"));
Serial.println(atm.getUnit("Speed"));
Serial.println(atm.getValue("Dir"));
Serial.print(atm.getValue("Altitude"));
Serial.println(atm.getUnit("Altitude"));
Serial.print(atm.getValue("Pressure"));
Serial.println(atm.getUnit("Pressure"));
Serial.println("----------------------------");
Serial.println(atm.getInformation(true));
delay(100);
display.setCursor(0, 0);display.setTextColor(BLACK);display.setTextSize(2);display.println("DFROBOT");
display.setCursor(0, 16);display.setTextColor(BLACK);display.setTextSize(1);display.print("Temp:"); display.print(atm.getValue("Temp"));
display.setCursor(0, 24);display.setTextColor(BLACK);display.setTextSize(1);display.print("Humi:"); display.print(atm.getValue("Humi"));
display.setCursor(0, 32);display.setTextColor(BLACK);display.setTextSize(1);display.print("Speed:"); display.print(atm.getValue("Speed"));
display.setCursor(0, 40);display.setTextColor(BLACK);display.setTextSize(1);display.print("Dir:"); display.print(atm.getValue("Dir"));
display.setCursor(0, 48);display.setTextColor(BLACK);display.setTextSize(1);display.print("Altitude:"); display.print(atm.getValue("Altitude"));
display.setCursor(0, 56);display.setTextColor(BLACK);display.setTextSize(1);display.print("Pressure:"); display.print(atm.getValue("Pressure"));
display.setCursor(0, 0);display.setTextColor(RED);display.setTextSize(2);display.println("DFROBOT");
display.setCursor(0, 16);display.setTextColor(YELLOW);display.setTextSize(1);display.print("Temp:"); display.print(atm.getValue("Temp"));
display.setCursor(0, 24);display.setTextColor(BLUE);display.setTextSize(1);display.print("Humi:"); display.print(atm.getValue("Humi"));
display.setCursor(0, 32);display.setTextColor(GREEN);display.setTextSize(1);display.print("Speed:"); display.print(atm.getValue("Speed"));
display.setCursor(0, 40);display.setTextColor(CYAN);display.setTextSize(1);display.print("Dir:"); display.print(atm.getValue("Dir"));
display.setCursor(0, 48);display.setTextColor(MAGENTA);display.setTextSize(1);display.print("Altitude:"); display.print(atm.getValue("Altitude"));
display.setCursor(0, 56);display.setTextColor(WHITE);display.setTextSize(1);display.print("Pressure:"); display.print(atm.getValue("Pressure"));
}
3. Display Effect
The above is the full-color OLED display to obtain data content
WeChat_20231203230552
|