Smart Glasses

Introduction: Smart Glasses

About: "For every house is built by someone, but the builder of all things is God." Hebrews 3:4

[The following is an example of a bad Instructable, but I have decided to leave it up to show others how I have progressed. Good luck reading this]

Hello everyone today I'm going to show you how to make Smart Glasses at home! One of the greatest things about smart glasses is how beneficial it is to have something like this in today's world of technology and how there isn't just one version of smart glasses as all have amazing features and a infinite number of applications that could be integrated in the future. The features of these smart glasses include telling time, telling you the temperature every 5 mins, between those 5 mins it swaps between the expected high and low temperature for that day, it also tells you the date. But its main feature is that it takes a picture every 10 seconds and then analyzes that picture for text in which it will return useful information about it, if it finds a question then it will answer it using wolfram, or if it finds a math equation it will solve it!

Supplies

The supplies necessary for this project will include the following:

1) A Raspberry Pi 0 W (From vilros.com)

2) A clear 128x64 OLED display (From Sparkfun.com)

3) A camera module formatted for Raspberry Pi 0 W (From amazon.com)

4) Any glasses of your choice

5) Wires

6) Soldering iron

7) Lead free solder (because you don't want to die from lead)

8) 2 way adhesive

9) SD card min of 8gb

10) computer and internet connection

Assuming you already have a computer and internet connection the cost of these glasses will come to around $130.00

Step 1: Wiring the Circuit!

In order to display text on the screen you are going to have connect to the OLED via I2C or SPI, I choose I2C as it is the one I am more comfortable using but if you feel like connecting to it via SPI go follow this tutorial on the Sparkfun website and come back here when you are done. https://learn.sparkfun.com/tutorials/transparent-g... If you have chosen I2C as I have solder the wires as indicated by the following:

Pi \/ OLED \/

3.3v < > 3.3v

GND < > GND

SDA < > SDA

SCL < > SCL

Please note that the clear OLED can only handle 3.3v.

After you have finished connecting the circuit, slide the ribbon cable of the camera module into the ribbon cable holder on the raspberry pi by pulling out the black clamp and sliding it back in once the ribbon cable is in place.

Step 2: Accessing the Raspberry Pi

Using ssh we can access our pi with our pc without connecting an extra external keyboard mouse and monitor. First thing you do is connect your SD card into your PC with an adapter or a built in port, then you are going to need to head to this link https://www.raspberrypi.org/downloads/raspbian/ and download Raspbian buster with desktop. Second you have to put the OS onto the SD card using BalenaEtcher select your SD card and the Raspbian OS and click "flash" this process could take some time so come back when you are finished. Third go to the SD card in file explorer or finder on mac and create a text file named wpa_supplicant make sure to delete the .txt extension and add .conf, in the file paste the following:

country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1
network={ ssid="WIFI_SSID" 
scan_ssid=1 
psk="WIFI_PASSWORD"
key_mgmt=WPA-PSK }

You are going to have to enter your WiFi name and password in the corresponding places and country if you aren't in the USA. Keep in mind the Raspberry Pi can only connect to a 2.4Ghz network meaning your pc will also have to connect to that network.
After create an empty text file with no extension called ssh and then eject your SD card. You are then going to need to install PuTTY https://www.putty.org/ which is what you will use to enable ssh. Once installed enter the IP address of your raspberry pi, you can figure out what it is by going to your routers website logging in and looking at the connected devices.

After you gain access to the Raspberry Pi it will ask you to log-in, the default username is "pi" and the password is "raspberry". Type sudo raspi-config then go to interfacing options and enable camera, ssh, and i2c, then click finish and type sudo reboot. Now you are ready to ssh into the raspberry pi, go ahead and install Remote Desktop and enter your raspberry pi's IP address and you are now good to ssh into the raspberry pi.

Step 3: Coding Time!

