Could Someone Provide Guidance on How to Set up a Custom Driver in RIOT OS?

Hello everyone :wave:

I am currently working on a project that involves incorporating a customised sensor into a RIOT OS based system. I have some knowledge of mobile devices and c programming; but this is my first time working with the RIOT OS.

This are the details of my project: :slightly_smiling_face:

The sensor is an xyz123 temperature and humidity sensor that communicates through I2C. I have the documentation and have earlier connected it with the arduino platform; so I am comfortable with its communication protocol and what is required commands. I am using an STM32 Nucleo platform, the nucleo f401re. I quickly set up the working setting for the RIOT OS and ran a few simple examples to become comfortable with the system. I created a simple RIOT application to set up the I2C capability on the Composer device. I created some beginning code to scan for I2C devices; and the sensor was successfully found.

Although I am already reaching the point where I need to create an appropriate driver for this sensor; I am not sure what guidelines and specific methods are inside the RIOT OS structure.

  • Is there an optimal structure and pattern for creating device programs in the RIOT OS? For example; are there provided files and locations where the driver code should be stored?
  • Are there any existing Methods and protocols in RIOT OS that I should follow when creating the driver? I discovered there are the saul and saul reg modules; should I use them, and if so, how?
  • What is the preferred method for handling I2C connection in RIOT OS? Are there any special functions and modules I should use to send and receive information through I2C?
  • What are the best ways to verify and fix apis in RIOT OS? Are there resources and strategies for improving this process?
  • Can somebody provide some example programs for similar indicators that I may use as a reference?

Also I explored some topics related to this https://forum.riot-os.org/t/riot-os-for-data-logger-system-with-servicenow-focus-on-maintenance/3023 but I did not get the sufficient solution of my query so I would really want to get some help from a more experienced person. I would appreciate any ideas; resources; and examples that the community may offer.

I am hoping to get this sensor working on RIOT OS and contribute to the community when I have workable software.

Thank you in advance for your help :saluting_face: :saluting_face:

1 Like

Hej Romana,

I haven’t written any driver for RIOT myself yet, but I would like to point you to the corresponding page in the documentation: Writing a Device Driver in RIOT

Have you seen that already? I think that it will answer at least some of your questions.

Best Mikolai

1 Like

Hello @Romana :smiling_face_with_three_hearts: I am delighted to help with your project. Creating a driver for your xyz123 temperature and humidity sensor involves following the RIOT OS structure and guidelines. What you can do is follow these steps: First, Create a new directory in boards/<board_name>/drivers/ and then use SAUL and SAUL reg modules in which you should Include i2c.h and use i2c_read and i2c_write functions. And the lastly verify and debug with RIOT OS tools. :blush: :blush:

1 Like

The other commentors already nailed it pretty much :slight_smile:

What I typically do is: I grab one existing driver and just copy it as a boilerplate/base for the new sensor.

This makes it quite easy to find all the SAUL and driver references in order to do it properly. It’s a nice guidance basically.

If there is an existing drivers for Arduino or something similar, I would also use it as inspiration. This makes it way easier than reading the specs :joy: