PDA

View Full Version : Displaying and storing the ADC value obtained over serial port



piyushpandey
26th December 2014, 10:19
Hi guys


I have wrote an user interface for interaction with the serial port and to display it's contents over the LCD display widget.

Currently I am just sending a character and receiving a character in return.

But now I want to add some extra functionalities to my user interface in which I want to let my user interface keep showing the changing ADC value of my microcontroller and also to store the first hundred readings of the ADC in
a temporary buffer and than when user ask to save it than this data gets stored in a file like notepad.

So can you people guide me the flow which I should follow and also which Qt classes will be most appropriate to me for my this task.

Also I don't know that how to manage the buffer in the Qt.

i.e. to store large amount of data and to store them on the harddrive and also to read them and to display on the display widget of the Qt.

right now I just want to read the data coming from the ADC of my microcontroller over the serial port and than
displaying it on the LCD widget of my User interface and than storing the first 100 values to a file when user ask
to do so.

anda_skoa
26th December 2014, 10:59
If you want to store in memory, you can use QBuffer.
But you could also just write into a QFile in all cases and just delete it if it is not "saved".
Or write into a QTemporaryFile and copy/rename to the save file name on save.

Cheers,
_

Lesiok
26th December 2014, 11:25
Remeber that "serial port" is ordinary stream of bytes. The protocol defines how to interpret it. You must implement "protocol of the ADC" on receiver (application) side.

piyushpandey
26th December 2014, 15:08
Thanks anda skoa for your reply and suggestions


Remeber that "serial port" is ordinary stream of bytes. The protocol defines how to interpret it. You must implement "protocol of the ADC" on receiver (application) side.

lesiok I didn't get your point can you describe me your concern a little bit more clearly.


Thanks

Lesiok
26th December 2014, 15:27
How this ADC sends data ? As single bytes or or any value is a few bytes. If this second how do you know when it begins a new value ? All of this is a protocol.

FreddyKay
26th December 2014, 20:49
to put it in a different way: Decide upon a way to send data. Most muC have either 8-bit or 16-bit ADCs. If you use an 8 bit adc it can be very easy as a serial port in general works on bytes. So each value that you receive on the the ComPort / serialPort on your PC is one value, that you can take, display and save directly (by using any kind of container, a ring buffer would be a good idea in your case). a 16 bit ADC needs you to combine 2 consecutive bytes. Demands a bit of logic but is essentially the same. Though very simple this is already a protocol. You can also think of a more complicated way to communicate between muC and PC depending on what you want to achive beyond just a few ADC values. You could for example use a char to indicate whether a value was send or a command, or any other information.

Though unlikely you should always consider that your muC can be faster than your program, depending on the speed of your ADC, the things you do in your program and the general load on your Computer.