I have chosen to code this program in python so make sure you have python3.7 or 3.8 installed on your desktop. This code works by using a server and a client, the sever being your pc. The client or raspberry pi will take a picture and upload that to dropbox which is the retrieved by the server who then runs image processing and text recognition on the image. You are going to have to get a wolframalpha, dropbox, and openweathermap app-id for this to work, all you have to do is go to the websites sign-up and it will give you an app-id. and then input them into corresponding places determined by the comments in the code. Make sure you have pip installed everything and installed Tesseract OCR and OpenCV. Create a python file named Server.py on your pc and a file named client.py on the raspberry pi and then copy and paste the code. But know that the bolder the characters and whiter the background the better the results, this is the case with every text recognition software.

All of the links to sign-up for an app-id \/

https://www.wolframalpha.com/

https://openweathermap.org/api

https://www.dropbox.com/developers/documentation

Make sure you install Tesseract OCR and OpenCV \/

https://github.com/UB-Mannheim/tesseract/wiki

https://opencv.org/

Server.py:

<p>import dropbox<br>from PIL import Image
import cv2
import pytesseract
from pytesseract import Output
import numpy as np
import wolframalpha
import socket
import time</p><p>dbx = dropbox.Dropbox("dropboxAPIkey")</p><p>s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)</p><p>app_id = "App-ID"</p><p>host = socket.gethostname()
port = 60567
print (host)
s.bind((host, port))
s.listen(2)</p><p>while True:
  c, addr = s.accept()
  print (f'Got connection from: {addr}')
  break</p><p>while True:
  while True:
      time.sleep(13.7)
      metadata, f = dbx.files_download("/dropbox_API/Image.jpg")
      out = open("Image.jpg", 'wb')
      out.write(f.content)
      out.close()
      print("Image downloaded!")
      
      image = cv2.imread("Image.jpg")
      Image = cv2.resize(image,(640, 480),interpolation=cv2.INTER_AREA)
      image68 =  cv2.rotate(Image, cv2.ROTATE_90_COUNTERCLOCKWISE)
      gray = cv2.cvtColor(image68, cv2.COLOR_BGR2GRAY)</p><p>      def remove_noise(gray):
        return cv2.medianBlur(gray, 5)
      def thresholding(gray):
        return cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
      def dilate(gray):
        kernel = np.ones((5, 5), np.uint8)
        return cv2.dilate(gray, kernel, iterations=1)
      
      
      d = pytesseract.image_to_data(gray, output_type = Output.DICT)</p><p>      n_boxes = len(d['text'])
      for i in range(n_boxes):
        if int(d['conf'][i]) > 60:
          (x, y, w, h) = (d['left'][i], d['top'][i], d['width'][i], d['height'][i])
          gray = cv2.rectangle(gray, (x, y), (x + w, y + h), (0, 255, 0), 2)
      
      break
  
  pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
  text = pytesseract.image_to_string(gray)
  print(text)
  
  while True:
    text2 = " "
    if len(text) >= 2:
      c.send(bytes(text, "utf-8"))
      
    if len(text) <= 1:
      c.send(bytes(text2, "utf-8"))
    
    if len(text) >= 2:
      query = text
      client = wolframalpha.Client(app_id)
      res = client.query(query)
      answer = next(res.results).text
      answer1 = answer.partition('\n')[0]
      print (answer1)
      c.send(bytes(answer1, "utf-8"))
    if len(text) <= 1:
      c.send(bytes(text2, "utf-8"))
      time.sleep(7.5)
    
    break</p><strong></strong><u></u><sub></sub><sup></sup><del></del><br>

Client.py:

<p>import dropbox<br>import picamera<br>import time
from luma.core.interface.serial import i2c
from luma.core.render import canvas
from luma.oled.device import ssd1306, ssd1325, ssd1331, sh1106
import socket
import datetime
from time import sleep
import pyowm
serial = i2c(port=1, address=0x3C)
device = ssd1306(serial, rotate=1)
camera = picamera.PiCamera()
dropbox_access_token= "" #Your dropbox-id again
computer_path=r"/home/pi/Image.jpg"
dropbox_path= f"/dropbox_API/Image.jpg"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = ""#ip address of your pc
port = 60567
s.connect((host, port))
msg1  = " "
owm = pyowm.OWM("")#app-id for openweathermap
num = ["05", "10", "15", "20", "25", "30", "35", "40", "45", "50", "55", "00"]
cdt = datetime.datetime.now()
min1 = str(cdt.minute)
date = str(cdt.day) + "/" + str(cdt.month) + "/" + str(cdt.year)
 
