Arduino

RC5 IR Decoding

Release: 20 décembre 2014 - 20th December 2014
Version: 1.0
OS: Arduino Uno Download: sources code + board scheme
Description
:

Français:
Ce morceau de code permet le décodage de trames RC5 transmises par infrarouge. Le protocole RC5 est celui utilisé par les télécommandes diverses et variées telles que celles des TV, magnétoscopes, etc.
Ce programme est actuellement conçu pour fonctionner avec une télécommande de TV (oubliez votre lecteur de CD), soit pour des transmissions à 36 KHz. Cela dit, il suffit de changer dedans la constante de durée d'un bit (et possiblement la tolérance que l'on ... tolère) pour s'adapter à d'autres fréquences.
En terme de carte matérielle, le programme fonctionne sur un Arduino Uno, ce qui implique une fréquence d'horloge de 16MHz (constante MCU_FREQ_HZ utilisée pour calculer la valeur à mettre dans OCR1A pour le timer) qu'il suffit d'adapter pour une autre carte (je rendrai tout ça plus configurable plus tard ;)).

Comment ça marche ?
Tout est géré par interruption en front "logique" montant (oui, un récepteur IR a un signal "logique 0" à HIGH). On a donc un handler d'interruption qui gère les fronts physiques descendants (que nous considérerons comme des fronts "logiques" montants). En fonction du temps écoulé entre 2 fronts on détermine la valeur du bit courant (ou des 2 bits "courants").
Malheureusement, la détection de front montant a l'inconvénient de ne pas détecter un bit final à 0. Pour s'en sortir, on utilise un timer (le 1) qui sert à détecter un timeout signifiant que le dernier bit de la trame était en fait à 0.
Le document décrivant plus précisément les détails techniques en Français se trouve ici.
Ce programme est au "format" .ino pour le moment, mais un décent Makefile devrait venir d'ici pas longtemps ;). On remarquera que ce programme utilise des constructions C++ uniquement pour le transfert (print) de débug vers le port série. Si l'on n'a pas besoin de ce débug, il est parfaitement conforme à du bon vieux (et nettement plus raisonnable que C++) C :).

English:
This piece of code decodes RC5 frames transmitted by infrared. The used protocol is the one involved in various remote controllers like those of TV or recorders.
This program is currently  designed to work with TV remote controllers (forget your VCR), i.e. for transmissions at 36 KHz. However, it should be sufficient to change the literal constant representing a bit duration (and possibly the tolerated ... tolerance) in order to comply with other frequencies.
In term of hardware, the program works on an Arduino Uno, which implies a clock frequency of 16MHz (constant MCU_FREQ_HZ used to compute the value to set in OCR1A for the timer) that can be changed to adapt another board (I'll make all this more configurable later ;)).

How does it work ?
Everything is handled under interrupt on "logical" rising edge (yep, an IR receiver has a "logical 0" signal at HIGH). Hence, we have got an interrupt handler handling physical falling edges (which we consider as "logical" rising edges). Depending on the elapsed time between 2 edges, one determines the value of the current bit (or the 2 "current" bits).
Unfortunately, using rising edge detection has the nasty drawback to not detect a final bit being a 0. To workaround with this, we use a timer (the 1) to detect a timeout meaning that in fact the last bit of the frame was a 0.
The document describing the history with more technical details will be here (French is already there).
This program currently is in the .ino "format", but a decent Makefile should come pretty soon ;). One may note that this program uses C++ constructs only for debug transfers (print) to the serial port. If no debug is needed, the code is perfectly suitable for a good old (and clearly realy more reasonable than C++) C :).

Countdown

Release: 16 février 2015 - 16th February 2015
Version: 1.0
OS: Arduino Due Download: sources code + board scheme
Description
:

Français:
Ce montage réalise un "minuteur" configurable au moyen de 2 boutons. Le décompte du temps en secondes est matérialisé par l'affichage en binaire sur 3 LEDs (donc décompte limité à 8 ou 7 en fonction de ce que vous entendez par "compter" ;)). Un premier bouton (gauche) permet de signaler que l'on souhaite régler le temps à décompter. Une fois pressé, un délai de 3 secondes est accordé pour presser le second bouton (droite) autant de fois que l'on souhaite "minuter". Passé ces 3 secondes, le "minuteur" démarre jusqu'à atteindre 0 et redevenir disponible pour une prochaine utilisation.

Le source est destiné à une Arduino Due puisqu'il utilise spécialement ses timers. Le code est segmenté en plusieurs fichiers et s'ouvre directement sous l'IDE Arduino. Néanmoins, un Makefile est fourni et 2 modifications mineures sont à faire pour utiliser make. Le fichier README dans l'archive décrit ces 2 petites modifications.

