Skip to content

Instantly share code, notes, and snippets.

@Shigawire
Created October 21, 2017 19:58
Show Gist options
  • Save Shigawire/56aac6f6ea2777a07320dc765306144b to your computer and use it in GitHub Desktop.
Save Shigawire/56aac6f6ea2777a07320dc765306144b to your computer and use it in GitHub Desktop.

IoT Docs:

ESP8266 Boards: Wemos D1 mini Pro (https://wiki.wemos.cc/products:d1:d1_mini_pro)

Board drivers:

Current:

https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers

Legacy (for OSX < 10.12):

http://community.silabs.com/t5/Interface-Knowledge-Base/Legacy-OS-Software-and-Driver-Packages/ta-p/182585

Arduino IDE works well with these boards: https://www.arduino.cc/en/main/software

Add the ESP8266 Boards to the Arduino Board Library: http://www.instructables.com/id/Programming-the-WeMos-Using-Arduino-SoftwareIDE/

Code Libraries and Samples:

8x8 Dot Matrix LEDs:

https://github.com/wemos/WEMOS_Matrix_LED_Shield_Arduino_Library

#include <WEMOS_Matrix_LED.h>

MLED mled(5); //set intensity=5

void setup()
{

}

void loop() {

  for(int y=0;y<8;y++)
  {
    for(int x=0;x<8;x++)
    {
        mled.dot(x,y); // draw dot
        mled.display();
        delay(200);
    }
  }
}

Yellow Push Button

/*
 * 1 Button Shield - Simple Push
 * Press the pushbutton to switch on the LED
 *
 * 1 Button Shield pushbutton connects pin D3 to GND
 */

const int buttonPin = D3;
const int ledPin = BUILTIN_LED;

int buttonState = 0;

void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT);

  // set initial state, LED off
  digitalWrite(ledPin, buttonState);
}

void loop() {
  // read button state, HIGH when pressed, LOW when not
  buttonState = digitalRead(buttonPin);

  // if the push button pressed, switch on the LED
  if (buttonState == HIGH) {
    digitalWrite(ledPin, HIGH);  // LED on
  } else {
    digitalWrite(ledPin, LOW); // LED off
  }
}

Buzzer (makes noise)

int buzzer=D5; //Buzzer control port, default D5

int freq[] = { 1047, 1175, 1319, 1397, 1568, 1760, 1976, 2093 };//Note name: C6 D6 E6 F6 G6 A6 B6 C7   http://newt.phys.unsw.edu.au/jw/notes.html
String note[] = {"C6", "D6", "E6", "F6", "G6", "A6", "B6", "C7"};

void setup() {
  pinMode(buzzer, OUTPUT);
  digitalWrite(buzzer, LOW);
  Serial.begin(115200);
  Serial.println("Buzzer Test...");
}

void loop() {
  for(int i=0; i<8; i++){
    analogWriteRange(freq[i]);
    Serial.print("Note name: ");
    Serial.print(note[i]);
    Serial.print(", Freq: ");
    Serial.print(freq[i]);
    Serial.println("Hz");

    analogWrite(buzzer, 512);
    delay(1000);
    analogWrite(buzzer, 0);
    pinMode(buzzer, OUTPUT);
    digitalWrite(buzzer, LOW);
    delay(1000);
  }
  Serial.println("STOP");
  delay(5000);

}

Temperature Sensors (SHT30)

Required library: https://github.com/wemos/WEMOS_SHT3x_Arduino_Library

#include <WEMOS_SHT3X.h>

SHT3X sht30(0x45);

void setup() {

  Serial.begin(115200);

}

void loop() {

  if(sht30.get()==0){
    Serial.print("Temperature in Celsius : ");
    Serial.println(sht30.cTemp);
    Serial.print("Temperature in Fahrenheit : ");
    Serial.println(sht30.fTemp);
    Serial.print("Relative Humidity : ");
    Serial.println(sht30.humidity);
    Serial.println();
  }
  else
  {
    Serial.println("Error!");
  }
  delay(1000);

}

LED 128x64 LED Display Shield

Use this library: https://github.com/Shigawire/Adafruit_SSD1306

Important OLED_RESET is on GPIO0: https://wiki.wemos.cc/_media/products:d1_mini_shields:mini_oled.pdf

#define OLED_RESET 0

Sample Script:

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>

//when in doubt, change the Adafruit_SSD1306.h file for this definition
#define SSD1306_128_64
// default pins: SCL=D1=GPIO5, SDA=D2=GPIO4
#define OLED_RESET 0              // OLED_RESET=D3=GPIO0
Adafruit_SSD1306 display(OLED_RESET);
void setup() {
 Serial.begin(9600);
 display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // I2C addr 0x3C
 display.setTextColor(WHITE);
 display.clearDisplay();          // Clear the display-buffer
 //-----write text to buffer------------------------------------
 display.setTextSize(1);
 display.setCursor(0,0);
 display.println("1234567890");
 display.println("abcdefghij");
 display.println("ABCDEFGHIJ");
 display.println("--Line 4--");
 display.println("1234567890");
 display.println("-_Line 6_-");
 display.display();               // show buffer
}

void loop() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment