def init_from_file(self, filename): json_file_content = open(filename, 'r').read() params = json.loads(json_file_content) if 'nanpy_dev' in params['communication']: serial_manager.connect(params['communication']['nanpy_dev']) self.set_communication(params['communication']['type'], **params['communication']['parameters']) for module in params['modules']: self.add_module(module['name'], module['type'], **module['parameters'])
#!/usr/bin/env python # LED with 560 Ohm resistor on Pin 10 to GND # Tony Goodhew - 10 May 2013 from nanpy import Arduino from nanpy import serial_manager serial_manager.connect('/dev/ttyACM0') # serial connection to Arduino from time import sleep import time #import plotly.plotly as py #import json import time import datetime from drawnow import * import matplotlib.pyplot as plt #from bokeh import pyplot #from bokeh import plotting import mpld3 #with open('./config.json') as config_file: #plotly_user_config = json.load(config_file) #py.sign_in(plotly_user_config["plotly_username"], plotly_user_config["plotly_api_key"]) #url = py.plot([ #{ #'x': [], 'y': [], 'type': 'scatter', #'stream': { #'token': plotly_user_config['plotly_streaming_tokens'][0], #axpoints': 200 #} #}], filename='aRi Analytics Demonstration')
## ## filename: demoCore.py ## import os import serial import re import datetime from nanpy import Arduino from nanpy import serial_manager serial_manager.connect('/dev/ttyACM0') from time import sleep import time import json analogPort = 0 powervoltage = 5. CURRENTDIR = os.path.dirname(__file__) BASEDIR = os.path.dirname(CURRENTDIR) last_received = '' class TempCore(): def index(self,request): json = 0 data = 0 if request.args.get('json', '') == "1":
#!/usr/bin/env python # import the necessary packages import serial import numpy as np from nanpy import Arduino from nanpy import serial_manager from picamera.array import PiRGBArray from picamera import PiCamera import time import cv2 serial_manager.connect('/dev/ttyACM0') # serial connection to Arduino ## Image Processing # initialize the camera and grab a reference to the raw camera capture camera = PiCamera() camera.resolution = (640, 480) camera.framerate = 32 rawCapture = PiRGBArray(camera, size=(640, 480)) # allow the camera to warmup time.sleep(0.1) # capture frames from the camera for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True): # grab the raw NumPy array representing the image, then initialize the timestamp # and occupied/unoccupied text image = frame.array
from flask import Flask from flask import render_template, flash, redirect, session, url_for, request, g, jsonify from nanpy import Arduino from nanpy import serial_manager #from flask.ext.login import login_user, logout_user, current_user, login_required from time import sleep from datetime import datetime import datetime as dt from decorators import async """ direction pin for motor B is Digital 12. Speed pin for motor B is Digital 9 (PWM) Diretion pin for motor A is Digital 13. Speed pin or motor A is Digital 10 (PWM) YG GY """ serial_manager.connect('/dev/ttyACM0') app = Flask(__name__) DIR_B_PIN = 12 # direction pin b SPEED_B_PIN = 9 # speed pin b DIR_A_PIN = 13 # direction pin a SPEED_A_PIN = 10 # speed pin a LED_PIN_R = 3 LED_PIN_G = 5 LED_PIN_B = 6 @app.route('/led_test/<r>/<g>/<b>') def led_test(r, g, b): r_val, g_val, b_val = int(r), int(g), int(b)
def serialconnection(self): self._con = serial_manager.connect(self.unit['device'])