Sorry, this entry is only available in Italiano.
May 11 2013
New release 1.2.0 of the swRTC
I’ve released the new version 1.2.0 of the swRTC library that introduces the support for the internal Real-Time Counter (RTC) that is present on several MCUs. This module permits to use the timer 2 in asynchronous mode with an external 32,768 Hz crystal. Setting up the timer 2 with a prescaler of 128, we get 1 overflow every 1 secon so that we can increment the software clock in a more accurate manner.
The RTC module is only present in Atmega88/168/328, Atmega8, Atmega344/644/1284 and Atmega1280/256x.
Download the latest revision of the library from this page.
May 09 2013
New advancedFunctions library for Arduino DUE
I’ve started writing a new library that let to use the integrated peripherals into the Atmel SAM3X8E microcontroller of the Arduino DUE board that are not yet supported by the Arduino IDE core.
At the moment the library, called advancedFunctions, supports the real time clock (RTC), that provides the timing and a calendar, and an alarm too, and the true random number generator (TRNG) that has passed the NIST tests too. The support for other hardware will be added in the future.
May 06 2013
New Atmel toolchain 3.4.2
Atmel has updated its toolchain (the kit of executables and libraries need to compile fimrware for its microcontrollers) to version 3.4.2. You can download the new release from the Atmel website (free registration) in the form of precompiled binaries for Linux or Windows (at the moment Atmel doesn’t release precompiled binaries for MacOS X). After downloaded the tool, you have to substitute the toolchain that comes integrated into the Arduino IDE with this on and modify some files of the Arduino core and the Tiny core, if you use it. To do that, follow this steps.
Apr 27 2013
LED clock
This is the LED clock, a LED wall clock that visualizes the time dividing the LEDs into columns that represent the ten’s/units of hours, minutes, and seconds. Compared to those binary clocks widely available, this is simpler to read.
The clock uses an ATmega328P and a PCF8563 as external RTC. It drives the LEDs with no multiplexing so the LEDs are brighter. The LEDs are 10 mm in size to facilitate their seeing. The circuit can regulate its luminosity depending on the ambient light of the room in which it is used.
Apr 14 2013
A new library, pRNG
I found some free time to spend on writing a new library that I called pRNG, for pretty Randon Number Generator.
Basically, the library is a pseudorandom number generator. It uses an interrupt raised by the WatchDog Timer (WDT) to collect entropy from a timer of the Arduino (or any microcontroller) and a 32-bits Galois linear feedback shift register (LFSR). Random data are stored in a pool that is constantly updated, from which the user can pick them up as single bytes. The mechanism gives patterns that are different every time the Arduino starts, and never replicated (at least in the short period).
Apr 14 2013
(Italiano) Scegliamo la giusta scheda Arduino
Sorry, this entry is only available in Italiano.
Apr 02 2013
Let’s schedule our jobs with millis()
Millis() is a function provided by the Arduino core that returns the number of milliseconds since the board has been powered on. Millis() is based on a counter that is automatically incremented by an interrupt attached to the timer 0, for the value it returns constantly increases not being influenced by the user’s code.
We can use millis() to schedule the execution particular actions, like it was a timer that give the starting signal at our code without blocking the execution of the same code awaiting the right moment to do jobs.

Let’s start with a simple test, a LED blink. The Arduino IDE provides a very famous example named “Blink”. The code below is almost identical to the original version:
const byte led = 13;
void setup() {
pinMode(led, OUTPUT); // initialize the digital pin as an output.
}
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
This code just set to HIGH the pin at which the LED is attached, wait for 1000 ms (1 second), set to LOW the pin, wait for another 1000 ms and then start again the loop.
This sketch has a big limit: while the code is executing the delay(1000), the microcontroller can do nothing else. If you modify the sketch and insert a Serial.print just after the second delay() you’ll se that the text will be printed on the serial monitor every 2 seconds:
const byte led = 13;
void setup() {
Serial.begin(19200);
pinMode(led, OUTPUT); // initialize the digital pin as an output.
}
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
Serial.println("Test...");
}
A possible workaround comes from “BlinkWithoutDelay” provided by the IDE. The following code is a revisited version of that example:
const int ledPin = 13; // the number of the LED pin
int ledState = 0; // ledState used to set the LED
unsigned long previousMillis = 0; // will store last time LED was updated
unsigned long interval = 1000; // interval at which to blink (milliseconds)
void setup() {
pinMode(ledPin, OUTPUT); // set the digital pin as output:
}
void loop() {
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
previousMillis = currentMillis; // save the last time you blinked the LED
// if the LED is off turn it on and vice-versa:
ledState ^= 1; //alternate the status of the pin with a XOR
digitalWrite(ledPin, ledState);
}
}
This example just does its job without blocking the code: every time the loop() is executed, the sketch checks if the difference between the actual value of millis() and the value of the past time the LED was blinked is greater than the choosen interval, in case it changes the status of the LED. If you put a Serial.print at the end of the loop() function you’ll see that this time the serial monitor will continuously show your message.
But, what if you have more than 1 job to run? We can use two couples of variables to store the blinking times. This is a possible code:
const byte ledPin = 13; // the number of the LED pin
byte ledState = 0; // ledState used to set the LED
unsigned long previousMillis1 = 0; // will store last time LED was updated
unsigned long interval1 = 100; // interval at which to blink (milliseconds)
unsigned long previousMillis2 = 0;
unsigned long interval2 = 1000;
unsigned int counter = 0;
void setup() {
Serial.begin(19200);
delay(2000);
pinMode(ledPin, OUTPUT); // set the digital pin as output:
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis1 > interval1) {
previousMillis1 = currentMillis; // save the last time you blinked the LED
// if the LED is off turn it on and vice-versa:
ledState ^= 1;
digitalWrite(ledPin, ledState);
}
currentMillis = millis();
if (currentMillis - previousMillis2 > interval2) {
previousMillis2 = currentMillis; // save the last time you blinked the LED
// if the LED is off turn it on and vice-versa:
Serial.println(++counter);
}
}
This sketch executes 2 jobs: the first one is the LED blinking with a 100 ms interval, while the second one prints a counter over the serial every 1000 ms. Every job is correctly executed because the program doesn’t freeze in any delay() but constantly checks if the time to execute a jobs of the two has come.
If you want to use a better jobs management, I suggest you to use my looper, a library that I wrote to execute several jobs in an easy way.
Apr 01 2013
New looper 1.0
I’ve released the new version 1.0 of looper, my scheduler that doesn’t use timers to execute the user’s jobs:
- new syntax of the methods that let the user use looper together with leOS;
- code cleaning, now the compiled sketches are smaller then before;
- new myDelay method that replaces the delay function of the Arduino core and with which you can insert a delay into the code while the scheduler can continue to launch the user’s jobs.
You can find the new version at this page.
Mar 31 2013
Let’s direct manipulate the logic ports of an MCU
If we want to light on an LED connected to a pin of our Arduino we know that in order to do this we have to follow these steps:
1) set the pin as OUTPUT with the command pinMode;
2) “write” on that pin the value HIGH with the command digitalWrite.
This seems an easy job but if we check the code of the Arduino core we can see that it isn’t. The simplicity of the Arduino IDE permits to do this operation with just 2 instructions but in the background more operations are executed, because the Arduino core has to do several calculations to transform the pin number into the corresponding phisical pin and then it checks that this pin isn’t connected to a timer, in such a case it first has to deactivates the PWM signal if any. Only then the pin is set as requested.
If we don’t need a quick respond we can not take care about all of these steps, that are executed each time we call those instructions, but if we are looking for a fasted way to do these things there’s only a possibility: we have to directly manipulate the logic ports of the microcontroller.




