Summer is coming with steadily increasing warmth. Now, it is a right time to prepare a summer thing──fanner! Therefore, I have bought a small fanner on line; it is good except that it cannot steering.


However, is this a problem? No! As a creative engineer, it’s my show time!

1. Hardware in need:

FireBeetle ESP32 IOT Microcontroller (Supports Wi-Fi & Bluetooth) × 1

FireBeetle Covers-Gravity I/O Expansion Shield× 1

Gravity: I2C OLED-2864 Display × 1

BME temperature-humidity sensor × 1

EC11J rotary encoder × 1

9g micro servo (1.6kg) × 1

Dupont line × 10

Crust By Overlord 3D printer × 1

* No need for soldering during the whole working process.

2. Hardware Connection:

Connect I2C interface of OLED12864 directly to I2C interface of Gravity Expansion shield, and connect A of EC11J rotary encoder to D0, B to D1, C to D8. Then connect the micro servo to D3 and connect SPI interface of BME280 directly to SPI interface of Gravity Expansion shield, CS (Chip Select) to D5.

The Circuit Diagram is as below:

3. Working Process:

- Print the crust with 3D printer.

Click here to download the program and the source code for 3D printing.

Fix the rotary encoder to the crust.

- Fix OLED2864 to the crust.

Connect OLED display to Gravity board with Dupont and the connection interface is I2C.

- Connect BME280.

BME280 uses SPI interface, please refer to the previous circuit diagram for details of connection.

- Allocate the fan.

Remove the lithium battery and connect the power supply of the fan to Vcc and GND of FireBeetle ESP8266, edge connecting the lithium battery to FireBeetle ESP8266. Then set connect the micro servo to D3.

- Complete machine assembly.

Cover the bottom and fix it with hot-melt glue, and download the program.

Code

#include   // Only needed for Arduino 1.6.5 and earlier
 #include  
 #include "SSD1306.h" // alias for `#include "SSD1306Wire.h"`
 #include "OLEDDisplayUi.h"
#include "images.h"
#include 
#include 
 
#define SEA_LEVEL_PRESSURE  1013.25f
#define BME_CS D5
 
SimpleTimer timer;
int timeCounter = 0;
 
boolean uiEnable = true;
 
DFRobot_BME280 bme(BME_CS); //SPI
 
SSD1306  display(0x3c, D7, D6);
Servo  mymotor;  
 
OLEDDisplayUi ui( &display );
 
enum model{
  MODEL_NULL,
  MODEL_LEFT,
  MODEL_RIGHT,
  MODEL_BUTTON
};
 
enum setFrame{
  SET_NULL,
  SET_FRAME_2_ON,
  SET_FRAME_2_OFF,
  SET_FRAME_3_ON,
  SET_FRAME_3_OFF
};
 
enum motorModel{
  MOTOR_AUTO,
  MOTOR_STATIC
};
 
char commondModel = MODEL_NULL;
char setFrameValue = SET_NULL;
 
char motorState = MOTOR_STATIC;
 
int encoderPinA = D0;
int encoderPinB = D1;
int buttonPin = D8;
 
volatile int lastEncoded = 0;
volatile long encoderValue = 0;
 
long lastencoderValue = 0;
 
int lastMSB = 0;
int lastLSB = 0;
 
int speedValue = 5;
int angleValue = 90;
boolean dir = true;
 
int frameIndex = 0;
 
long readEncoderValue(void){
    return encoderValue/4;
}
 
boolean isButtonPushDown(void){
  if(!digitalRead(buttonPin)){
    delay(5);
    if(!digitalRead(buttonPin)){
      while(!digitalRead(buttonPin));
      return true;
    }
  }
  return false;
}
 
void msOverlay(OLEDDisplay *display, OLEDDisplayUiState* state) {
  if(frameIndex == 0)
    return;
  display->setTextAlignment(TEXT_ALIGN_RIGHT);
  display->setFont(ArialMT_Plain_10);
  display->drawString(128, 0, String(angleValue));
}
 
void drawFrame1(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
  display->setTextAlignment(TEXT_ALIGN_LEFT);
  display->setFont(ArialMT_Plain_24);
  display->drawString(15 + x, 10+ y, "ChoCho");
}
 
void drawFrame2(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
  float temp = bme.temperatureValue();
  float pa = bme.pressureValue();
  float hum = bme.altitudeValue(SEA_LEVEL_PRESSURE);
  float alt = bme.humidityValue();
  // Demonstrates the 3 included default sizes. The fonts come from SSD1306Fonts.h file
  // Besides the default fonts there will be a program to convert TrueType fonts into this format
  display->setTextAlignment(TEXT_ALIGN_LEFT);
  display->setFont(ArialMT_Plain_16);
 display->drawString(x,...

Read more »