def run(self): my_Ard.init() while True: packet = my_Ard.listen() #packet is in dict format queueLock.acquire() if not dataQueue.full( ): #check if queue is full. If full, dont put it inside queue #print("data into queue: " + str(packet)) dataQueue.put(packet) queueLock.release()
def run(dongle, p_num, q_num): if (not arduino.connected): return if (not arduino.inited): arduino.init() # Init data direction register for output. arduino.call_response("DOUT,1\r") # Set shield pin high. arduino.call_response("DSET,1\r")
def run(dongle, p_num, q_num): if (not arduino.connected): return if (not arduino.inited): arduino.init() # Init data direction register for output. arduino.call_response("DOUT,0\r") # Set shield pin low. arduino.call_response("DCLR,0\r")
def run(dongle, p_num, q_num): #print dongle.get_version() if (not arduino.connected): return if (not arduino.inited): arduino.init() # Init data direction register for output. arduino.call_response("DOUT,0\r") # Set shield pin high. arduino.call_response("DSET,0\r")
def wake(): global isAwake global boredom_threshold global shame_threshold global anger_threshold global sick_threshold global darkness_threshold global luminosity_threshold global photographer_threshold global memory_threshold global mailto expressions.init() arduino.init() gmail.init() raspberry.init() webcam.init() cfg = ConfigParser.ConfigParser() cfg.read(["config.cfg"]) boredom_threshold = int(cfg.get("personality", "boredom_threshold")) shame_threshold = int(cfg.get("personality", "shame_threshold")) anger_threshold = int(cfg.get("personality", "anger_threshold")) sick_threshold = int(cfg.get("personality", "sick_threshold")) darkness_threshold = int(cfg.get("personality", "darkness_threshold")) luminosity_threshold = int(cfg.get("personality", "luminosity_threshold")) photographer_threshold = int( cfg.get("personality", "photographer_threshold")) memory_threshold = int(cfg.get("personality", "memory_threshold")) mailto = cfg.get("gmail", "mailto") print memory_threshold print mailto isAwake = True
def __init__(self): threading.Thread.__init__(self) my_Ard.init()
def connect_to_arduino(main_d): main_d["arduino"] = arduino.init()
#!/usr/bin/env python import serial import arduino arduino.init(debug=1) from arduino import * def setup(): pinMode(LED, OUTPUT) def loop(): # Produce "1 microsend" pulse of LED # In quotes because a board running on few-MHz clock doesn't have enough # speed to produce such short pulse, so it will be few times longer likely. # A LED also has own inertion, so pulse will be pretty visible. digitalPulse_us(LED, HIGH, 1) delay(1000) arduino.run(globals())
from arduino import listen, init import time print("Welcome to debug mode!") init() while True: packet = listen() if packet is not None: print(packet)
# i2ctst.py -- test the i2c connection # EPIC Robotz, dlb, Feb 2021 import time import sys import arduino import arduino_reg_map as reg import random okay = arduino.init() if not okay: print("Init failed.") sys.exit() data_errcnt = 0 bus_errcnt = 0 ncnt = 0 dx0 = dx1 = dx2 = 0 arduino.writereg(reg.XXX0, dx0) arduino.writereg(reg.XXX0, dx1) arduino.writereg(reg.XXX0, dx2) wregs = [reg.PWM9, reg.PWM10, reg.PWM11, reg.XXX0, reg.XXX1, reg.XXX2] wdat = [0, 0, 0, 0, 0, 0] for r in wregs: arduino.writereg(r, 0) while True: ncnt += 1 try:
#!/usr/bin/env python import arduino arduino.init(debug=True) from arduino import * def setup(): pinMode(LED, OUTPUT) def loop(): digitalWrite(LED, HIGH) delay(1000) digitalWrite(LED, LOW) delay(1000) arduino.run(globals())
def main(): stream = util.start_stream() arduino.init() last_error = None last_ipfetch = datetime.datetime.now() last_reading = datetime.datetime.now() while True: now = datetime.datetime.now() high_temp = None low_temp = None humidity = None # Read Sensors try: data = arduino.get_readings() sensors = {} messages = [] for reading in data: name = reading['name'] if 'num' not in reading.keys() \ else reading['name'] + str(reading['num']) stype = reading['name'] if isinstance(reading['value'], float): sensors[name] = {'value': reading['value'], 'type': stype} if stype == 'temp': if not high_temp: high_temp = reading['value'] low_temp = reading['value'] if reading['value'] > high_temp: high_temp = reading['value'] if reading['value'] < low_temp: low_temp = reading['value'] elif stype == 'humid': if humidity: humidity = max(humidity, reading['value']) else: humidity = reading['value'] else: msg = f'Arduino message: {reading.value}' messages.append(msg) for name, sensor in sensors.items(): if name in NAME_MAP.keys(): name = NAME_MAP[name] print(f'Updating sensor {name} {sensor}') web.set_sensor(name, sensor['value'], sensor['type']) for msg in messages: print(f'Sending message "{msg}"') web.log_message(msg, web.WARNING) # Sensor read error if not high_temp or not low_temp: if (now - last_reading).total_seconds() >= 60: print('Failed to read temperature') send = True if not last_error: last_error = now elif (now - last_error).total_seconds() < ERROR_TIMEOUT: send = False if send: web.log_message('Failed to read temperature', web.CRITICAL) web.send_email( 'CRITICAL: Temperature read failure', 'Failed to read tank temperature. Check on Oatmeal ASAP' ) last_error = now else: last_reading = now # Climate Control print( f'High temp: {high_temp}. Low temp: {low_temp}. Humidity: {humidity}' ) if high_temp and low_temp and humidity: controller.climate_control(now, high_temp, low_temp, humidity) except Exception as err: print(f'Error: {err}') traceback.print_tb(err.__traceback__) try: web.log_message(f'Error: {err}', web.CRITICAL) send = True if not last_error: last_error = now elif (now - last_error).total_seconds() < ERROR_TIMEOUT: send = False if send: web.send_email('CRITICAL: Pi Encountered an Error', f'Recovered from runtime error: {err}') last_error = now except Exception as err: print( f'CRITICAL: Exception while reporting on exception: {err}') time.sleep(10)
from xbmc import Xbmc import arduino # create our little application :) app = Flask(__name__) app.config.from_object('credentials') @app.before_request def before_request(): g.xbmc = Xbmc(app.config['USER'], app.config['PASSWORD']) @app.route('/', methods=['GET', 'POST']) def power(): if request.method == 'POST': if request.form['Action'] == 'Power': arduino.send_power() display.switch_monitor_state() elif request.form['Action'] == 'Music': g.xbmc.start_music() return redirect(url_for('power')) elif request.method == 'GET': tv_on = display.is_display_on() return render_template('power.html', tv_on=tv_on) if __name__ == '__main__': arduino.init() app.run(host='0.0.0.0')