Skip to content

Added Support for SX1276 LoRa module for long range wireless communication #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jun 8, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added a transaction function to sciencelab.SPI . made code edits base…
…d on Codacy recommendations

 sciencelab.SPI.xfer created. fixes #64 . Minor changes to Sensor libraries
  • Loading branch information
jithinbp committed Jun 8, 2017
commit fff2fa21e03f29576859a15705d46ac80da5cc05
11 changes: 9 additions & 2 deletions PSL/Peripherals.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def __captureStart__(self,address,location,sample_length,total_samples,tg):
Blocking call that starts fetching data from I2C sensors like an oscilloscope fetches voltage readings
You will then have to call `__retrievebuffer__` to fetch this data, and `__dataProcessor` to process and return separate channels
refer to `capture` if you want a one-stop solution.

.. tabularcolumns:: |p{3cm}|p{11cm}|
================== ============================================================================================
**Arguments**
Expand Down Expand Up @@ -440,7 +440,7 @@ def __retrievebuffer__(self):
self.H.__sendInt__(DATA_SPLITTING)
self.H.__sendInt__(i*DATA_SPLITTING)
rem = DATA_SPLITTING*2+1
for a in range(200):
for _ in range(200):
partial = self.H.fd.read(rem) #reading int by int sometimes causes a communication error. this works better.
rem -=len(partial)
data+=partial
Expand Down Expand Up @@ -825,6 +825,13 @@ def send16_burst(self, value):
except Exception as ex:
self.raiseException(ex, "Communication Error , Function : " + inspect.currentframe().f_code.co_name)

def xfer(self,chan,data):
self.start(chan)
reply=[]
for a in data:
reply.append(self.send8(a))
self.stop(chan)
return reply

class DACCHAN:
def __init__(self, name, span, channum, **kwargs):
Expand Down
1 change: 0 additions & 1 deletion PSL/SENSORS/BH1750.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from __future__ import print_function
from numpy import int16


def connect(route, **args):
Expand Down
4 changes: 2 additions & 2 deletions PSL/SENSORS/HMC5883L.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ def setGain(self, gain):
self.gainValue = self.gain_choices.index(gain)
self.__writeCONFB__()

def getVals(self, addr, bytes):
vals = self.I2C.readBulk(self.ADDRESS, addr, bytes)
def getVals(self, addr, numbytes):
vals = self.I2C.readBulk(self.ADDRESS, addr, numbytes)
return vals

def getRaw(self):
Expand Down
9 changes: 4 additions & 5 deletions PSL/SENSORS/MLX90614.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from __future__ import print_function
from numpy import int16


def connect(route, **args):
Expand Down Expand Up @@ -27,8 +26,8 @@ def __init__(self, I2C, **args):
try:
print('switching baud to 100k')
self.I2C.configI2C(100e3)
except:
print('FAILED TO CHANGE BAUD RATE')
except Exception as e:
print('FAILED TO CHANGE BAUD RATE',e.message)

def select_source(self, source):
if source == 'object temperature':
Expand All @@ -40,8 +39,8 @@ def readReg(self, addr):
x = self.getVals(addr, 2)
print(hex(addr), hex(x[0] | (x[1] << 8)))

def getVals(self, addr, bytes):
vals = self.I2C.readBulk(self.ADDRESS, addr, bytes)
def getVals(self, addr, numbytes):
vals = self.I2C.readBulk(self.ADDRESS, addr, numbytes)
return vals

def getRaw(self):
Expand Down
10 changes: 2 additions & 8 deletions PSL/SENSORS/MPU6050.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ def __init__(self, I2C, **args):
'KalmanFilter': {'dataType':'double','min':0,'max':1000,'prefix':'value: '} }
self.setGyroRange(2000)
self.setAccelRange(16)
'''
try:
self.I2C.configI2C(400e3)
except:
pass
'''
self.powerUp()
self.K = None

Expand All @@ -60,8 +54,8 @@ def KalmanFilter(self, opt):
sd = std(noise[a])
self.K[a] = KalmanFilter(1. / opt, sd ** 2)

def getVals(self, addr, bytes):
vals = self.I2C.readBulk(self.ADDRESS, addr, bytes)
def getVals(self, addr, numbytes):
vals = self.I2C.readBulk(self.ADDRESS, addr, numbytes)
return vals

def powerUp(self):
Expand Down
33 changes: 11 additions & 22 deletions PSL/SENSORS/MPU925x.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,9 @@ def __init__(self,I2C,**args):
self.params={'powerUp':None,'setGyroRange':[250,500,1000,2000],'setAccelRange':[2,4,8,16],'KalmanFilter':[.01,.1,1,10,100,1000,10000,'OFF']}
self.setGyroRange(2000)
self.setAccelRange(16)
'''
try:
self.I2C.configI2C(400e3)
except:
pass
'''
self.powerUp()
self.K=None



def KalmanFilter(self,opt):
if opt=='OFF':
self.K=None
Expand All @@ -62,9 +54,8 @@ def KalmanFilter(self,opt):
sd = std(noise[a])
self.K[a] = KalmanFilter(1./opt, sd**2)

