UedaTakeyuki / mh-z19

Read CO2 concentration from mh-z19 sensor on the Raspberry Pi & handle it. Detect Raspberry Pi model automatically and read the value from an appropriate serial device.
MIT License
182 stars 37 forks source link

Question about enabling serial port #13

Closed joshuajon closed 4 years ago

joshuajon commented 4 years ago

I was attempting to follow the instructions at https://github.com/UedaTakeyuki/mh-z19/wiki/How-to-Enable-Serial-Port-hardware-on-the-Raspberry-Pi but ran into issues with permissions on the /dev/ttyS0 port on (rpi3). I added the enable_uart=1 in /boot/config.txt and rebooted, the device was set with permissions 620. I could chmod them but it would reset on boot.

The only way I found to fix this issue was to use the raspi-config instructions instead. Is this the intended behavior?

It would be better to not run python as root or with sudo as it wreaks havoc with pipenv and dependencies. I think that by enabling the serial port via raspi-config the resultant permissions should let me run python as a normal user and still access the hardware.

UedaTakeyuki commented 4 years ago

Hi, joshuajon !

Thank you for asking. I really hope to provide a solution to your problem, but I'm afraid I still haven't a clear understanding of what you are asking about. If you don't mind, would you please tell me more detail about

The only way I found to fix this issue was to use the raspi-config instructions instead. Is this the intended behavior?

Would you please share the detail steps about 'raspi-config instructions'. Also is this work well for you? Or some problems still remain?

In addition not only questions, but opinions and requests are also highly welcome if you have it. Please tell me more without hesitation, thank you.

joshuajon commented 4 years ago

When I read the instructions at https://github.com/UedaTakeyuki/mh-z19/wiki/How-to-Enable-Serial-Port-hardware-on-the-Raspberry-Pi it seemed like there were two options:

1) add enable_uart=1 to /boot/config.txt and reboot 2) use raspi-config to enable the serial interface

After performing step 1, the permissions are: crw--w---- 1 root tty 4, 64 Aug 20 08:43 /dev/ttyS0

Only after performing step 2 were the permissions correctly set to: crw-rw-rw- 1 root dialout 4, 64 Aug 20 08:44 /dev/ttyS0

That's all. I believe I've worked through the issue, I was just trying to understand if this was the correct / expected behavior or if I misunderstood the instructions.

UedaTakeyuki commented 4 years ago

Hi joshuajon,

Thank you for giving me detail and sorry to bother you. I didn't understand the difference in the permissions you mentioned and it affects when using this library with pi user or dialout group without root permission. I've really appreciated your information. I'll update the step with your information, thank you.

UedaTakeyuki commented 4 years ago

I've updated the page. Thank you for your informative information.

UedaTakeyuki commented 4 years ago

no feedback.

Philipp91 commented 1 year ago

After debugging an issue for a while today where mh_z19 couldn't read from /dev/ttyS0, let me post this info to anyone who finds this thread in the future (as it was the first place I looked):