Re: [fltk.general] Read Signal from ADC on Raspberry Pi with FLTK

GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
Previous Message ]New Message | Reply ]Next Message ]

Re: Read Signal from ADC on Raspberry Pi with FLTK Ian MacArthur 10:34 Oct 23 top right image
I meant to post a worked example of the polling approach. But then I forgot...

Here is it anyway - I have commented out the R.Pi specific parts, and stubbed the read of the ADC, but it shows the basics of the timer polling approach...

With the ADC stuff added back in (and my dummy counter removed) this ought to pretty much work on the R.Pi, though you will need to link against wiringPi of course, as well as the fltk lib.

Something like this might do the trick to compile it:

    g++ `fltk-config --cxxflags` app.cxx -o app -lwiringPi `fltk-config --ldstaticflags`

// Start of file

#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Value_Output.H>
#include <FL/Fl_Button.H>

// You would need these headers...
// #include <wiringPi.h>
// #include <mcp3004.h>

#define BASE 100
#define SPI_CHAN 0
#define chan0 0     /* Poti                     */
#define chan1 1     /* LDR                      */

static Fl_Double_Window *main_win = NULL;
static Fl_Value_Output *adc_out = NULL;

static int get_adc (void)
    // This is where the ADC read would go...
    //return analogRead (BASE);

    // for now, here's a dummy test stub - reomve this!
    static int dummy = 0;
    if (dummy > 255) dummy = 0;
    return dummy;
} // get_adc

// animate the meter for testing purposes
static void poll_adc (void *)
    static int old_level = (-1);

    int level = get_adc ();

    if (level != old_level)
        old_level = level;
        adc_out->value (old_level);

    Fl::repeat_timeout(0.1, poll_adc);
} // poll_adc

static void cb_Exit (void *)
} // cb_Exit

int main (int argc, char **argv)

    // Setup wiringPi and mcp3004
//    wiringPiSetup();
//    mcp3004Setup(BASE, SPI_CHAN);

    main_win = new Fl_Double_Window(247, 130);

    adc_out = new Fl_Value_Output(100, 22, 66, 33, "ADC READ :");

    Fl_Button* o = new Fl_Button(175, 80, 60, 25, "Exit");

    main_win->show(argc, argv);

    Fl::add_timeout(0.25, poll_adc);

    return Fl::run();
} // main

// end of file

You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
Direct Link to Message ]
bottom left image   bottom right image
Previous Message ]New Message | Reply ]Next Message ]

Comments are owned by the poster. All other content is copyright 1998-2021 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to ''.