Hi, I am using 4 XBee series 2 for my project 1 is coordinator & rest 3 are routers. Now I have a problem with reading 2 analog input at the same time in python. I have been using temperature & gas sensors at the same time & both connected to pin ADC01 & ADC02. if the sensor is connected independently than it works fine & I got what I am looking for but connecting 2 sensors gives me a problem. here is my python code. if anyone knows the solution then I will be so thankful.
import numpy as np
import matplotlib.pyplot as pyplot
import matplotlib.animation as animation
import time
import serial
ser = serial.Serial()
ser.port = ‘COM5’
ser.baudrate = 9600
ser.open()
sensorA = ‘0013A2004180A78A’
sensorB = ‘0013A2004180A7CF’
sensorC = ‘0013A2004180A7C8’
voltageA = []
voltageB = []
voltageC = []
time = []
def infiniteLoop():
i = 0;
while True:
yield i
i += 1
for x in infiniteLoop():
for y in range(3):
#read data of 30 bytes & convert to Hex
x = ser.read(30).encode(“hex”)
print(x)
hexvolt = x[54:-2] #trim 28bytes & make it to 2 bytes of recieving volt.
refvolt = 1.2 #Corresponding maximum voltage xbee can transmit.
refhex = ‘03FF’ #Corresponding maximum voltage in hex, xbee can transmit.
#converting hex to decimal
rfhexDecVal = (long(refhex,16))
voltDec = (long(hexvolt,16))
#setting equation for calculating recieved voltage
rxVoltage = (refvolt * voltDec)/rfhexDecVal
macAddress = x[8:-36]
print("SensorA:")
print(sensorA.lower() == macAddress)
print("SensorB:")
print(sensorB.lower() == macAddress)
print("SensorC:")
print(sensorC.lower() == macAddress)
#if Macaddress is matched than put the voltages in list & print it
#under that address.
if sensorA.lower() == macAddress:{
voltageA.append(rxVoltage)
}
elif sensorB.lower() == macAddress.lower():{
voltageB.append(rxVoltage)
}
elif sensorC.lower() == macAddress:{
voltageC.append(rxVoltage)
}
print(len(voltageA))
for vA in voltageA:
print("SensorA Rx Voltage:")
print(vA)
print(len(voltageB))
for vB in voltageB:
print("SensorB Rx Voltage:")
print(vB)
print(len(voltageC))
for vC in voltageC:
print("SensorC Rx Voltage:")
print(vC)
This is a result i got when i test sensor seperatly
7e001a91 0013a2004180a7cf ddb0e8e80092c10501010800040800 0271 44
0013a2004180a7cf corresponding Mac address
0271 receiving voltage in hex.