def __init__(self, serialport, baudrate=19200, heatTime=80, heatInterval=2, heatingDots=7):
        self.printer = streams.serial(serialport,baudrate)        
        self.write(self._ESC) # ESC - command
        self.write(chr(64)) # @   - initialize
        self.write(self._ESC) # ESC - command
        self.write(chr(55)) # 7   - print settings
        self.write(chr(heatingDots))  # Heating dots (20=balance of darkness vs no jams) default = 20
        self.write(chr(heatTime)) # heatTime Library default = 255 (max)
        self.write(chr(heatInterval)) # Heat interval (500 uS = slower, but darker) default = 250

        # Description of print density from page 23 of the manual:
        # DC2 # n Set printing density
        # Decimal: 18 35 n
        # D4..D0 of n is used to set the printing density. Density is 50% + 5% * n(D4-D0) printing density.
        # D7..D5 of n is used to set the printing break time. Break time is n(D7-D5)*250us.
        printDensity = 15 # 120% (? can go higher, text is darker but fuzzy)
        printBreakTime = 15 # 500 uS
        self.write(chr(18))
        self.write(chr(35))
        self.write(chr((printDensity << 4) | printBreakTime))
Ejemplo n.º 2
0
################################################################################
# Timers Basics
#
# Created by VIPER Team 2015 CC
# Authors: G. Baldi, D. Mazzei
################################################################################

import timers
import streams

#create a serial port with default parameters
streams.serial()

#create a new timer
t=timers.timer()
#start the timer
t.start()

minutes=0
   
while True:
    
    if t.get()>= 60000:        #check if 60 seconds are passed
        t.reset()              #timer can be reset
        minutes +=1
    seconds=t.get()//1000
    print("time is:", minutes,":",seconds) #just print the current value since timer starts or last reset
    print("System time is:", timers.now(), "(millis)") #timers.now() gives the system time in milliseconds since program starts
    print()
    
    sleep(500)                 #run every 500 millisec
Ejemplo n.º 3
0
# VIPER IoT Notes Printer
#
# Created by VIPER Team 2015 CC
# Authors: G. Baldi, D. Mazzei
################################################################################

# import everything needed
import streams
from drivers.thermalprinter import thermalprinter
from wireless import wifi
from drivers.wifi.cc3000 import cc3000_tiny as cc3000
# and also import the viperapp module
from libs.apps import viperapp
p = thermalprinter.ThermalPrinter(SERIAL1,19200)

s=streams.serial()

# save the template.html in the board flash with new_resource
new_resource("template.html")

# connect to a wifi network
try:
    cc3000.auto_init()

    print("Establishing Link...")
    wifi.link("SSID_WiFi",wifi.WIFI_WPA2,"PWD_WiFi")
    print("Ok!")        
except Exception as e:
    print(e)

def printMessage(msg):
Ejemplo n.º 4
0
#
# Created by VIPER Team 2015 CC
# Authors: D. Mazzei, G. Baldi,  
###############################################################################

import streams

from drivers.thermalprinter import thermalprinter

# create a printer passing to the class the serial port name. Printer RX wire have to be connected 
# to the selected serial port TX pin. The default baudrate for the thermal printers is 19200
# In this case SERIAL1 is used. In Arduino the serial 1 TX pin is D18 while in the Nucleo is on the morphos connector (seventh from the top on the right series)
p = thermalprinter.ThermalPrinter(SERIAL1,19200)

# another serial port for printign on the console
s= streams.serial(SERIAL0)

def test(printer):  
    # print_text(msg,"a","s") takes as input a string containing the massage and two characters for the definition of the a:allignment and s:syle    
    # first character denotes justification (l=left, c=centre, r=right)
    # second character denotes style (n=normal, b=bold, u=undfrom drivers.thermalprinter erline, i=inverse, f=font B)
    # normal style with left alignment is the default
    # \n is required for line termination
    
    p.print_text("Default\n")
    p.print_text("Left and Bold\n","l","b")
    p.print_text("Center and Underlined\n","c","u")
    p.print_text("Right and Inverted\n","r","i")
    p.print_text("Left and Font B\n\n","l","f")    

    #print_text also supports auto line ending giving as input chars_per_line as last parameter
Ejemplo n.º 5
0
import streams

# import toishield module
from toishield import toishield

# define three functions that print three different messages


def single():
    print("touch")


def double():
    print("double")


def loong():
    print("loong")


streams.serial()

# set 'single' as the function to be executed after the first touch of the TOI Shield
# touch sensor and 'double' after the second. To really execute these functions touch
# has to respect some time constraints: first touch must be of at least 50 milliseconds
# to be considered voluntary and must not be longer than 1500 milliseconds, furthermore
# not more than 1000 milliseconds shall pass between the first and second touch to consider
# two single touches a real double touch.
# The 'loong' function is executed if the 1500 milliseconds constraint is not respected.
toishield.touch.onDoubleTouch(50, 1500, 1000, single, double, loong)
Ejemplo n.º 6
0
################################################################################
# Serial Port Basics
#
# Created by Zerynth Team 2015 CC
# Authors: G. Baldi, D. Mazzei
################################################################################

import streams
# creates a serial port and name it "s"
s = streams.serial()

while True:
    print(
        "Write some chars on the serial port and terminate with \\n (new line)"
    )
    line = s.readline(
    )  # read and return any single character available on the serial port until a \n is found
    print("You wrote:", line)
    print()
    sleep(300)
Ejemplo n.º 7
0
CHARGE_COMPLETE = 2
IGNITION_OFF = 0
IGNITION_ON = 1
SOS_OFF = 0
SOS_ON = 1

# Private globals
_ANALOG_VREF = 2.50
_ANALOG_SCALE = 13.0154525
_ANALOG_SCALE_LOW = 2.0
_ADC2VOLT = _ANALOG_VREF * _ANALOG_SCALE / 4095
_ADC2VOLT_LOW = _ANALOG_VREF * _ANALOG_SCALE_LOW / 4095

# Default initialization
import streams
streams.serial(SERIAL0)
import adc


def init():
    """
.. function:: init()

    Performs required initializion of Polaris pins and common functionalities.
    It should be called at the start of your application.
    """
    # Setup power
    digitalWrite(internal.PIN_POWER_DIS, LOW)
    pinMode(internal.PIN_POWER_DIS, OUTPUT)
    digitalWrite(internal.PIN_POWER_DIS, LOW)
    pinMode(internal.PIN_BATT_EN, INPUT)
Ejemplo n.º 8
0
def widget_choice_cbk(_widget_choice, _):
    global widget_choice
    widget_choice = _widget_choice - __ORD('0')
    widget_choice_evt.set()


palette_default = bt81x.Palette((0xff, 0xff, 0xff),
                                foreground=(0x3c, 0x82, 0x82))
txt = bt81x.Text(0,
                 0,
                 31,
                 bt81x.OPT_CENTERX | bt81x.OPT_CENTERY,
                 "",
                 palette=palette_default)

streams.serial()  # open serial channel to display debug messages

print('> Init chip')
bt81x.init(SPI0, D4, D33, D34)
bt81x.touch_loop(
    ((-1, widget_choice_cbk),
     ))  # listen to touch events and make widget_choice_cbk process them


def widget_selection():
    bt81x.dl_start()
    bt81x.clear(1, 1, 1)

    txt.font = 31
    txt.text = "Choose a widget"
    txt.x = bt81x.display_conf.width // 2
Ejemplo n.º 9
0
    tx_hash = eth.rpc.sendTransaction(tx.to_rlp(True))
    print("> Monitor transaction at:\nhttps://ropsten.etherscan.io/tx/%s" %
          tx_hash)


def ethereum_store():
    tx_mutex.acquire()
    config.led_start_transaction()
    temp, hum = sensor.get_temp(), sensor.get_hum()
    thing.mqtt.publish(config.config['TOPIC'], {'touch': True})
    send_eth_transaction(temp, hum)
    config.led_end_transaction()
    tx_mutex.release()


ser_ch = streams.serial()
config.led_init()

wifi_driver.init()
for _ in range(3):
    try:
        print("> Establishing Link...")
        wifi.link(config.config['SSID'], wifi.WIFI_WPA2, config.config['PSW'])
        break
    except Exception as e:
        print("> ooops, something wrong while linking :(")