obs = owm.weather_at_place("")#your town and country in string format
weather = obs.get_weather()
temp2 = str(weather.get_temperature("fahrenheit")["temp_max"])
temp3 = str(weather.get_temperature("fahrenheit")["temp_min"])
while True:
  cdt = datetime.datetime.now()
  min1 = str(cdt.minute)
  hour = str(cdt.hour)
  with canvas(device) as draw:
    draw.text((0, 0), hour, fill = "white")
    draw.text((11, 0),":", fill = "white")
    draw.text((15, 0), min1, fill = "white")
    draw.text((0, 9), "___________", fill = "white")
    draw.text((0, 9), date, fill = "white")
    if min1 in num:
       obs = owm.weather_at_place("")#your town and country in string format again</p><p>       weather = obs.get_weather()
       temp = str(weather.get_temperature("fahrenheit")["temp"])
       draw.text((32, 0), "F", fill = "white")
       draw.text((40, 0), temp, fill = "white")
    if min1 not in num:
       draw.text((40, 0), temp2, fill = "white")
       draw.text((32, 0), "F", fill = "white")
  camera.start_preview()
  time.sleep(2)
  camera.capture("/home/pi/Image.jpg")
  camera.stop_preview
 
  client = dropbox.Dropbox(dropbox_access_token)
  print("[SUCCESS] dropbox account linked")
  client.files_upload(open(computer_path, "rb").read(), dropbox_path)
  print("[UPLOADED] {}".format(computer_path))
  full_msg = " "
  time.sleep(5)
  msg = s.recv(100)
  if len(msg) >= 2:
    full_msg += msg.decode("utf-8")
    print (full_msg)
    cdt = datetime.datetime.now()
    min1 = str(cdt.minute)
    hour = str(cdt.hour)
    with canvas(device) as draw:
      draw.text((0, 19), full_msg, fill = "white")
      draw.text((0, 0), hour, fill = "white")
      draw.text((11, 0),":", fill = "white")
      draw.text((15, 0), min1, fill = "white")
      draw.text((0, 9), "___________", fill = "white")
      draw.text((0, 9), date, fill = "white")
      if min1 in num:
        obs = owm.weather_at_place("")#your town and country in string format again</p><p>        weather = obs.get_weather()
        temp = str(weather.get_temperature("fahrenheit")["temp"])
        draw.text((32, 0), "F", fill = "white")
        draw.text((40, 0), temp, fill = "white")
      if min1 not in num:
        draw.text((40, 0), temp3, fill = "white")
        draw.text((32, 0), "F", fill = "white")
  if len(msg) <= 1:
    cdt = datetime.datetime.now()
    min1 = str(cdt.minute)
    hour = str(cdt.hour)
    with canvas(device) as draw:
      draw.text((0, 0), hour, fill = "white")
      draw.text((11, 0),":", fill = "white")
      draw.text((15, 0), min1, fill = "white")
      draw.text((0, 9), "___________", fill = "white")
      draw.text((0, 9), date, fill = "white")
      if min1 in num:
        obs = owm.weather_at_place("")#your town and country in string format again</p><p>        weather = obs.get_weather()
        temp = str(weather.get_temperature("fahrenheit")["temp"])
        draw.text((32, 0), "F", fill = "white")
        draw.text((40, 0), temp, fill = "white")
      if min1 not in num:
        draw.text((40, 0), temp3, fill = "white")
        draw.text((32, 0), "F", fill = "white")
  time.sleep(5.4)
  full_msg1 = " "
  msg1 = s.recv(100)
  if len(msg1) >= 2:
   full_msg1 += msg1.decode("utf-8")
   full_msg2 = ("\n".join(textwrap.wrap(full_msg1, 9)))
    cdt = datetime.datetime.now()
    min1 = str(cdt.minute)
    hour = str(cdt.hour)
    with canvas(device) as draw:
      draw.text((0, 19), full_msg, fill = "white")
      draw.text((0, 29), full_msg2, fill = "white")
      draw.text((0, 0), hour, fill = "white")
      draw.text((11, 0),":", fill = "white")
      draw.text((15, 0), min1, fill = "white")
      draw.text((0, 9), "___________", fill = "white")
      draw.text((0, 9), date, fill = "white")
      if min1 in num:
        obs = owm.weather_at_place("")#your town and country in string format again</p><p>        weather = obs.get_weather()
        temp = str(weather.get_temperature("fahrenheit")["temp"])
        draw.text((32, 0), "F", fill = "white")
        draw.text((40, 0), temp, fill = "white")
      if min1 not in num:
        obs = owm.weather_at_place("")#your town and country in string format again</p><p>        weather = obs.get_weather()
        temp = str(weather.get_temperature("fahrenheit")["temp"])
        draw.text((32, 0), "F", fill = "white")
        draw.text((40, 0), temp, fill = "white")
      if min1 not in num:
        draw.text((40, 0), temp3, fill = "white")
        draw.text((32, 0), "F", fill = "white")
  if len(msg1) <= 1:
    cdt = datetime.datetime.now()
    min1 = str(cdt.minute)
    hour = str(cdt.hour)
    with canvas(device) as draw:
      draw.text((0, 0), hour, fill = "white")
      draw.text((11, 0),":", fill = "white")
      draw.text((15, 0), min1, fill = "white")
      draw.text((0, 9), "___________", fill = "white")
      draw.text((0, 9), date, fill = "white")
      if min1 in num:
        obs = owm.weather_at_place("")#your town and country in string format again</p><p>        weather = obs.get_weather()
        temp = str(weather.get_temperature("fahrenheit")["temp"])
        draw.text((32, 0), "F", fill = "white")
        draw.text((40, 0), temp, fill = "white")
      if min1 not in num:
        draw.text((40, 0), temp3, fill = "white")
        draw.text((32, 0), "F", fill = "white")
  time.sleep(7)
  client.files_delete(dropbox_path)
  print ("Files deleted")</p>