def getVals(self,addr,bytes):
vals = self.I2C.readBulk(self.ADDRESS,addr,bytes)
return vals
def getVals(self,addr,numbytes):
return self.I2C.readBulk(self.ADDRESS,addr,numbytes)

def powerUp(self):
self.I2C.writeBulk(self.ADDRESS,[0x6B,0])
Expand All @@ -79,8 +70,7 @@ def setAccelRange(self,rs):

def getRaw(self):
'''
This method must be defined if you want GUIs to use this class to generate
plots on the fly.
This method must be defined if you want GUIs to use this class to generate plots on the fly.
It must return a set of different values read from the sensor. such as X,Y,Z acceleration.
The length of this list must not change, and must be defined in the variable NUMPLOTS.

Expand Down Expand Up @@ -151,8 +141,8 @@ def getMag(self):

def WhoAmI(self):
'''
Returns the ID .
It is 71 for MPU9250 .
Returns the ID.
It is 71 for MPU9250.
'''
v = self.I2C.readBulk(self.ADDRESS,0x75,1)[0]
if v not in [0x71,0x73]:return 'Error %s'%hex(v)
Expand All @@ -164,8 +154,8 @@ def WhoAmI(self):

def WhoAmI_AK8963(self):
'''
Returns the ID fo magnetometer AK8963 if found.
It should be 0x48.
Returns the ID fo magnetometer AK8963 if found.
It should be 0x48.
'''
self.initMagnetometer()
v= self.I2C.readBulk(self.AK8963_ADDRESS,0,1) [0]
Expand All @@ -175,10 +165,9 @@ def WhoAmI_AK8963(self):
def initMagnetometer(self):
'''
For MPU925x with integrated magnetometer.
It's called a 10 DoF sensor, but technically speaking ,
the 3-axis Accel , 3-Axis Gyro, temperature sensor are integrated in one IC, and the 3-axis magnetometer is implemented in a
It's called a 10 DoF sensor, but technically speaking ,
the 3-axis Accel , 3-Axis Gyro, temperature sensor are integrated in one IC, and the 3-axis magnetometer is implemented in a
separate IC which can be accessed via an I2C passthrough.

Therefore , in order to detect the magnetometer via an I2C scan, the passthrough must first be enabled on IC#1 (Accel,gyro,temp)
'''
self.I2C.writeBulk(self.ADDRESS,[self.INT_PIN_CFG,0x22]) #I2C passthrough
Expand All @@ -190,8 +179,8 @@ def initMagnetometer(self):
if __name__ == "__main__":
from PSL import sciencelab
I = sciencelab.connect()
A = connect(I.I2C)
t,x,y,z = I.I2C.capture(A.ADDRESS,0x43,6,5000,1000,'int')
A = connect(I.I2C)
t,x,y,z = I.I2C.capture(A.ADDRESS,0x43,6,5000,1000,'int')
#print (t,x,y,z)
from pylab import *
plot(t,x)
Expand Down
47 changes: 24 additions & 23 deletions PSL/SENSORS/SHT21.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from __future__ import print_function
from numpy import int16
import time


Expand All @@ -9,6 +8,27 @@ def connect(route, **args):
'''
return SHT21(route, **args)

def rawToTemp( vals):
if vals:
if len(vals):
v = (vals[0] << 8) | (vals[1] & 0xFC) # make integer & remove status bits
v *= 175.72
v /= (1 << 16)
v -= 46.85
return [v]
return False

def rawToRH( vals):
if vals:
if len(vals):
v = (vals[0] << 8) | (vals[1] & 0xFC) # make integer & remove status bits
v *= 125.
v /= (1 << 16)
v -= 6
return [v]
return False



class SHT21():
RESET = 0xFE
Expand Down Expand Up @@ -38,25 +58,6 @@ def init(self):
self.I2C.writeBulk(self.ADDRESS, [self.RESET]) # soft reset
time.sleep(0.1)

def rawToTemp(self, vals):
if vals:
if len(vals):
v = (vals[0] << 8) | (vals[1] & 0xFC) # make integer & remove status bits
v *= 175.72
v /= (1 << 16)
v -= 46.85
return [v]
return False

def rawToRH(self, vals):
if vals:
if len(vals):
v = (vals[0] << 8) | (vals[1] & 0xFC) # make integer & remove status bits
v *= 125.
v /= (1 << 16)
v -= 6
return [v]
return False

@staticmethod
def _calculate_checksum(data, number_of_bytes):
Expand All @@ -69,7 +70,7 @@ def _calculate_checksum(data, number_of_bytes):
# calculates 8-Bit checksum with given polynomial
for byteCtr in range(number_of_bytes):
crc ^= (data[byteCtr])
for bit in range(8, 0, -1):
for _ in range(8, 0, -1):
if crc & 0x80:
crc = (crc << 1) ^ POLYNOMIAL
else:
Expand All @@ -95,6 +96,6 @@ def getRaw(self):
print(vals)
return False
if self.selected == self.TEMP_ADDRESS:
return self.rawToTemp(vals)
return rawToTemp(vals)
elif self.selected == self.HUMIDITY_ADDRESS:
return self.rawToRH(vals)
return rawToRH(vals)
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy