arduino

Functions with variable lenght arguments in Arduino

Submitted by fabio on Wed, 2012-01-18 17:27.

I was reading about variable length arguments for functions in the C programming language and I thought, "hey, will this thing work on an Arduino?".. well, it turns out that yes, it's working great!

But, what are functions with a variable length? Well, the standard C printf function is a good example (not available on Arduino of course). You can call it with how many arguments you want, for example:

printf("%d", 5);
printf("%d %d", 5, 7);

So, how can we make this with the Arduino? Here is an example, using the same example from here, just ported into Arduino code:

#include <stdarg.h>
#include <stdio.h>

/* this function will take the number of values to average
   followed by all of the numbers to average */
float average ( int num, ... )
{
    va_list arguments;                     
    float sum = 0;

    /* Initializing arguments to store all values after num */
    va_start ( arguments, num );           
    /* Sum all the inputs; we still rely on the function caller to tell us how
     * many there are */
    for ( int x = 0; x < num; x++ )        
    {
        sum += va_arg ( arguments, double ); 
    }
    va_end ( arguments );                  // Cleans up the list

    return sum / num;                      
}


void setup() {
  Serial.begin(9600);
}

void loop() {
  float avg = average( 3, 12.2, 22.3, 4.5 );
  Serial.println(avg);
  avg = average( 5, 3.3, 2.2, 1.1, 5.5, 3.3 );
  Serial.println(avg);
  
  delay(1000);
}

JeeNode v6 - Assembling and Soldering trough hole PTH components

Submitted by fabio on Mon, 2012-01-09 15:23.

I recently bought a couple of JeeNode v6, a small form arduino compatible board which has wireless communication capabilities through the RFM12B module. I'll be using this in an internet of things project we are prototyping at University.

Btw, since the boards came in kits you had to assemble, I took the camera out and recorded the process. The video is a nice example of soldering through hole components. Enjoy!

Updating to Arduino 1.0 APIs and improvements

Last updated on Mon, 2011-12-19 12:33. Originally submitted by fabio on 2011-12-05 18:01.

As you may have heard, the Arduino team just released the version 1.0 of their IDE which comes with quite some changes in the programming APIs. So, I spent some time updating all my Arduino libraries to be used with Arduino 1.0.

From now on, I consider previous versions of the IDE/API no more supported. So, if you are using my libraries, you are strongly suggested to update to Arduino 1.0 and the most recent version of my libraries.

Here are the new versions with the changes made:

  • HMC58X3 library: updated to Arduino 1.0 with a better calibration.
  • MS5611-01BA: better reading functions which cache the results when the sensor can't provide a newer reading, update to Arduino 1.0.
  • FreeIMU library: updated to Arduino 1.0 and to the new algorithm by Sebastian.

Enjoy it!

UPDATE 2011-12-07: The Arduino 1.0 API has a bug in the Wire implementation which throws an error on compiling: call of overloaded 'write(int)' is ambiguous. In order to fix it, search Wire.h within your Arduino install and add the following lines:

inline size_t write(unsigned long n) { return write((uint8_t)n); }
inline size_t write(long n) { return write((uint8_t)n); }
inline size_t write(unsigned int n) { return write((uint8_t)n); }
inline size_t write(int n) { return write((uint8_t)n); }

Your Wire.h will look like this. See the bug report for all the details.

Arduino Pro Mini and FreeIMU v0.3.5 flight controller

Submitted by fabio on Sun, 2011-07-24 10:46.

This is a picture of the flight controller Tilman from microcopters.de has been able to assemble using an Arduino Pro Mini and FreeIMU v0.3.5 (version without barometer). The full article is available in German here.

Awesome work!

Arduino Pro Mini and FreeIMU v0.3.5 flight controller

Etching an Arduino Shield PCB: step by steb video guide

Submitted by fabio on Fri, 2011-06-24 12:58.

In this video I documented how I'm using Press and Peel blue sheets for toner transfer PCB etching for an Arduino Shield PCB. The video covers all the steps in the procedure somehow explained in my awful English.

Posted in:

How to disable internal Arduino ATMEGA pullups on SDA and SCL with I2C bus

Last updated on Wed, 2011-12-07 13:50. Originally submitted by fabio on 2011-06-23 00:29.

Wire, the library available in the Arduino apis to communicate with devices on the I2C bus, as of the 022 version of the Arduino IDE, by default enable the internal pullups of the ATMEGA microcontroller.

As all 16MHz ATMEGA runs at 5V this means that with pullups enabled signals will have a 5 volt as logic level. Unfortunately, as many I2C devices runs at 3 Volts and aren't 5Volts tolerant, sending 5V signals to them is clearly a very bad idea. You may shorten your device life or even damage them irreparably.

Posted in:

Connecting Sparkfun ITG3200 breakout board to Arduino

Last updated on Thu, 2011-07-07 14:22. Originally submitted by fabio on 2011-06-22 13:07.

I've been asked how to connect a Sparkfun breakout board for the ITG3200 to an Arduino UNO. Here's a schematics of the connection. If you are using an Arduino Mega you'll have to use pins 20 (SDA) and 21 (SCL) instead of A4 and A5.

IMPORTANT: Remember that in order to use this setup you have to disable the internal pullups of the ATMEGA. Note that Wire will enable them by default.

Arduino Camp this weekend

Submitted by fabio on Wed, 2011-06-15 13:48.

This weekend (18-19 June 2011) I'll participate in the Arduino Camp Milano.. I'll bring there some of my projects: PALLA, FreeIMU and Femtoduino.

If you happen to be there, let me know. Looking forward knowing you in person.

Arduino Logo

MS5611-01BA Arduino library: first developments results

Submitted by fabio on Sun, 2011-06-12 20:16.

I spent the last days working on the MS5611-01BA high resolution pressure sensor. I wrote an Arduino library for it which you can find on my bzr repository:

The library comes associated with a Processing visualization sketch which you can use to visualize a the readings coming from the sensor using a graphical tool.

The results I've got so fare are pretty good. Precision is about 0.02-0.03 mbar and altitude estimation resolution is about 10-15 cm. Relative measurement of altitude using the sensor looks very good but I'm still looking for a better approach on absolute altitude estimation.

In the video below you find an example of my initial developments.

My HMC58X3 library is now fully compatible with the HMC5883L

Submitted by fabio on Wed, 2011-04-27 12:59.

I'm happy to announce that my libre Arduino Library for the HMC5843 and HMC5883L Honeywell magnetometers is now fully compatible with the HMC5883L. From version 0.2 on both the HMC5843 and HMC5883L will be supported.

By default the library assumes you are using the HMC5883L. In order to use the library with the HMC5883L you have to edit the file HMC58X3.h and uncomment the line "#define ISHMC5843".

The FreeIMU library has been updated to include support for the new HMC58X3 library.