RIOT and Peripherals

Hello Rioters, I am using a samr21 and I want to connect some peripheral devices (one motion sensor, its connected to the pin_17 and if there is motion I will get an 1 as input, and a speaker, I will create a frequence with the osciloscope and then send it to the speaker). Is there any library which takes care of these staff?? Any example or any help overall will be appreciated. Thank you in advance!

Your Faithfully, Ilias seitanidis

Hi Ilias,

what exactly are you looking for? You can find all supported sensors (and actuators) here:

https://github.com/RIOT-OS/RIOT/tree/master/drivers .

Concerning the speaker you might be interested in the PWM API?

https://github.com/RIOT-OS/RIOT/blob/master/drivers/include/periph/pwm.h

Best regards Peter

Hi, Thanks Peter, The idea is if the pir detects something, then the speaker will produce a sound, for example for 2 minutes, then a udp message will be sent. I have some questions(as a newbie :slight_smile: ) :

  • I didn’t find the pwm.c file, maybe someone erased it during a clean up operation? -Is there any example of using the pwm lib? (mostly on the sequence of the function call)
  • There is a variable dev that points to the speaker device(as mentioned this lib was used with virtual devices), is there a specific integer for one device or it doesn’t matter? (

void pwm_set(pwm_t dev, uint8_t channel, uint16_t value); |

  • |

)

-For the pir Library is it mandatory to register as a thread(?), it will be my main thread.

I’ve seen the project of Mr. Nhat Pham, but the main idea is to use the RIOT OS as it is. Thank you in advance!

Best regards, Ilias

Hi

- I didn't find the pwm.c file, maybe someone erased it during a clean up operation?

pwm need to be implemented for each supported platform, here is the sam3 one for example :

-Is there any example of using the pwm lib? (mostly on the sequence of the function call)

maybe here : https://github.com/RIOT-OS/RIOT/blob/master/tests/periph_pwm/main.c

Hope this helps, Laurent

Hi,

if you are on a samr21-xpro the pwm.c driver implementation can be found here:

https://github.com/RIOT-OS/RIOT/blob/master/cpu/samd21/periph/pwm.c .

The pin configurations on an Atmel samr21-xpro board are defined here:

https://github.com/RIOT-OS/RIOT/blob/master/boards/samr21-xpro/include/periph_conf.h#L146 .

As Laurent already said, an example lies here:

https://github.com/RIOT-OS/RIOT/tree/master/tests/periph_pwm .

I didn't really understand the question about the "variable dev" but probably the example will explain everything.

There is no *need* to open a separate thread for the PIR but probably you want to. Did you already have a look at the PIR example under "tests":

https://github.com/RIOT-OS/RIOT/tree/master/tests/driver_pir ?

Best Peter

Dear all,

I would like a small explanation of the value “TCC_CTRLA_PRESCALER_DIV*_VAL” in line 84 in [1], is it possible to add the equivelant value of the “TC_CLOCK_PRESCALER_DIV1”(as found from the atmel studio).

Thank you in advance!

Best regards,

Ilias

[1] https://github.com/RIOT-OS/RIOT/blob/master/cpu/samd21/periph/pwm.c .

Hi Ilias,

I don't know details about the PWM clock generation on this microcontroller *but* "TCC_CLOCK_PRESCALER_DIV1" means "no division of the source clock". That will be the case when (compare [1]):

CLOCK_CORECLOCK / (freq * res) = 1 .

Calling the function like this: get_prescaler(1, &scale), returns 0 (same value as TCC_CTRLA_PRESCALER_DIV1_Val) resulting in no prescaler selection here [2]. That's why I assume the feature you want should be already there, or am I mistaken?

In case you convince me of the contrary :-), there's nothing against improving the peripheral driver implementation.

Best regards Peter

[1] https://github.com/RIOT-OS/RIOT/blob/master/cpu/samd21/periph/pwm.c#L101 [2] https://github.com/RIOT-OS/RIOT/blob/master/cpu/samd21/periph/pwm.c#L137