HTU21D #175
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hi,
I'm wondering what do You think of adding HTU21D sensor to Your plugin?
I know it was mentioned earlier issues... And You sad that You dont have this sensor...
Ok the point... Looking at the datasheet of HTU21D and Si7021 they at the same, same commands, same bits etc.
But when i connected it to RasPi and run Si7021 script directly in the cmd Line i am getting - 1 | - 1
I went throu your Code and seen that this value represents bad address... Maybe i am running the Code wrong? Should i Add address at the end of execution command? Like ./Si7021.py 40?
Tje address of both HTU21D and Si7021 is the same 0x40
I've also tried different Code witch was working in cmd Line but not in browser :/
(before trying browser i recompiled Python program).
What do You think? Maybe together we can solve the problem and it will be easier to add that sensor :)
Yes, you need to pass the address to the script.
python Si7021.py 40If that works, you don't need to change anything anywhere, just choose Si7021 as the sensor, and put address 40.
I've added the address at the end of the line but that gave me an error:
IOError: [Errno 121] Remote I/O error
So Your code only works with SI7021 ( as You mentioned ).
I have working code for HTU21D but i dont know how to send the vaules to Your pugin
There is no way to use an external script today, I can add this feature on the next release, now, you could for example override the existing code on the SI7021 with your code and it would probably work.....
Here i have python file that is working form console and should output the same data format as Your
script
I've replaced Your file with this and compiled all python files again
but still no response
Maybe the reason is that plugin is adding address at the end of execution command?
I don't know how to get it working inside plugin :(
if you are hacking the file you need to follow the same format as mine, and accept the parameters that I pass (I'm passing the address to the command).
I'll create a feature enhancement on the future to accept external scripts to read the temperature, for now, I suggest you just using a supported sensor, there are so many already, and most are very very cheap.
Hi,
I followed your file format and made the changes below, which works for HUT21D, SI7021, and SHT21. I expect other similar parts to these will work also. I used information from "https://github.com/jaques/sht21_python.git" to create this mod. This code doesn't use smbus. I found an issue when I trying to read bytes back to back from smbus. This why I created this version.
Regards,
Robert
import fcntl
import time
import sys
SOFT_RESET = 0xFE
TEMP_NO_HOLD = 0xF3
HUM_NO_HOLD = 0xF5
I2C_SLAVE = 0x703
I2C_SLAVE_FORCE = 0x0706
I2C_DEVICE_NUM = 1
STATUS_BITS_MASK = 0xFFFC
TEMP_WAIT_TIME = 0.086
HUM_WAIT_TIME = 0.030
if len(sys.argv) == 2:
address = int(sys.argv[1],16)
else:
print('-1 | -1')
sys.exit(1)
i2c = open('/dev/i2c-%s' % I2C_DEVICE_NUM, 'r+', 0)
fcntl.ioctl(i2c, I2C_SLAVE, address)
i2c.write(chr(SOFT_RESET))
time.sleep(0.050)
i2c.write(chr(TEMP_NO_HOLD))
time.sleep(TEMP_WAIT_TIME)
data = i2c.read(3)
unadjusted = (ord(data[0]) << 8) + ord(data[1])
unadjusted &= STATUS_BITS_MASK # zero the status bits
unadjusted *= 175.72
unadjusted /= 1 << 16 # divide by 2^16
unadjusted -= 46.85
cTemp = unadjusted
i2c.write(chr(HUM_NO_HOLD))
time.sleep(HUM_WAIT_TIME)
data = i2c.read(3)
unadjusted = (ord(data[0]) << 8) + ord(data[1])
unadjusted &= STATUS_BITS_MASK # zero the status bits
unadjusted *= 125.0
unadjusted /= 1 << 16 # divide by 2^16
unadjusted -= 6
humidity = unadjusted
if humidity > 100.0:
humidity = 100
print('{0:0.1f} | {1:0.1f}'.format(cTemp, humidity))
i2c.close()
Hi there Reshuler,
I try'd Your code, and after running sudo python filename.py 40 i get nothing . If i dont write address at the end of the command i'm getting -1 | -1 value
Do You know what can be a problem ?
Hi Shalvan,
Please send me the code you are using, information the temperature module you are using, and the I2C address of the temperature module you are using.
The software mods are working well on my side.
Are you sure you are able to talk to the Temperature module on the I2C bus? I used a logic analyzer to verify I had the correct I2C address before I modified the software.
Have you run sudo i2cdetect -y 1 to verify you temperature module is being seen on the I2c bus?
Thanks,
Robert
I ran i2cdetect -y 1 and i see that my device is at address 40
for testing i used code i posted one post above Yours, and that piece of code is working
The module i am using is HTU21D
Maybe i am missing some kind of library for python ?
You can also try and make new python file with code i posted above to see if it is working for You
or maybe i am typing wrong command in cmd line ?
i am typing
sudo python test.py 40
is that correct ?
Hi Shalvan,
It is good that you see the module at address 0x40. I’m also using a similar module.
Can you run the python code outside of the enclosure environment and see what happens?
Thanks,
Robert
This is the exact output for 0x40
pi@octopi:/oprint/lib/python2.7/site-packages/octoprint_enclosure
sudo python SI7021.py 0x40 pi@octopi:/oprint/lib/python2.7/site-packages/octoprint_enclosurefor only 40
pi@octopi:/oprint/lib/python2.7/site-packages/octoprint_enclosure
sudo python SI7021.py 40 pi@octopi:/oprint/lib/python2.7/site-packages/octoprint_enclosureand for nothing in arguments
pi@octopi:/oprint/lib/python2.7/site-packages/octoprint_enclosure $ sudo python SI7021.py
-1 | -1
pi@octopi:/oprint/lib/python2.7/site-packages/octoprint_enclosure $
and this is output from code i've posted above ( but it isnt working with the plugin)
pi@octopi:/oprint/lib/python2.7/site-packages/octoprint_enclosure $ sudo python SI7021_moje.py
25.4 | 53.3
pi@octopi:/oprint/lib/python2.7/site-packages/octoprint_enclosure $
With regards
Lucas
Hi Shalvan,
Pass it a 64. It converts the second arguments to hex.
Regards,
Robert
what do You mean about second argument ?
sudo python SI7021.py 64 and 64 is the argument ?
But still the same... :/
First argument the program name, the second argument is the value.
I would recommend that you add print statements in the code and see where the failure is. -1 | -1 is the first check/failure for passed arguments. If you are getting pass that, then you should be able to add prints in your code at various points to check the values at various points.
I’m using a HUT21 module I got off amazon, and I have it working well.
Regards,
Robert
so it seams that after
sys.exit(1)
program stops... Just before i've made a print statment and it was priting ok... i've made another print after sys.exit(1) and ... bam .. nothing
When i pasted the code into github, the spacing format wasn’t kept. The sys.exit(1) should be on the same space level the print in the line above.
The code should look like:
if len(sys.argv) == 2:
address = int(sys.argv[1], 16)
else:
print(’-1 | -1’)
sys.exit(1)
if sys.exit(1) is not at the same space (indention) as the print above, the code will always quit.
Regards,
Robert
The same thing for the humidity if. Needs spaces or humidity will always be 100.
Regards,
Robert
now its getting better :)
now i have
pi@octopi:~/oprint/lib/python2.7/site-packages/octoprint_enclosure $ sudo python SI7021.py 64
Traceback (most recent call last):
File "SI7021.py", line 26, in
i2c.write(chr(SOFT_RESET))
IOError: [Errno 121] Remote I/O error
EDIT
ok its working in the console the argument needed to be 0x40 and it started to show values
now i need to check in the plugin but i am in the midle of the print an i think it will need restart ?
EDIT 2
after changes in teh file i need to compile the python files with
python -m compileall .
in the file location directory, am i right ?
Much better. Can you add code to print out the address after it is converted to hex, so we can verify the address.
I’ve had the Error 121 before. It is a basic communication error message. How long is your cable to the module? I2C see is sensitive to length. You may want to try the module on a short cable connected up the Raspberry Pi.
Regards,
Robert
I've edited my post ... now it seams to work in console
pi@octopi:~/oprint/lib/python2.7/site-packages/octoprint_enclosure $ sudo python SI7021.py 0x40
25.3 | 56.0
but in web interface its not working maybe i need to reset but i have ongoing print atm,
ive did python -m compileall . after all changes in the file but i think i still need to reboot the server
Good to see that you got it working. Sorry for the bad format of the source file.
You can compile the code, but Octopi may do it for you on start up.
You need to make sure you pick the SI7021, with an address of 0x40, and the correct I2C interface in the plug in.
How did you get pass the Error 121?
Regards,
Robert
I've made code formatting ( all the spaces ) then i've tried different addresses in console and found that 0x40 is working
now i need to test the web interface, at the moment it isn't working. mayne restart will help, but i will be able to do so after the print. so tomorrow i will send resoults here :)
Much apriciate the help ;)
This is Yours code with formating
Good Luck.
Thanks,
Robert
Ok,
So after formatting the Code aka adding few spaces, finding proper device address witch was 0x40 and disabling sudo check box in the plugin everything is working perfect.
BIG THANKS for the perfect Code ;) Reshuler
And also BIG to Vitormhenrique for creating this awesome plugin.
Great.
Thanks,
Robert
How did you get it to work in the enclosure Plugin?
After copy&past the code above the script runs perfekt and returns correct data, but at the octopi website I still see 0°C and 0%
Uncheck use sudo on advanced section.
On Wed, Feb 13, 2019 at 4:00 PM januar3829 notifications@github.com wrote:
Just a note to everyone...I couldn't get this to work in the plugin (no problem via cli) until I hardcoded the address. Not sure why but I tried all different values in the plugin settings and none would work.