def main(): global getAxes global this from machine import Pin, I2C import adxl345 i2c = I2C(0, scl=Pin(22), sda=Pin(21)) a = adxl345.ADXL345(i2c, 83) this = ACCELEROMETER(a, 'adxl345_calibration_2point') getAxes = this.getAxes
def accelerometer(): accel = adxl345.ADXL345() axes = accel.getAxes(True) print '\n\nACCELERATION....\n\n' x = axes['x'] y = axes['y'] z = axes['z'] print x print y print z return x, y, z
def main(): global read # make function global global this from machine import Pin, I2C import adxl345 import VL53L0X import accelerometer i2c = I2C(0, scl=Pin(22), sda=Pin(21)) adxl = adxl345.ADXL345(i2c, 83) a = accelerometer.ACCELEROMETER(adxl, 'adxl345_calibration_2point') tof = VL53L0X.VL53L0X(i2c, 41) this = HeightTiltCompensator(a, tof) this.offset = -50 read = this.read # make function callable (so we can call distance.read() )
def raw_to_value(detect): accel = adxl345.ADXL345() axes = accel.getAxes(True) accel.setRange(adxl345.RANGE_16G) while (not detect): x = axes['x'] y = axes['y'] z = axes['z'] l1 = [] l1.append(x) l1.append(y) l1.append(z) return l1
def log(): log_string = "" date = str(datetime.now()).replace(" ", ",").split(".")[0] gps_p = GPS.souradnice() gps = gps_p[0] + gps_p[1] + "," + gps_p[2] + gps_p[3] gps_nm = str(GPS.nad_morska_vyska()) gps_ps = str(GPS.pocet_satelitu()) gps_kvalita = str(GPS.kvalita_signalu_GPS()) cpu_t = str(CPUtemp.getCPUtemperature()) temp = teplotaDS.getDCtemp() dc_t = str(temp[0]) + "," + temp[1] rssi = str(log_RSSI.get_RSSI()) adxl = adxl345.ADXL345().getAxes() acc = str(adxl["x"]) + "," + str(adxl["y"]) + "," + str(adxl["z"])
def __init__(self): # initiaize the Motor object ### left motor's pins self.in1 = 18 # lf_pin1 self.in2 = 23 # lf_pin2 # enA = x (left motor 'PWM' for speed - not used) ### right motor's pins self.in3 = 24 # rt_pin1 self.in4 = 25 # rt_pin2 # enB = y (right motor 'PWM' for speed - not used) GPIO.setmode(GPIO.BCM) GPIO.setup(self.in1, GPIO.OUT) GPIO.setup(self.in2, GPIO.OUT) GPIO.setup(self.in3, GPIO.OUT) GPIO.setup(self.in4, GPIO.OUT) self.lf_pin1 = 0 self.lf_pin2 = 0 self.rt_pin1 = 0 self.rt_pin2 = 0 GPIO.output(self.in1, self.lf_pin1) GPIO.output(self.in2, self.lf_pin2) GPIO.output(self.in3, self.rt_pin1) GPIO.output(self.in4, self.rt_pin2) self.p_status = 'Init/IN' # previous motor status self.p_rgb = (255, 255, 0) # previous rgb status - yellow self.m_status = 'Init/IN' # current motor status self.rgb_status = (255, 255, 0) # current rgb status - yellow self.mt7219 = mLED.LED_mat() # create max7219 object self.mt7219.led_matrix(chr(79)) # 'o' sign for readiness self.lcd = lcd1602.lcd() # create lcd1602 object self.lcd.backlight(1) # turn on the lcd1602 backlight self.lcd.lcd_clear() # clear the display self.line = 'Robot Car ' # display 'Robot Car' in LCD self.lcd.lcd_display_string(self.line, 1) self.rgb_bulb = rgb.RGB_led() # create RGB object self.rgb_bulb.led_RGB_setColor((255, 255, 0)) # yellow colour time.sleep(0.1) self.sonic = sc.Sonic_dev() # create the ultrasionic object self.servo = sv.Servo() # create the servo object self.adxl345 = adxl.ADXL345() # create the ADXL345 object print(self.m_status)
def acquire_data(seconds=20): # Constants and things bmp_file = "bmpdata.txt" lidar_file = "lidardata.txt" # I2C Object i2c = I2C(0, scl=Pin(22), sda=Pin(21)) # Configure BMP BMP.set_oversampling(i2c) cal = BMP.read_coefficients(i2c) # Configure VL50LOX adxl = ADX.ADXL345(i2c, 83) a = ACCEL.accelerometer(adxl, 'adxl345_calibration_2point') lidar = L0X.VL53L0X(i2c, 41) this = height_lidar(a, lidar) # main loop: for i in range(seconds): # BMP BMPdata = BMP.get_altitude(i2c, cal) write_data( bmp_file, str(BMPdata[0]) + "," + str(BMPdata[1]) + "," + str(BMPdata[2]) + "," + str(BMPdata[3])) print("BMP " + str(i) + '>\t' + str(BMPdata[0])) # optional # LIDAR LIDARdata = str(this.read) write_data(lidar_file, LIDARdata) print("LDR " + str(i) + '>\t' + LIDARdata) sleep(1) # Successful Completion Here return 1
def setup(): # # Declare global variables # global myRegId global myUsername global myPassword global myToken global contactid global subject global ws global adxl # # setup Raspberry Pi ADXL345 # see http://shop.pimoroni.com/products/adafruit-triple-axis-accelerometer # if not simulation_mode: adxl = adxl345.ADXL345() #adxl.setRange(adxl345.RANGE_2G) adxl.setRange(adxl345.RANGE_16G) # # Read configuration from file # config = ConfigParser.RawConfigParser() config.read('salesforce_login.cfg') # # Establish Websockt connection for monitoring chat service # if chat_mode: ws_url = config.get('Chat', 'ws_url') ws = create_connection(ws_url) # # Lookup Salesforce demo org credentials and configuration # sf_lookup = Salesforce(username=config.get('Salesforce', 'username'), password=config.get('Salesforce', 'password'), security_token=config.get('Salesforce', 'security_token')) result = sf_lookup.query( "SELECT Id, Username__c, Password__c, Security_Token__c, Case_Contact_Id__c, Case_Subject__c FROM Raspberry_Pi_Demo__c WHERE Active__c = true AND Raspi_Hostname__c = " + config.get('Host', 'hostname')) # # Register new demo run # myRegId = result.get('records')[0].get('Id') sf_lookup.Raspberry_Pi_Demo_Registration__c.create({ 'Raspberry_Pi_Demo__c': myRegId, 'Status__c': 'connected' }) myUsername = result.get('records')[0].get('Username__c') myPassword = result.get('records')[0].get('Password__c') myToken = result.get('records')[0].get('Security_Token__c') contactid = result.get('records')[0].get('Case_Contact_Id__c') subject = result.get('records')[0].get('Case_Subject__c') if chat_mode: chat("Sensor", "Connection established.")
import adxl345 import time import os from gps import * import threading accelerometer = adxl345.ADXL345(i2c_port=1, address=0x53) accelerometer.load_calib_value() accelerometer.set_data_rate(data_rate=adxl345.DataRate.R_100) accelerometer.set_range(g_range=adxl345.Range.G_2, full_res=True) accelerometer.measure_start() #accelerometer.calibrate() # Calibrate only one time gpsd = None #seting the global variable os.system('clear') #clear the terminal (optional) i = 0 class GpsPoller(threading.Thread): def __init__(self): threading.Thread.__init__(self) global gpsd #bring it in scope gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info self.current_value = None self.running = True #setting the thread running to true def run(self): global gpsd while gpsp.running:
def accel_logger(): global inLocSync #create ADXL345 object accel = adxl345.ADXL345() max_x = max_y = max_z = -20 min_x = min_y = min_z = 20 sum_x = sum_y = sum_z = 0 c = 0 while not inLocSync: time.sleep(5) next = time.time() + 1 while not done: try: #get axes as g #axes = accel.getAxes(True) # to get axes as ms^2 use axes = accel.getAxes(False) #put the axes into variables x = axes['x'] y = axes['y'] z = axes['z'] sum_x += x sum_y += y sum_z += z if x > max_x: max_x = x if y > max_y: max_y = y if z > max_z: max_z = z if x < min_x: min_x = x if y < min_y: min_y = y if z < min_z: min_z = z c += 1 now = time.time() if now > next and c != 0: acceltime = time.strftime("%Y-%m-%dT%H:%M:%S.000Z") x1 = sum_x / c y1 = sum_y / c z1 = sum_z / c lock.acquire() print( "%s A %d % 02.3f % 02.3f % 02.3f % 02.3f % 02.3f % 02.3f % 02.3f % 02.3f % 02.3f *" % (acceltime, c, min_x, x1, max_x, min_y, y1, max_y, min_z, z1, max_z)) lock.release() max_x = max_y = max_z = -20 min_x = min_y = min_z = 20 sum_x = sum_y = sum_z = 0 c = 0 next = now + 1 except IOError: pass
new_hv = 0 global settings_flag settings_flag = 0 spi = spidev.SpiDev() spi.open(0, 0) spi.max_speed_hz = 100000 spi.mode = 0b00 hv = MCP4725.MCP4725(address=0x60) sv = MCP4725.MCP4725(address=0x61) bme = BME280(t_mode=BME280_OSAMPLE_8, p_mode=BME280_OSAMPLE_8, h_mode=BME280_OSAMPLE_8) pm = pmsensor.Honeywell() adxl = adxl345.ADXL345() ads = ads1115.ADS1115() node1 = serial.Serial(port='/dev/rfcomm0', baudrate=9600, timeout=8) node2 = serial.Serial(port='/dev/rfcomm1', baudrate=9600, timeout=8) db = InfluxDBClient(database='log') def set_sv(volt): global sv global sval val = int((float(volt) / gain) * 4096 / 3.3) if val > sval: i = sval while i < val:
def accel_logger(): global inSync, gpstime #create ADXL345 object accel = adxl345.ADXL345() x0 = x1 = x2 = 0 y0 = y1 = y2 = 0 z0 = z1 = z2 = 0 c = 0 lasttime = "" while True: try: if inSync == 0: time.sleep(5) continue #get axes as g #axes = accel.getAxes(True) # to get axes as ms^2 use axes = accel.getAxes(False) #put the axes into variables x = axes['x'] y = axes['y'] z = axes['z'] x1 += x y1 += y z1 += z if x > x2: x2 = x if y > y2: y2 = y if z > z2: z2 = z if x < x0: x0 = x if y < y0: y0 = y if z < z0: z0 = z c += 1 d = datetime.datetime.utcnow() now = d.strftime("%Y-%m-%dT%H:%M:%S.000Z") if now != lasttime: lasttime = now x1 = x1 / c y1 = y1 / c z1 = z1 / c lock.acquire() print( "%f %s A %d % 02.3f % 02.3f % 02.3f % 02.3f % 02.3f % 02.3f % 02.3f % 02.3f % 02.3f *" % (time.time(), gpstime, c, x0, x1, x2, y0, y1, y2, z0, z1, z2)) lock.release() x2 = -10 x0 = 10 y2 = -10 y0 = 10 z2 = -10 z0 = 10 c = 1 except InteruptedException: quit()
import time import os import math import Adafruit_ADS1x15 import adxl345 import RPi.GPIO as gpio milli_time = lambda: int(round(time.time() * 1000)) adcf = Adafruit_ADS1x15.ADS1015(address=0x49, busnum=1) adcl = Adafruit_ADS1x15.ADS1015(address=0x4a, busnum=1) adcr = Adafruit_ADS1x15.ADS1015(address=0x48, busnum=1) adcb = Adafruit_ADS1x15.ADS1015(address=0x4b, busnum=1) accel = adxl345.ADXL345() GAIN = 1 def distfr(): return adcf.read_adc(0, gain=GAIN) def distfm(): return adcf.read_adc(2, gain=GAIN) def distfl(): return adcf.read_adc(1, gain=GAIN)
def acc(): return adxl345.ADXL345().getAxes()
import sdcard import uos #import max31865 import bmp280 import adxl345 import network from machine import ADC, Pin, I2C, SPI led = Pin(5, Pin.OUT) led.value(0) i2c = I2C(scl=Pin(22), sda=Pin(21), freq=400000) bmp280 = bmp280.BMP280(i2c) adxl345 = adxl345.ADXL345(i2c) ap = network.WLAN(network.AP_IF) ap.active(True) ap.config(essid="uPy Payload") xpin = 34 ypin = 32 zpin = 34 xadc = ADC(Pin(xpin)) yadc = ADC(Pin(ypin)) zadc = ADC(Pin(zpin)) xadc.atten(ADC.ATTN_11DB) yadc.atten(ADC.ATTN_11DB)
from math import sqrt import bluetooth #import Adafruit_BBIO.GPIO as GPIO def sumSquares(x, y, z): return sqrt(x * x + y * y + z * z) bd_addr = "F4:B7:E2:13:36:36" port = 1 falls = 0 sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM) sock.connect((bd_addr, port)) adxl345 = adxl345.ADXL345() #GPIO.setup("P9_12", GPIO.IN) #GPIO.add_event_detect("P9_12", GPIO.FALLING) print "ADXL345 on address 0x%x:" % (adxl345.address) try: while 1: if GPIO.event_detected("P9_12"): print "event detected!" axes = adxl345.getAxes(True) x = axes['x'] y = axes['y'] z = axes['z'] sumsqr = sumSquares(x, y, z) if sumsqr > 1.35: falls = falls + 1
differenceList.append(difference) if len(differenceList) > smoothness: average = sum(differenceList)/len(differenceList) differenceList.pop(0) return average else: return 0 def bars(inputt, scale=0.01): #Takes a float/int input named inputt and a float input named scale (default 0.01) #returns a visual representation of data with ascii bars. With default scale of 0.01, each # = 100. return "#" * int(scale * inputt) if __name__ == "__main__": accel = adxl345.ADXL345() #I don't know what this is for but I'm too scared to take it out. while True: orestes = ADXL345() #Orestes is my pet name for the accelerometer. The raspi is affectionatley named the Temeraire. (Only Freespace 2: Blue Planet people would get this) readingX = readAccelerometerX(orestes) readingY = readAccelerometerY(orestes) readingZ = readAccelerometerZ(orestes) timestamp = time.time() print ("{},{},{},{}".format(timestamp, readingX, readingY, readingZ)) stdout.flush()
def accel_logger(): global inSync, gpstime #create ADXL345 object accel = adxl345.ADXL345() xv = [] yv = [] zv = [] x0 = x1 = x2 = 0 y0 = y1 = y2 = 0 z0 = z1 = z2 = 0 c = 0 lasttime = "" while True: try: if inSync == 0: time.sleep(5) continue #get axes as g #axes = accel.getAxes(True) # to get axes as ms^2 use axes = accel.getAxes(False) #put the axes into variables x = axes['x'] xv.append(x) y = axes['y'] yv.append(y) z = axes['z'] zv.append(z) x1 += x y1 += y z1 += z if x > x2: x2 = x if y > y2: y2 = y if z > z2: z2 = z if x < x0: x0 = x if y < y0: y0 = y if z < z0: z0 = z c += 1 d = datetime.datetime.utcnow() now = d.strftime("%Y-%m-%dT%H:%M:%S.000Z") if now != lasttime: lasttime = now if c > 1: N = c T = 1.0 / N ls = np.linspace(0.0, 1.0, N) (ax1, ay1) = fft(ls, xv, N, T) (ax2, ay2) = fft(ls, yv, N, T) (ax3, ay3) = fft(ls, zv, N, T) lock.acquire() print "%f %s R %d %f %f %f %f %f %f *" % ( time.time(), gpstime, c, ax1, ay1, ax2, ay2, ax3, ay3) lock.release() x1 = x1 / c y1 = y1 / c z1 = z1 / c lock.acquire() #print ("%f %s A %d % 02.3f % 02.3f % 02.3f % 02.3f % 02.3f % 02.3f % 02.3f % 02.3f % 02.3f *" % (time.time(),gpstime,c,x0,x1,x2,y0,y1,y2,z0,z1,z2)) lock.release() x2 = -10 x0 = 10 y2 = -10 y0 = 10 z2 = -10 z0 = 10 c = 0 xv = [] except KeyboardInterrupt: quit()
import adxl345, spidev, time spi = spidev.SpiDev() spi.open(1, 1) # /dev/spidev1.1 acc = adxl345.ADXL345(1, 0x1D) columns = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08] buffer = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] def clearMatrix(): for i in range(0, 8): buffer[i] = 0x00 spi.xfer([columns[i], buffer[i]]) def setPixel(x, y): if (x in range(0, 8)) and (y in range(0, 8)): x += 8 x %= 8 buffer[y] = buffer[y] | (1 << x) for i in range(0, 8): spi.xfer([columns[i], buffer[i]]) def setSquare(x, y): setPixel(x - 1, y - 1) setPixel(x, y - 1) setPixel(x - 1, y) setPixel(x, y)