go away spammer

Author Topic: Serial port reading ADC values in DevCpp (like datalogger)  (Read 11325 times)

0 Members and 1 Guest are viewing this topic.

Offline bootstrapTopic starter

  • Full Member
  • ***
  • Posts: 61
  • Helpful? 0
Serial port reading ADC values in DevCpp (like datalogger)
« on: March 05, 2008, 01:58:29 AM »
Hi,
I have just started using sensors and I did the coding for ADC.I am able to get the ADC values using the Hyperterminal.But I want to build real time graphs using  C in DevCpp (Windows).Any sample code which will help me read the data from the serial port (9600-8-N-1) in DevCpp (windows).
Thanks in advance

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
    • izua electronics
Re: Serial port reading ADC values in DevCpp (like datalogger)
« Reply #1 on: March 05, 2008, 04:14:47 AM »
I had a class once to do this. Let me look for it.
The only problem is, it's a class, so you'll need c++.
what are you going to use for the UI, if you build graphs? or it's simply aquire data-generate image from a console program.

If you develop a scope-like program, please let me know, i wanted to make something like this a long time ago :P
« Last Edit: March 05, 2008, 04:15:43 AM by izua »
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
    • izua electronics
Re: Serial port reading ADC values in DevCpp (like datalogger)
« Reply #2 on: March 05, 2008, 04:17:50 AM »
Here you go.
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline bootstrapTopic starter

  • Full Member
  • ***
  • Posts: 61
  • Helpful? 0
Re: Serial port reading ADC values in DevCpp (like datalogger)
« Reply #3 on: March 06, 2008, 08:47:43 AM »
Here you go.
I am getting the following linker error
E:\Dev-Cpp\lib/libmingw32.a(main.o)(.text+0x106):main.c: undefined reference to `WinMain@16'

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
    • izua electronics
Re: Serial port reading ADC values in DevCpp (like datalogger)
« Reply #4 on: March 06, 2008, 12:38:25 PM »
let's try and figure that out.
first, when we get a random class off the internet, we suppose it's a simple, raw, algorithm or API usage. so we don't use any GUI.
is your project supposed to be a GUI program?

WinMain is the equivalent of main() in a console program.
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline bootstrapTopic starter

  • Full Member
  • ***
  • Posts: 61
  • Helpful? 0
Re: Serial port reading ADC values in DevCpp (like datalogger)
« Reply #5 on: March 07, 2008, 08:28:03 PM »
let's try and figure that out.
first, when we get a random class off the internet, we suppose it's a simple, raw, algorithm or API usage. so we don't use any GUI.
is your project supposed to be a GUI program?

WinMain is the equivalent of main() in a console program.
I also have to use Open CV (so its GUI).Can you please tell me how to solve the linker error?Did the program work fine for you?Did you create a project and then passed a parameter to it?

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
    • izua electronics
Re: Serial port reading ADC values in DevCpp (like datalogger)
« Reply #6 on: March 08, 2008, 02:48:57 AM »
No, I simply let values scroll in a console terminal.
I don't want to be a nuissance, but if you don't know how to adapt a console class to a GUI class, you should definitely learn some C++.

I've tested the class in a console environment. There was one instance when I haven't done that, using openGL for drawing samples and I haven't found a single problem.
Take steps to meet all the requirments imposed by your GUI framework: having a winmain, or using a macro to implement the graphic env, or whatever it asks for (i'm not familliar with openCV).

You can't simply add my file (main.cpp) into your project and expect it to work, since my file has a main function and it prints data to cout. You'll have to use the main function of your graphic env (which will generate winmain, anyway), instantiate a class
Code: [Select]
SFile mySerial, open it (
Code: [Select]
mySerial.open(1,9600)) and then graph or show all the data you'll read using a label, button or whatever your GUI permits.
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline bootstrapTopic starter

  • Full Member
  • ***
  • Posts: 61
  • Helpful? 0
Re: Serial port reading ADC values in DevCpp (like datalogger)
« Reply #7 on: March 09, 2008, 12:45:40 AM »
No, I simply let values scroll in a console terminal.
I don't want to be a nuissance, but if you don't know how to adapt a console class to a GUI class, you should definitely learn some C++.

I've tested the class in a console environment. There was one instance when I haven't done that, using openGL for drawing samples and I haven't found a single problem.
Take steps to meet all the requirments imposed by your GUI framework: having a winmain, or using a macro to implement the graphic env, or whatever it asks for (i'm not familliar with openCV).

You can't simply add my file (main.cpp) into your project and expect it to work, since my file has a main function and it prints data to cout. You'll have to use the main function of your graphic env (which will generate winmain, anyway), instantiate a class
Code: [Select]
SFile mySerial, open it (
Code: [Select]
mySerial.open(1,9600)) and then graph or show all the data you'll read using a label, button or whatever your GUI permits.

Izua ,I now know what the problem is .Yours zipped file has only sfile.cpp and sfile.h .There is no main block (or main.cpp) in it.Thats why I was getting such error.I think I need to create my own main block and call the functions in sfile.cpp

Offline bootstrapTopic starter

  • Full Member
  • ***
  • Posts: 61
  • Helpful? 0
Re: Serial port reading ADC values in DevCpp (like datalogger)
« Reply #8 on: March 09, 2008, 01:04:42 AM »
Quote
Izua
I am getting the following errors.Dont know why.!!!

main.o(.text+0x158):main.cpp: multiple definition of `SFile::Open(unsigned int, unsigned long)'
SFile.o(.text+0x58):SFile.cpp: first defined here
main.o(.text+0x388):main.cpp: multiple definition of `SFile::Read(void*, unsigned long, unsigned long&)'
SFile.o(.text+0x288):SFile.cpp: first defined here
main.o(.text+0x630):main.cpp: multiple definition of `SFile::Write(void const*, unsigned long, unsigned long&)'
SFile.o(.text+0x530):SFile.cpp: first defined here
main.o(.text+0x87e):main.cpp: multiple definition of `SFile::ReadByte(unsigned char&)'
SFile.o(.text+0x77e):SFile.cpp: first defined here
main.o(.text+0x8c8):main.cpp: multiple definition of `SFile::WriteByte(unsigned char)'
SFile.o(.text+0x7c8):SFile.cpp: first defined here
main.o(.text+0x918):main.cpp: multiple definition of `SFile::SetCommMask(unsigned long, unsigned char)'
SFile.o(.text+0x818):SFile.cpp: first defined here
main.o(.text+0x9ce):main.cpp: multiple definition of `SFile::WaitCommEvent(unsigned int, unsigned long*)'
SFile.o(.text+0x8ce):SFile.cpp: first defined here
main.o(.text+0xc10):main.cpp: multiple definition of `SFile::SetBaudRate(unsigned long)'
SFile.o(.text+0xb10):SFile.cpp: first defined here
main.o(.text+0xc94):main.cpp: multiple definition of `SFile::BytesInComm()'
SFile.o(.text+0xb94):SFile.cpp: first defined here
main.o(.text+0xce4):main.cpp: multiple definition of `SFile::PurgeComm()'
SFile.o(.text+0xbe4):SFile.cpp: first defined here
main.o(.text+0x100):main.cpp: multiple definition of `SFile::Close()'
SFile.o(.text+0x0):SFile.cpp: first defined here
collect2: ld returned 1 exit status

make.exe: *** [Project1.exe] Error 1

Execution terminated


Offline bootstrapTopic starter

  • Full Member
  • ***
  • Posts: 61
  • Helpful? 0
Re: Serial port reading ADC values in DevCpp (like datalogger)
« Reply #9 on: March 10, 2008, 04:07:54 AM »
Any idea about how to eliminate the errors?

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
    • izua electronics
Re: Serial port reading ADC values in DevCpp (like datalogger)
« Reply #10 on: March 10, 2008, 05:41:56 AM »
please post your main() and be sure to use include guards. looks like a idempotence problem to me.
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline bootstrapTopic starter

  • Full Member
  • ***
  • Posts: 61
  • Helpful? 0
Re: Serial port reading ADC values in DevCpp (like datalogger)
« Reply #11 on: March 10, 2008, 10:30:42 AM »
please post your main() and be sure to use include guards. looks like a idempotence problem to me.
#include <iostream.h>
#include <stdio.h>
#include <conio.h>

#include <E:\robotics\serialtry\sfile\SFile.h>
#include <E:\robotics\serialtry\sfile\SFile.cpp>
int main()
{
     SFile myserial;
     printf("ADC values\n");
     myserial.Open(1,9600);
     getch();
     return 0;
     }

Offline bootstrapTopic starter

  • Full Member
  • ***
  • Posts: 61
  • Helpful? 0
Re: Serial port reading ADC values in DevCpp (like datalogger)
« Reply #12 on: March 11, 2008, 09:27:00 AM »
So what is the problem in the code which is causing the error?

Offline bootstrapTopic starter

  • Full Member
  • ***
  • Posts: 61
  • Helpful? 0
Re: Serial port reading ADC values in DevCpp (like datalogger)
« Reply #13 on: March 13, 2008, 12:01:06 AM »
please post your main() and be sure to use include guards. looks like a idempotence problem to me.

"izua" i solved the problem regarding the linker errors...My question is say u have the ADC values coming from the serial port.I was able to get the values in the hyper terminal.Were you able to read the values with your program?(Which functions you used for this?)
« Last Edit: March 13, 2008, 12:03:06 AM by bootstrap »

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
    • izua electronics
Re: Serial port reading ADC values in DevCpp (like datalogger)
« Reply #14 on: March 13, 2008, 10:15:52 AM »
You're not seeing any values because you aren't invoking the class member which returns data from the buffer.
You must use classinstance.read/write/readbyte/writebyte.

Anyway, i attached my original test application, with main. Hope this works.
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline bootstrapTopic starter

  • Full Member
  • ***
  • Posts: 61
  • Helpful? 0
Re: Serial port reading ADC values in DevCpp (like datalogger)
« Reply #15 on: March 20, 2008, 04:52:30 AM »
Izua I am drawing a graph with the adc values.I was able to build the graph.But for that I used (int)b , i type casted the byte to interger.But this is not proving to be accurate.What I mean is if i have the adc values say 550,552 in terms of integers rather than the (int)b I will be able to interpret the graph in a better way.How shall I convert the byte 550 to integer 550 value.Please suggest

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
    • izua electronics
Re: Serial port reading ADC values in DevCpp (like datalogger)
« Reply #16 on: March 20, 2008, 09:59:17 AM »
this depends a lot on how are you receiving your data.
explain me the format the electronics send data to the port.

what library are you using to plot the graph?
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline bootstrapTopic starter

  • Full Member
  • ***
  • Posts: 61
  • Helpful? 0
Re: Serial port reading ADC values in DevCpp (like datalogger)
« Reply #17 on: March 21, 2008, 06:47:26 AM »
izua I was successuflly able to draw the graph.I am sending you the some of the  graphs generated real time .The values were obtained using potentiometer attached to ADC0 on atmega8.Also I have this MMA7261QT 3D accelerometer from freescale. I tried moving it around but did not observe any change in the output voltage level.It has been set to a sensitivity of 2.5 G.May be the accelerometer is damaged..?? I dont know why it is not showing any variations in the values.

Offline bootstrapTopic starter

  • Full Member
  • ***
  • Posts: 61
  • Helpful? 0
Re: Serial port reading ADC values in DevCpp (like datalogger)
« Reply #18 on: May 13, 2008, 06:43:25 AM »
this depends a lot on how are you receiving your data.
explain me the format the electronics send data to the port.

what library are you using to plot the graph?

Hey I want to send characters and strings using your program .What functions shall I use .Please give an example Izua.Thanks in advance .

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
    • izua electronics
Re: Serial port reading ADC values in DevCpp (like datalogger)
« Reply #19 on: May 13, 2008, 09:20:25 AM »
maybe the acce needs a pullup or something. check datasheet.
anyway dude, really helpful, you could have at least explained the library used for UI (as my initial request). I'm not even thinking of asking for sourcecode. dammit.

anyway, to send strings, just decide what exactly a "string" is, and make a function to read each byte in the string, know when to end, and send the bytes out one by one.
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline bootstrapTopic starter

  • Full Member
  • ***
  • Posts: 61
  • Helpful? 0
Re: Serial port reading ADC values in DevCpp (like datalogger)
« Reply #20 on: May 16, 2008, 09:41:33 PM »
this depends a lot on how are you receiving your data.
explain me the format the electronics send data to the port.

what library are you using to plot the graph?

Dear Izua ,I have used OpenCV to draw the graphs.I have use the function to draw lines between two points.I converted the ADC valuse to integer and used it as the vertical sepration between two points have the same X value.After that I incremented X value by unity.

Also is there a function in your headfer file to send chars or strings?

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,703
  • Helpful? 173
    • Society of Robots
Re: Serial port reading ADC values in DevCpp (like datalogger)
« Reply #21 on: May 24, 2008, 07:34:09 AM »
Hey bootstrap

Did you ever get it to work? I've recently had a need for something like this so I'm going to try it out soon too . . .


Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
    • izua electronics
Re: Serial port reading ADC values in DevCpp (like datalogger)
« Reply #22 on: August 03, 2008, 05:13:35 PM »
For anyone else who wonders how to send out C strings.
Code: [Select]
                char gigi[50]="testing testing..\n";

                char *p;
                p = &gigi[0];

                while (*p != 0)
                {
                    com.WriteByte(*p++);
                }
Check out my homepage for in depth tutorials on microcontrollers and electronics.

 


Get Your Ad Here