How to write sensors libraries from scratch ?

Thread Starter

Youssef Abbih

Joined Mar 7, 2018
3
need to develop device libraries like dht11/dht22, 16x2 lcd, BLE, ecc.. from scratch (almost). Is there any doc or tutorial that can help me? Question is, how to write a device library using C given a datasheet and a platform like STM32 or other ARMs?
Thanks so much
I've tried to read device libraries from Arduino library and various Github, but I would like to have a guide/template to follow (general rules) to write proper device libraries from a given datasheet.
I'm not asking a full definitive guide, just where to start, docs, methods approach.
 

dl324

Joined Mar 30, 2015
13,285
Welcome to AAC!

If it has already been done, find source for a library and study how they did it.

If you want to learn how to do it on your own, do what others had to do. Get the datasheet for the microcontroller you want to use and learn how to access the I/O's.

For example, the ARM microcontroller used for Raspberry Pi Zero is attached. How to use GPIO registers is Chapter 6 starting on page 89.
 

Attachments

Ian Rogers

Joined Dec 12, 2012
935
I almost always write my own drivers... Most libraries, written by the companies that make them, or libraries on the GitHub, write for many platforms and devices... I strip out the crap so I can use it for me! Take a library.. and make it suit your own applications.. Some devices have no drivers and have to be written from scratch... Datasheets out!!
 

Thread Starter

Youssef Abbih

Joined Mar 7, 2018
3
Welcome to AAC!

If it has already been done, find source for a library and study how they did it.

If you want to learn how to do it on your own, do what others had to do. Get the datasheet for the microcontroller you want to use and learn how to access the I/O's.

For example, the ARM microcontroller used for Raspberry Pi Zero is attached. How to use GPIO registers is Chapter 6 starting on page 89.
Hi dl324,

I readed the datasheet (example sht31) , and when i reded the library for arduino I didn't understand it it was too long, and the paragraphe described it on the datasheet is short
 

atferrari

Joined Jan 6, 2004
4,442
need to develop device libraries like dht11/dht22, 16x2 lcd, BLE, ecc.. from scratch (almost). Is there any doc or tutorial that can help me? Question is, how to write a device library using C given a datasheet and a platform like STM32 or other ARMs?
Thanks so much
I've tried to read device libraries from Arduino library and various Github, but I would like to have a guide/template to follow (general rules) to write proper device libraries from a given datasheet.
I'm not asking a full definitive guide, just where to start, docs, methods approach.
Your problem is related to sensors only?

If so, oversimplifying things, I dare to say that it could be as simple as reading the voltage output of a potentiometer or as complex as identifying a 1Wire device amongst so many plus decoding the data it outputs. I wrote the full library for DS1820 devices, just following the datasheet (always RTFM!) and enjoyed the journey a lot.

Prior starting make sure that you have a clear idea of the protocol in use to communicate with the sensor. Chasing ghosts could frustrate you easily.
 
Top