Ce programme est/sera/devrait être utilisé en tant que TP à l'ENSTA ParisTech où j'enseigne en cours de C / Systèmes d'exploitation en 1ère année.

English:
This sketch implements a "countdown" that can be configured thanks to 2 buttons. The elapsing time in seconds is shown in binary on 3 LEDs (hence limited to 8 or 7 depending on what you mean by "counting" ;)). A first button (left) allows to signal we want to set the time to count. Once pressed, a 3 seconds delay is allowed to press the second button (right) as many times as we want to count down. After these 3 seconds, the countdown starts until it reaches 0 and become usable again.

The source is targeted to an Arduino Due since it espacially uses its timers. The code is split in several files and can directly be opened in the Arduino IDE. However, a Makefile is provided and 2 minor modifications must be performed to use make. The README file in the archive describes these 2 small modifications.

This program is/will be/should be used as practicals at ENSTA ParisTech where I teach the C / Operating Systems courses in 1st year.

Hardware Debounce + Interrupt (Due only)

Release: 19 mars  2015 - 19th March 2015
Version: 1.0
OS: Arduino Due Download: sources code + board scheme
Description
:

Français:
Ce montage permet d'allumer / éteindre une LED en pressant sur un interrupteur. Il utilise une interruption pour détecter le changement d'état du bouton. Afin d'éviter le bruit du signal issu de l'interrupteur (et ne pas détecter plusieurs interruptions -- parasites), on active le debounce matériel du SAM3x8e.

Deux #define sont présents et servent à compiler pour Due ou Uno et à activer ou non "l'affichage" (via le port série) du nombre d'interruptions reçues.

Le source est destiné à une Arduino Due puisqu'il utilise spécialement ses registres, en particulier pour le debounce matériel. Sous Uno, le debounce n'est pas activé, seule reste la partie interruption pour allumer / éteindre la LED.

English:
This sketch allows to turn on / off a LED with a switch. It uses an interrupt to detect the switch state changes. In order to avoid the noise on the signal coming from the switch (and avoid detecting several -- spurious -- interrupts), we activate teh hardware debounce of the SAM3x8e.

Two #define are present and serve to compile for Due or Uno and activate or not "displaying" (via the serial port) the number of received interrupts.

The source is targeted to an Arduino Due since it espacially uses its registers. With a Uno, the debounce is not activated, only the part dealing with interrupt and LED on / off remains.

Dice Roller (Due only, but easy to change for other boards)

Release:  4 avril  2015 - 4th April 2015
Version: 1.0
OS: Arduino Due Download: sources code + board scheme
Description
:

Français:
Ce montage simule simplement un dé à 6 faces. Un interrupteur permet de "lancer" le dé. Les LEDs servent à afficher les points du dé qui ralentit jusqu'à s'arrêter. La configuration des LEDs en fonction de la face du dé est directement encodée dans une table d'indirection qui donne (sur 1 octet) pour chaque valeur l'état des ports à écrire. La LED de l'interrupteur est volontairement sur la broche 10 pour éviter qu'une erreur dans la fonction d'allumage des LEDs ne provoque une écriture sur la broche en entrée relié à l'interrupteur.

English:
This sketch simulate in a simple way a 6-faces dice. A switch is used to "throw" the dice. The LEDS are used to display points of the dice, this latter slowing until it stops. The configuration of the LEDs depending on the face of the dice is directly encoded in an indirection table. This table gives (on 1 byte) for each value the state of the ports to write. The LED wired to the switch is voluntarily on the pin 10 to avoid that an error in the lighting function causes a write on the input pin wired to the switch.

Babix (Due only)

Release:  juillet 2015 - July 2015
Version: 2.0
OS: Arduino Due
Downloads:
    Source code for the "lite" version (i.e. processes cannot terminate and must be endeless loops)
    Source code for the "normal" version (i.e. processes can terminate)
Description
:

Français:


English:
What it IS
  • Babix is a little preemptive multitask kernel for Arduino Due.
  • It is mostly dedicated for educational purposes.
  • It is basic and simple and aims at showing the principles underlying preemptive kernels.
  • The main user process (the standard loop () function) is ran only if there is no other processes.
It is written in C with some inevitable assembly inlines. Even if some files are suffixed by ".cpp", it is C. The C++ is only to use Serial.print () for debug or feedback printing.

You may also download the related PDF course / tutorial explaining the principles of preemptive multitasks kernel, illustrated by the Babix implementation. All the details about the implementation are presented in this document.

What it is NOT
  • A complete OS
  • A real-time kernel
  • A fully optimized kernel.
July 2015