P.S. I'm an amateur programmer so please don't question my horrible programing methods.

Step 4: Putting It All Together!

Once you have finished everything else you are practically done all you have left to do is attach the raspberry pi camera and display to the glasses. You can do this by using the double sided adhesive mentioned in the supplies or you can use any methods you think necessary. You also might have noticed I haven't mentioned a battery anywhere in this lesson that is because I have future upgrades planned for these glasses and didn't want to attach one on right now. But if you do want to attach one you are going to need a li-po charger circuit from amazon https://www.amazon.com/McIgIcM-Lithium-Charging-Pr...

If you enjoyed this and want to see more, I have started a YouTube channel and will hopefully be posting tutorials on there as well. Here is the link:

https://www.youtube.com/channel/UCGqcWhHXdZf231rLe...

God Saves!

John 3:16 "For God so loved the world that He gave His one and only Son the who so ever believes in Him shall not perish but have an everlasting life."

Wearables Contest

Participated in the
Wearables Contest

Be the First to Share

    Recommendations

    • Arduino Contest

      Arduino Contest
    • Barbecue Speed Challenge

      Barbecue Speed Challenge
    • Colors of the Rainbow Contest

      Colors of the Rainbow Contest

    3 Comments

    2
    Samlikesham
    Samlikesham

    1 year ago

    This is amazing and very impressive

    1
    Bradley_Campbell
    Bradley_Campbell

    Reply 1 year ago

    Thanks! it took a while to do because I basically know nothing about python lol

    1
    Samlikesham
    Samlikesham

    Reply 1 year ago

    Yeah me neither 🤣🤣