Fabio Souza
Published © CC BY-SA

DIY ESP8266-Based Badge

This badge is a DIY dev board for MicroPython. Based on ESP8266, it has a lot of features which are possible to learn and have fun with!

BeginnerFull instructions provided3 hours1,631

Things used in this project

Hardware components

DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Adafruit OLED
×1
Buzzer
Buzzer
×1
SparkFun Mini Photocell
×1
Flora RGB Neopixel LEDs- Pack of 4
Adafruit Flora RGB Neopixel LEDs- Pack of 4
×1
NXP PCF8574AP
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×4
NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
LED (generic)
LED (generic)
×4
Resistor 10k ohm
Resistor 10k ohm
×5
Resistor 4.75k ohm
Resistor 4.75k ohm
×3
Resistor 1k ohm
Resistor 1k ohm
×1
Resistor 330 ohm
Resistor 330 ohm
×4
General Purpose Transistor NPN
General Purpose Transistor NPN
×1
SparkFun Snappable Protoboard
SparkFun Snappable Protoboard
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
SparkFun Flush Cutters - Xcelite
SparkFun Solder Leaded - 100-gram Spool

Story

Read more

Schematics

Schematic

To explore the features of MicroPython I decided to put a variety of modules. The schematic was drawn in EasyEDA.

Board Features:

NodeMCU
DHT11
OLED Display
Buzzer
LDR
Neopixel with Expander connector
PCF8574AP (4 Entradas e 4 Saídas)
I2C Expander
SPI Expander

Code

Demo - MicroPython test

MicroPython
Script MicroPython for board test
from machine import Pin,I2C,ADC
import ssd1306
from neopixel import NeoPixel
from dht import DHT11
from time import sleep


i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000)  #Init i2c
i2c.scan()


lcd=ssd1306.SSD1306_I2C(128,64,i2c)             #create LCD object,Specify col and row
d = DHT11(Pin(2))
adc0=ADC(0)                                     #create ADC object on ADC pin
pin = Pin(0, Pin.OUT)                           # set GPIO0 to output to drive NeoPixels
np = NeoPixel(pin, 6)                           # create NeoPixel driver on GPIO0 for 8 pixels
buzzer = Pin(15, Pin.OUT)

i2c.writeto(0x38, bytes(0xFF))                  #Start PCF

buzzer.value(1)
sleep(0.2)
buzzer.value(0)
sleep(0.2)

np.write()

lcd.text("Hello",0,0)                           
lcd.text("TESTE",0,16)                       
lcd.text("MICROPYTHON",0,32)     
lcd.text("BOARD",0,48) 
lcd.show()                                      #display

sleep(1.0)

x = 0
y = 0
z = 0
tempo = 4

while True:
  sleep(0.01)
  
  tempo+=1
  if tempo == 5:
    tempo = 0
    d.measure()
    temp = '{:.1f}'.format(d.temperature())
    hmdty = '{:.1f}'.format(d.humidity() )
    
    lcd.fill(0) 
    lcd.text('T:', 0, 0)
    lcd.text(temp ,20,0)                         #set "DFRobot" at (0,0)
    lcd.text('H:', 0, 20)
    lcd.text(hmdty ,20,20)                         #set "DFRobot" at (0,0)
    #lcd.show()                                      #display
    
    #print(temp)
    #print(hmdty)

    np[x] = (0, 0, 0)       # set the first pixel to white
    np.write()              # write data to all pixels
    x+=1
    if x == 6: 
      x=0
      
    np[x] = (0, 0, 255)     # set the first pixel to white
    np.write()              # write data to all pixels

    buf = bytearray(1)
    buf[0] = 255
    i2c.writeto(0x38,buf)
    
    buf[0] = 0xff &~(1<<0|1<<1|1<<2|1<<3)
    i2c.writeto(0x38,buf)
    
    buf[0] = 0xF0|(1<<y)
    i2c.writeto(0x38,buf)
    y+=1
    if y==4:
      y = 0
  
  buf = i2c.readfrom(0x38,1) 
  z = buf[0]
  z=z>>4
  #print(z)
  
  if z == 7:
    lcd.text('Tecla: 1', 0, 40)
    buzzer.value(1)
    sleep(0.2)
    buzzer.value(0)
    sleep(0.2)
  elif z == 11:
    lcd.text('Tecla: 2', 0, 40)
    buzzer.value(1)
    sleep(0.2)
    buzzer.value(0)
    sleep(0.2)
  elif z == 13:
    lcd.text('Tecla: 3', 0, 40)
    buzzer.value(1)
    sleep(0.2)
    buzzer.value(0)
    sleep(0.2)
  elif z == 14:
    lcd.text('Tecla: 4', 0, 40)
    buzzer.value(1)
    sleep(0.2)
    buzzer.value(0)
    sleep(0.2)
  else:
    lcd.text('Tecla: -', 0, 40)
  
  lcd.show()   

  

Credits

Fabio Souza

Fabio Souza

9 projects • 42 followers
Electrical Engineer, Maker and Teacher.

Comments