StandardFirmata with pinModes for ping and capacitive sensing


I was thinking of hacking the StandardFirmata code a little bit in order to add two pinModes (besides Input, Output, PWM and Servo): - ping, for use with a ping distance sensor like this - capacitive, for using the pin as a capacitive sensor like this

When set in one of these mode, the pin would behave from the PC's point of view as an analog pin, sending in measured values continuously.

Has anybody already done something similar? (I'm hoping yes)

Otherwise, any advice to start with? Such as which is the most relevant part of the code of the StandardFirmata sketch that I should look at, or any similar example to look at? Is this something that you can do without hacking the Firmata library itself, just changing the top-level program?

Part of these questions may sound stupid, I don't have a deep knowledge of the Firmata internals, and I don't alway know very well where the Firmata protocol ends and Standard Firmata as a whole program starts......

Thanks in advance cheers m.

Well, I’ve done the “ping” part (not the capacitive sensing part).

I’m sure it can be done much better, but (or that’s precisely why) here it is just in case anyone may want to start from here to improve it.

I’ve started from Hans-Christoph Steiner’s StandardFirmata 2.2 and StandardFirmata_2_2_for_UNO_0_3, though I’ve only tested the first with a Duemilanove board.

I’ve added a new pinMode called “PING” which is 0x07 and is meant for use with digital pins.

This is how it works (or is supposed to work): you connect a digital pin, say pin N, to the signal pin of the ultrasonic range sensor, and you set this pin to PING mode.
The pin will periodically trigger the ultrasonic sensor and then read the pulse width, at the same rate as analog reads. It will report the value as if it belonged to a virtual Analog Pin N+8 (so this is ad-hoc for arduino boards with no more than 8 analog pins). You don’t need to enable analog pin reporting for the corresponding virtual analog pin (N+8).

Note that Analog pins can only be 0-15 so you can only use digital pins 2-7 in PING mode.

Also, the reading can take up to about 30 milliseconds, so it may slow down the other analog readings, especially if you use more than one ping sensors. I haven’t tested what happens in those cases. At the very least, the rate of all analog readings will slow down and jitter, but I haven’t checked out if there are even worse side effects. This is just a quick hack, use at your own risk.

I also attach a modified version of Pduino (HCS’s Pd abstraction for communicating with Arduino from Pd) which includes the “ping” pinMode.

arduino.pd (19.4 KB)

arduino-test.pd (30.4 KB)

Updated version with a small fix.

The sampling rate of the ping readings is limited to no more than once every 65 milliseconds (regardless of the general analog sampling rate), because otherwise you’ll occasionally get wrong readings .

It is recommended (i guess) to set the general sampling period equal to or higher than this, if you want to avoid other analog readings to jitter. Well they will jitter anyway, I guess, but I think you’ll reduce the jittering if the sampling period is higher than this

StandardFirmataWithPing.pde (15.7 KB)

StandardFirmataWithPing_2_2_forUNO_0_3.pde (16.7 KB)