2

I am new to pi and was wondering if there are any existing libraries for common sensors.

I have used Arduino in the past and that time I didn't use any existing libraries, just checked specs for sensors, and wrote the program accordingly, but at that time the sensors weren't too complicated.

Currently, I am researching for a product to add IoT functionality. So if you know of any resource, please let me know.

There must be some standard that people must be using, any opensource libraries that must have gotten popular, or is it a jungle out there and everybody codes from scratch?


Edit: I am not sure why nobody mentioned TinkerForge

rents
  • 123
  • 5

3 Answers3

4

The source of sensor code is generally the same as the source of sensors themselves, i.e., the vendors. Not all of them supply such, and not all of them supply it in a 100 % compatible form. Note that this will be OS specific, but I doubt you will find much around for Windows IoT at this point (since it is quite a new OS) so we are talking about GNU/Linux (all flavours are the same in this sense). Presuming the sensor uses a standard interface (I2C, SPI, serial) it does not have to be hardware specific (i.e. "for the raspberry pi") since the linux API for these things is universal.

However I still think it is unusual, so yes people are commonly rolling their own code. Here's an introduction to the I2C interface; there is something similar if you look around for serial and SPI although I have not used them, and there should be versions of the APIs (I believe the serial interface is largely language agnostice) for most popular languages. Remember, you are not looking for "rpi spi", you are looking for "linux spi".

There must be some standard that people must be using...

Beyond the bus style (I2C, SPI, USB, etc) you really are into device specific stuff, so it is hard to see what special "standard" beyond this could apply. Note that some popular sensors do have drivers already available in the stock kernel, something you may want to check on.

goldilocks
  • 60,325
  • 17
  • 117
  • 234
3

Quick reply: it is a jungle...

But it's not like everybody codes from scratch.

Arduino is simple partly because the inventors limited the choice to one language and focused on code reuse. Raspberry Pi is more complicated and there are several choices for development. Basically you have the same choices as for an Intel-based PC.

For example, almost any tools/libraries used on Ubuntu Linux for C development can be used if it has been ported to ARM architecture. Or you you can port it yourself! Left that as an exercise ;-)

There is no guidance as for Arduino, nor are there any limitations. Software licensing aside.

Useful tips:

  1. Look at Adafruit's github, they do a great work with all the sensors they support and sell. I'm not affiliated, just a fan.
  2. Pick a sensor you want to interface and Google it like "DHT22 raspberry pi python"
jogco
  • 497
  • 2
  • 7
1

You can find some Python libraries to common sensors at https://learn.adafruit.com/category/sensors If the sensors you require are not listed there is enough information here to point you in the right direction to write your own.

gruffymax
  • 23
  • 5