development of a module for the bmp180 pressure sensor

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
User avatar
dhylands
Posts: 3212
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: development of a module for the bmp180 pressure sensor

Post by dhylands » Thu Jul 03, 2014 2:27 pm

torwag wrote:On a side note, I believe that micropython could take the buspirate to the next level. Now it is all hard-coded in C for a PIC. Using micro-python would allow much more flexibility and a much easier maintenance plus, a lot of more features due to the ARM SoC (e.g. data logging to SD card.)
I saw a mention of the HydraBus over on github. http://hydrabus.com/ mentions micropython and also mentions bus pirate...

Turbinenreiter
Posts: 288
Joined: Sun May 04, 2014 8:54 am

Re: development of a module for the bmp180 pressure sensor

Post by Turbinenreiter » Fri Jul 04, 2014 12:42 pm


pfalcon
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

Re: development of a module for the bmp180 pressure sensor

Post by pfalcon » Fri Jul 04, 2014 5:31 pm

This looks *really* good for a guy who started with asking questions about hexadecimal numbers ;-). Hopefully that proves that Python is really easy to program with, no matter how much background one has.

That said, there's yet some way to go for that module to have really "professional" look. Few issues immediately catching an eye:

1. Naming. Stuff like "UP()", "UT()", "T()", "p()" is really confusing. I bet you yourself, if looking at the code which uses this module in a year, won't be able to tell what they mean. And other people will have that trouble immediately. So, please consider using more detailed names. They sure should not be too long either. Finding good and consistent naming is kind of art (yeah, like poetry). Ses also suggestion below.

2. Code is vividly not compliant with PEP8 code style guidelines. For example, there's no (or inconsistent) spaces around operators and in function argument lists. Also, PEP8 doesn't appreciate following usage of if/else:

Code: Select all

        if B7 < 0x80000000: p = (B7*2)/B4
        else:                        p = (B7/B4)*2
It should be instead (if you trust PEP8, and you should in general, because most other Python programmers trust PEP8, so if you won't trust PEP8, they won't trust your code):

Code: Select all

        if B7 < 0x80000000:
            p = (B7*2)/B4
        else:
            p = (B7/B4)*2
Anyway once again, this looks very good for v0.5. Btw, did you notice another guy's module for another temperature sensor: http://forum.micropython.org/viewtopic.php?f=5&t=154 ? What would be really cool if you guys communicated and came to a common naming conventions on which method names to use to get temperature, etc. - in other words, established an interface which temperature and other sensor modules should provide to be compatible and be able to substitute one another. That would be true Pythonic way and allowed people to write great apps which would work with any hardware easily.
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

Turbinenreiter
Posts: 288
Joined: Sun May 04, 2014 8:54 am

Re: development of a module for the bmp180 pressure sensor

Post by Turbinenreiter » Fri Jul 04, 2014 7:09 pm

Btw, did you notice another guy's module for another temperature sensor: viewtopic.php?f=5&t=154 ? What would be really cool if you guys communicated and came to a common naming conventions on which method names to use to get temperature, etc. - in other words, established an interface which temperature and other sensor modules should provide to be compatible and be able to substitute one another.
Actually, I saw his work and had the same idea. Now that I have solved most of my own problems I will look into that.
Code is vividly not compliant with PEP8 code style guidelines.
Oh, maaan. Yeah, as we talked earlier, I will start using pep8. In this special case ... I would *much* prefer the way I do it right now. Still, code is written to be read by people, so PEP8 wins.
edit: update: Woah, pep8 is great to use. Took me 5 minutes and now it passes. Should be much better now. I actually have to read the whole PEP8 once ... .
Naming.
UP(), UT() and B5() would normally not be used by others, but only internally. Maybe I should underscore them (according to PEP8, there is something in there, leading underscores to show something should be 'private').
T() and p() - that's the common symbols for temperature and pressure. I had get_temp() and get_pressure() before. Better? I will look at the other guys (randomhuman) code as you suggested.
This looks *really* good for a guy who started with asking questions about hexadecimal numbers ;-). Hopefully that proves that Python is really easy to program with, no matter how much background one has.
Thanks! In my Informatics Class for Mechanical Engineers I did calculations in dual and hex per hand and I loved it, but in real code - that threw me off. Also, I'm pythoning for about three years now, sooo ... yeah. But I mostly used numpy and matplotlib for data visualization.

Turbinenreiter
Posts: 288
Joined: Sun May 04, 2014 8:54 am

Re: development of a module for the bmp180 pressure sensor

Post by Turbinenreiter » Sat Jul 12, 2014 7:05 pm

I massively reworked the code.

Image

Post Reply