I am using an Infineon PASCO2V01 to determine CO2 levels via a 3.3v logic board called a Beaglebone Black. I am using an i2c peripheral onboard this device to determine the IR Emitter PPM (Parts Per Million) of CO2 in the direct area of 1728 square feet.
So, I am accounting for assignment values and using the assignment operator = for making my assignments to names to be used later. My values are in hexadecimal format since I am using i2c onboard the device for relaying data.
I am also using Python3 to encompass the "quick" write up of the source.
#!/usr/bin/python3
import os
import sys
from time import sleep
import smbus
bus = smbus.SMBus(1)
addr = 0x28
SENS_STS = 0x01
PRES_REF_H = 0x0B
PRES_REF_L = 0x0C
MEAS_RATE_H = 0x02
MEAS_RATE_L = 0x03
MEAS_CFG = 0x04
MEAS_STS = 0x07
CO2PPM_H = 0x05
CO2PPM_L = 0x06
OnePlus1 = 0x00
OnePlus2 = 0x00
try:
racks = int(input("Please type a decimal or hexadecimal value: "))
rack = int(racks, 16)
while True:
if racks == 16:
bus.read_byte_data(addr, SENS_STS)
bus.read_byte_data(addr, PRES_REF_H)
bus.read_byte_data(addr, PRES_REF_L)
bus.read_byte_data(addr, MEAS_RATE_H)
bus.read_byte_data(addr, MEAS_RATE_L)
bus.read_byte_data(addr, MEAS_CFG)
bus.read_byte_data(addr, MEAS_STS)
OnePlus1 = bus.read_byte_data(addr, CO2PPM_H) << 16
sleep(5)
OnePlus2 |= bus.read_byte_data(addr, CO2PPM_L)
sleep(5)
bus.write_byte_data(addr, SENS_STS, 0x00)
bus.write_byte_data(addr, MEAS_RATE_H, 0x00)
bus.write_byte_data(addr, MEAS_RATE_L, 0x0A)
bus.write_byte_data(addr, MEAS_CFG, 0x02)
sleep(0.5)
result2 = int(OnePlus2, 16)
result1 = int(OnePlus1, 16)
print("The result of this PPM in the CO2 around here is: {}".format(result1))
print("PPM in CO2 is around: {}".format(result2))
else:
arm = binascii.unhexlify(result1, 16)
bar = binascii.unhexlify(result2, 16)
print("Um...: {}".format(arm))
print("Yep...: {}".format(bar))
except (KeyboardInterrupt, ValueError):
print("Done for now and you did not answer with a hexadecimal value...")
pass
That is my very random source for now. My error is oblivious to the changes in what will take place and does not concern me, i.e. as the source is just a monster of a trial for now.
My main concern is how to assign values via the assignment operator and use them in hexadecimal source within a program.
So, how would I utilize hex values (base 16) via i2c with a sensor to detect PPM of CO2?
There is a lot of missing data so far and I will be reviewing all and every bit of missing data from the datasheet, programming guide, and the user manual.
Right now, there is an issue with the datasheet online not allowing me to view the i2c device data for the source builds. I have my i2c circuit completed and it works but now is the trial.
I have tried other source just to run the code...
For instance, I tried:
...
racks = int(input("Please enter a value of int: "))
while True:
if racks >= 0:
bus.read_byte_data(addr, SENS_STS)
bus.read_byte_data(addr, PRES_REF_H)
bus.read_byte_data(addr, PRES_REF_L)
bus.read_byte_data(addr, MEAS_RATE_H)
bus.read_byte_data(addr, MEAS_RATE_L)
bus.read_byte_data(addr, MEAS_CFG)
bus.read_byte_data(addr, MEAS_STS)
OnePlus1 = bus.read_byte_data(addr, CO2PPM_H) << 8
sleep(5)
OnePlus2 |= bus.read_byte_data(addr, CO2PPM_L)
sleep(5)
bus.write_byte_data(addr, SENS_STS, 0x00)
bus.write_byte_data(addr, MEAS_RATE_H, 0x00)
bus.write_byte_data(addr, MEAS_RATE_L, 0x0A)
bus.write_byte_data(addr, MEAS_CFG, 0x02)
sleep(0.5)
result2 = int(OnePlus2, 16)
result1 = int(OnePlus1, 16)
print("The result of this PPM in the CO2 around here is: {}".format(result1))
print("PPM in CO2 is around: {}".format(result2))
...
Is shifting 16 bits left collective in this instance and is accepting it via the bitwise | operator valid at all?
You can see what I did with those ideas on lines:
OnePlus1 = bus.read_byte_data(addr, CO2PPM_H) << 16 # Probably should be "8" in this instance...
OnePlus2 |= bus.read_byte_data(addr, CO2PPM_L)
I am supposedly getting to the point where I should add CO2PPM_H and CO2PPM_L together in a sum of the total PPM assignments. Any guidance is welcomed.
I tried to run the python3 source via ./Gas.py and I expected to have the source run without concern for error.
So, so far. The errors are meaningless to me as I am not 100% sure how to handle smbus in Linux for i2c peripherals.