Thursday, January 12, 2012

How complex ?

How complex can a voltmeter be, with ZPUino, my yet-to-be-released SerPro3 software and a Gadget Factory ADC wing ?

Well, judge for yourselves:

This is ZPUino code (29 lines):

#include <SerPro3.h>
#include <SPI.h>
#include <Papilio.h>

SERPRO_ARDUINO_BEGIN();

Papilio::ADC8_Wing myadc;

void setup()
{
Serial.begin(115200);
myadc.begin( Papilio::Wing_A_Low );
}

uint16_t sample(int channel)
{
return myadc.sample(channel);
}

void loop()
{
if (Serial.available())
SerPro::processData(Serial.read());
}

EXPORT_FUNCTION(1,sample);

SERPRO_ARDUINO_END();


And this is PC code (23 lines, Linux):

#include <SerPro/SerPro-glib.h>

SERPRO_GLIB_BEGIN();
IMPORT_FUNCTION(1,sample,uint16_t(int));

void go()
{
while(1) {
printf("Voltage: %.02f\n", ((double)sample(0)*3.3)/255.0 );
usleep(500000);
}
}

int main(int argc,char **argv)
{
SerProGLIB::init(argv[1],B115200);
SerProGLIB::start();
SerProGLIB::waitConnection();

go();
}

SERPRO_GLIB_END();


And this is how it runs, with ADC connected (channel 0) to 1.2V power rail:

$ ~/sketchbook/remote/pc/remote /dev/ttyUSB1
Channel set up OK
Voltage: 1.20
Voltage: 1.20
Voltage: 1.20
Voltage: 1.20
Voltage: 1.20


Not much of a hassle, is it ?