Aloe Ninja

Ticker Monitor

A simple device that allows you to monitor the stock price.

Ticker Monitor Exterior

Ticker monitor based on ESP-12F module and e-paper screen.

A ticker symbol is a unique identifier for an exchange instrument.

Materials

  • ESP-12F module
  • Screen based on Waveshare 2.13in V2 e-ink technology
  • Capacitors 10uF and 0.1uF, two each
  • Resistor 4.7k
  • Linear stabilizer LM1117–3.3
  • Breakout-wired mini-USB connector
  • Double-sided breadboard 7x3cm
  • Wire 32AWG

Ticker Monitor Components

To flash the module, you will need a USB-UART converter with an output high logic level of 3.3V.

Schematics

Next, you need to show your mad skillz and connect the parts together according to the scheme.

Power stabilizer

The stabilizer is placed in a separate circuit, because it is common to almost all of my crafts on ESP8266 modules.

Controller

E-Paper Screen

The pins GND, DIN, CLK, CS, DC, RST, BUSY should be connected to the corresponding screen pins. VCC screen is +3.3V on the diagram.

Buttons ESPRST and FLASH are needed to reset the module and switch to firmware upload mode.

I got this mess and I’m fine with it:

Ticker Monitor Exterior back

The device does not have a “case”. The boards are attached to what I call a “micro-information stand”. If you decide not to make your own body, the print files can be downloaded from the Onshape project.

In the slicer, it is desirable to orient the model so that the drop-shaped holes are directed with the sharp end up.

Micro Info Stand

Code

We will receive information about the current share price using the IEXCloud API . There you need to register and create a publishable token, which is then specified in the config.

# boot.py

import gc
import network
import esp
esp.osdebug(None)
gc.collect()
# config.py

essid = "YourSSID"
password = "yourwifipassword"
TIMEZONE = 8
TOKEN = 'pk_123123123'
SYMBOLS = ('AMD', 'NVDA', 'INTC', 'ROSYY', 'AAPL', 'BA', 'GOOG', 'MSFT', 'MU', 'FB')
# main.py

import epaper2in13v2
import machine
import time
import ntptime
import framebuf
import usocket as socket
import ussl as ssl
from config import *


def connect():
    sta_if = network.WLAN(network.STA_IF)
    if not sta_if.isconnected():
        print("Connecting to {}...".format(essid))
        sta_if.active(True)
        sta_if.connect(essid, password)
        while not sta_if.isconnected():
            pass
    print("Network config:", sta_if.ifconfig())

connect()

def get_price(sym):
    try:
        sock = socket.socket()
        addr_info = socket.getaddrinfo("cloud.iexapis.com", 443)
        addr = addr_info[0][-1]
        req = 'GET /stable/stock/' + sym + '/quote/latestPrice?token=' + TOKEN + ' HTTP/1.0\r\n\r\n'
        sock.connect(addr)
        secure_sock = ssl.wrap_socket(sock)
        secure_sock.write(req.encode())
        response = secure_sock.read().decode().split('\r\n')
        secure_sock.close()
        sock.close()
    except:
        return 'ERR'
    else:
        return response[-1]

rtc = machine.RTC()
try:
    ntptime.settime()
except:
    print('Error setting time')
    machine.reset()

sec = time.time() + TIMEZONE * 3600
localtime = time.localtime(sec)

cs_pin = machine.Pin(15)
dc_pin = machine.Pin(2)
rst_pin = machine.Pin(4)
busy_pin = machine.Pin(10)
hsspi = machine.SPI(1, baudrate=4000000, polarity=0, phase=0)

e_display = epaper2in13v2.EPD(hsspi, cs_pin, dc_pin, rst_pin, busy_pin)
e_display.init()
e_display.set_full_update_mode()

e_display.clear_display(0xff)

buf = bytearray(128 * 250 // 8)
fb = framebuf.FrameBuffer(buf, 128, 250, framebuf.MONO_HLSB)

fb.fill(1)
fb.fill_rect(0, 0, 122, 22, 0)
fb.text('{2:02d}-{1:02d}-{0:02d}'.format(*localtime), 2, 2, 1)
fb.text('{3:02d}:{4:02d}'.format(*localtime), 2, 12, 1)

for i, symbol in enumerate(SYMBOLS):
    price = get_price(symbol)
    print(symbol, price)
    fb.text(symbol, 0, 16*(i+2)+2, 0)
    fb.text(price, 122-len(price)*8, 16*(i+2)+2, 0)

e_display.display_master_image(buf)

rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)
rtc.alarm(rtc.ALARM0, time.ticks_ms() + 900*1000)
print('Entering deepsleep')
machine.deepsleep()

Also, the config contains the name and password of the wireless network, the time zone and, in fact, the list of tickers.

In the directory with the project, you still need to download the library for working with the display.

Firmware upload

You will need esptool and rshell to download the firmware .

I was using the latest, at the time of writing, stable version of micropython 1.13.

After connecting the module via USB - UART converter, the firmware is loaded using esptool:

esptool.py --port /dev/ttyUSB0 --baud 115200 write_flash --flash_size=detect -fm dio -ff 40m 0 esp8266–20200911-v1.13.bin

In my case, it was necessary to use the dio mode and the flash memory frequency of 40MHz ( -fm dio -ff 40m) otherwise the module refused to start, although it was flashed successfully.

Next, you need to load the code into the python module:

rshell -p /dev/ttyUSB0 -b 115200 cp config.py boot.py epaper2in13v2.py main.py /pyboard

Notes

IEXCloud allows 50,000 requests per month for free, so the module launch interval can be reduced from one hour to 9 minutes, as long as the number of tracked tickers remains at 10.

When assembling the device, you should consider increasing the capacitance of the electrolytic capacitors to 100uF, especially if it will be connected with a long and thin USB cable.


Original article on Medium

License

CC BY-SA 4.0

↑ Top