If one were so inclined to take a stab at writing the code for a library to work with a particular sensor, where would you start? I'd like to especially learn how to port a library that is available for Arduino but not yet for Micropython.
Where would one start on this journed? What information would I need to be looking for?
Writing A Sensor Library/Driver
Re: Writing A Sensor Library/Driver
There is a nice talk about that: An Introduction to Hardware Drivers in Micro Python
To sum up:
To sum up:
- Understand the datasheet
- Know how to write/read to/from the sensor registers (it varies a bit depending on the protocol used I2C/SPI/UART)
- Also understanding bitwise operations, binary/hexadecimal numbering system and how this representations works in python will help a lot
Ex:Code: Select all
>>> bin(42) '0b101010' >>> hex(42) '0x2a' >>> 0b101010 42 >>> 0x2a 42 >>>
Re: Writing A Sensor Library/Driver
Outstanding! Thank you cqqlzpy.
cgglzpy wrote: ↑Tue Dec 15, 2020 6:37 pmThere is a nice talk about that: An Introduction to Hardware Drivers in Micro Python
To sum up:
- Understand the datasheet
- Know how to write/read to/from the sensor registers (it varies a bit depending on the protocol used I2C/SPI/UART)
- Also understanding bitwise operations, binary/hexadecimal numbering system and how this representations works in python will help a lot
Ex:Code: Select all
>>> bin(42) '0b101010' >>> hex(42) '0x2a' >>> 0b101010 42 >>> 0x2a 42 >>>
Re: Writing A Sensor Library/Driver
Since making this post I have been trying to find some simple device that uses I2C that I could attempt to write a library for, for the experience and the experience of it. However, I am coming up short. Does anyone have some ideas? I need to start with something relatively simple, not something like the BME680 or something insane like that. Something I can buy the sensor for and get the datasheet for and start working through the process of how to actually write the library and test it out.
-
- Posts: 363
- Joined: Sun Apr 17, 2016 1:55 pm
Re: Writing A Sensor Library/Driver
You're my hero. How/Where did you learn to do that?
shaoziyang wrote: ↑Tue Dec 22, 2020 1:26 pmYou can refer to my micropython library:
https://github.com/micropython-Chinese- ... ty/mpy-lib
-
- Posts: 363
- Joined: Sun Apr 17, 2016 1:55 pm
Re: Writing A Sensor Library/Driver
It's not difficult, just try more, and more discussion.
Re: Writing A Sensor Library/Driver
This is rather long, and I have not read through the whole thing as of yet, but it appears to be a good document on porting/writing libraries for sensors.
https://www.digikey.fi/fi/maker/project ... 1725f28b1b
https://www.digikey.fi/fi/maker/project ... 1725f28b1b