else:
    mcu.reset()
print("> linked!")

tx_mutex = threading.Lock()
Ejemplo n.º 10
0
################################################################################
# lcd
#
# Created: 2016-04-06 14:35:49.885160
#
################################################################################

import streams
import serLCD

error = streams.serial()
try:

    lcd = serLCD.serLCD(SERIAL1)
    lcd.clear()
    lcd.home()

    lcd.writeLine(0, 'Hello World!!')
    lcd.writeLine(1, 'Zerynth Team')

    thread(lcd.scrollingLeftToRight(1000, 1000))

    print('ok1', end='', stream=error)
except Exception as e:
    print(e, stream=error)
Ejemplo n.º 11
0
def relay_on():
    digitalWrite(D23, HIGH)
    
def relay_off():
    digitalWrite(D23, LOW)

pin = ""                #pin which user enter
valid_pin = "1234"      #valid pin
valid_pin2 = "2580" 
screenLayout = 0        #window currently used
wait = False
counter = 0
user2 = False

#serial communication
pc = streams.serial() 
ser = streams.serial(SERIAL1, baud=9600,set_default=False)

evr = easyvr.EasyVR(ser)

#buttons handler
def pressed(tag, tracked, tp):
    
    global screenLayout
    global pin
    global wait
    global counter
    global user2
    
    #if we are in pinscreen
    if (screenLayout == 2):
Ejemplo n.º 12
0
# Eseye Anynet AWS Publish and Subscribe example
# Created at 2018-04-11 09:09:21.039592

import streams
from eseye.anynetaws import anynetaws as aws

def my_callback(index, topic, data):
    print('> callback from', topic)
    print('> content:', data)

main_ser = streams.serial()
aws.init(SERIAL2) # select the serial driver the modem is connected to

print('> subscribe...')
# subscribe to mychannel/commands/thingname and mychannel/cloudmessages/thingname topics
aws.subscribe('mychannel/commands', my_callback, sock_index=0)
aws.subscribe('mychannel/cloudmessages', my_callback, sock_index=1)
print('> subscriptions completed!')

while True:
    print('> [ENTER] to publish')
    main_ser.readline()
    print('> publish...')
    # publish a message on topic mychannel/devices/thingname
    aws.publish('mychannel/devices', 'hello!')
    print('> publish completed!')
Ejemplo n.º 13
0
# Temp&humidty Web Server
#
# Created by Zerynth Team 2018 CC
# Authors: K.Hamdy
###############################################################################

# import streams & socket
import streams
import socket

# import the wifi interface
from wireless import wifi
from espressif.esp32net import esp32wifi as wifi_driver  #importing Esp32 Wifi driver
from stm.hts221 import hts221

streams.serial()  #initate serial driver
temp_hum = hts221.HTS221(I2C0, D16)  #initiate i2C protocol with the sensor

WifiAP_name = "TOI"
Wifi_Pass = "******"

wifi_driver.auto_init()
print("Establishing Link...")
try:
    wifi.link(WifiAP_name, wifi.WIFI_WPA2, Wifi_Pass)
except Exception as e:
    print("ooops, something wrong while linking :(", e)
    while True:
        sleep(1000)

print("Linked!")
Ejemplo n.º 14
0
from aws.iot import iot
import helpers
pinMode(2, OUTPUT)
new_resource('private.pem.key')
new_resource('certificate.pem.crt')
new_resource('thing.conf.json')


def shadow_callback(requested):
    global publish_period
    print('requested publish period:', requested['publish_period'])
    publish_period = requested['publish_period']
    return {'publish_period': publish_period}


ser2 = streams.serial(SERIAL2)
#ser2 = streams.serial()
wifi_driver.auto_init()

print('connecting to wifi...')
i = 5
while (i):
    digitalWrite(2, HIGH)
    sleep(100)
    digitalWrite(2, LOW)
    sleep(100)
    i -= 1
#Enter Wifi Name and Password here:
wifi.link("STUXNET", wifi.WIFI_WPA2, "telnet#202928")
digitalWrite(2, HIGH)
pkey, clicert = helpers.load_key_cert('private.pem.key', 'certificate.pem.crt')