FLTK logo

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

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   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 Oct 20, 2020  
 
On 20 Oct 2020, at 11:24, Ian MacArthur wrote:
> 
> On 20 Oct 2020, at 10:56, LosCelos wrote:
>> 
>> Hi,
>> 
>> is there a way to read signals from an ADC on Raspberry Pi with FLTK ?
>> I already have installed FLTK on Raspberry Pi and make some Apps and it works.
>> But now i need to read data for example from a potentiometer which goes on a ADC MCP3008 and show the data on my FLTK on a scope like a oszilloskop.
>> 
>> I have the Oszilloskop-App to show the data.
>> And i can read the data from the ADC on my Raspberry Pi with a make-file (without FLTK).
>> 
>> The problem is that i have to read it with fltk to show it with the app.
>> Every data input should be shown instead, so there is no way to first put the data in a txt-file.
> 
> 
> It’ll depend very much on what API your ADC presents (and how complicated you want to make things too, I suppose...)
> 
> Assuming your ADC presents some sort of C-callable API that acts as a FIFO or presents a buffer of data, say, then what I’d probably do myself is start the app in fltk, and create the UI, then spawn a worker thread to poll the ADC for input.
> 
> The worker then puts that data into a buffer, retaining on the last (however many you want to display) samples and the fltk main thread then reads that buffer periodically to refresh the display. 
> 
> So, if you are comfortable with threads and such, that should be pretty straightforward. I you are not comfortable with threads... then this might be too complex a solution (sorry!)


So it occurred to me that I must have code lying around that does basically this - but I went looking and couldn’t find anything directly suitable (work from home is strange...)

Anyway, attached a sample that *sort of* does what I described - this will not compile as-is, since it needs access to a separate audio input API I can not post here, but the basic idea is “the same”

This file creates a fltk window with a few widgets, then creates a worker thread called draw_wave() that loops around polling the audio port for input. That input is then copied into the buffer “sample” where it can be read by the fltk thread.

In the fltk thread, the timer callback method wave_CB() runs every 0.1 seconds to poll the sample data for changes. If there are changes, it refreshes the display accordingly.
So this is pretty incomplete, but there might be enough there to give you a few clues anyway... Note that there is a lot of spurious code to do with handling the buffers and so forth - your challenge is to figure out which bits matter and which bits are just my junk!

-- 
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 fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/3D4697E2-5413-4443-96C1-D0CC4E8D9259%40gmail.com.




-- 
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 fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/3D4697E2-5413-4443-96C1-D0CC4E8D9259%40gmail.com.
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

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