Show Posts
|
|
Pages: [1]
|
|
2
|
Using Arduino / Interfacing w/ Software on the Computer / Re: interfacing arduino mega adk with vc++
|
on: January 05, 2013, 09:03:10 pm
|
Thanks for the quick answers, for: char buf0[1000], buf1[1000], buf2[1000], buf3[1000],buf4[1000], buf5[1000],buf6[1000], buf7[1000], buf8[1000], buf9[1000],buf10[1000], buf11[1000],buf12[1000], buf13[1000],buf14[1000], buf15[1000]; yes I was to afraid that the buffer will not enough  so do you recommend to change Serial.print("\n\r"); with Serial.println() and for more than 9 the char request[1]; with [code]char request[2]; but when I try with the serial monitor in arduino is fine I write 10 and the result is fine. but not working with the vc++ actually for 10, 11, etc I use program: sprintf_s(buffer,"10"); oSerial.WriteData(buffer,2); do I right?[/code]
|
|
|
|
|
4
|
Using Arduino / Interfacing w/ Software on the Computer / interfacing arduino mega adk with vc++
|
on: January 05, 2013, 08:23:38 pm
|
Hi, I want to read analog sensor using arduino mega adk and with Visual Studio C++ but the result is not correct, look like in the attachment: sensor 0:023 1 sensor1:023 1 sensor2:023 9 sensor3:21 etc my arduino program is: void setup() { // initialize serial communications at 9600 bps: Serial.begin(9600); }
void loop() { char request[1]; if(Serial.available()){ request[0]=Serial.read(); Serial.print(analogRead(atoi(request))); Serial.print("\n\r"); }; delay(2); }
and my vc++ program is: #include <windows.h> #include "stdafx.h" #include "SerialClass.h"
char buffer[20]; char buf0[1000], buf1[1000], buf2[1000], buf3[1000],buf4[1000], buf5[1000],buf6[1000], buf7[1000], buf8[1000], buf9[1000],buf10[1000], buf11[1000],buf12[1000], buf13[1000],buf14[1000], buf15[1000];
int _tmain(int argc, _TCHAR* argv[]) { Serial oSerial("COM5:");//arduino uno com 6 while(1){ sprintf_s(buffer,"0"); oSerial.WriteData(buffer,1); Sleep(100); oSerial.ReadData(buf0,6); printf("Sensor 0: %s \n",buf0); Sleep(100);
sprintf_s(buffer,"1"); oSerial.WriteData(buffer,1); Sleep(100); oSerial.ReadData(buf1,6); printf("Sensor 1: %s\n",buf1); Sleep(100); sprintf_s(buffer,"2"); oSerial.WriteData(buffer,1); Sleep(100); oSerial.ReadData(buf2,6); printf("Sensor 2: %s \n",buf2); Sleep(100);
sprintf_s(buffer,"3"); oSerial.WriteData(buffer,1); Sleep(100); oSerial.ReadData(buf3,6); printf("Sensor 3: %s\n",buf3); Sleep(100); sprintf_s(buffer,"4"); oSerial.WriteData(buffer,1); Sleep(100); oSerial.ReadData(buf4,6); printf("Sensor 4: %s \n",buf4); Sleep(100);
sprintf_s(buffer,"5"); oSerial.WriteData(buffer,1); Sleep(100); oSerial.ReadData(buf5,6); printf("Sensor 5: %s\n",buf5); Sleep(100); sprintf_s(buffer,"6"); oSerial.WriteData(buffer,1); Sleep(100); oSerial.ReadData(buf6,6); printf("Sensor 6: %s \n",buf6); Sleep(100);
sprintf_s(buffer,"7"); oSerial.WriteData(buffer,1); Sleep(100); oSerial.ReadData(buf7,6); printf("Sensor 7: %s\n",buf7); Sleep(100); sprintf_s(buffer,"8"); oSerial.WriteData(buffer,1); Sleep(100); oSerial.ReadData(buf8,6); printf("Sensor 8: %s \n",buf8); Sleep(100);
sprintf_s(buffer,"9"); oSerial.WriteData(buffer,1); Sleep(100); oSerial.ReadData(buf9,6); printf("Sensor 9: %s\n",buf9); Sleep(100); sprintf_s(buffer,"10"); oSerial.WriteData(buffer,2); Sleep(100); oSerial.ReadData(buf10,6); printf("Sensor 10: %s \n",buf10); Sleep(100);
sprintf_s(buffer,"11"); oSerial.WriteData(buffer,2); Sleep(100); oSerial.ReadData(buf11,6); printf("Sensor 11: %s\n",buf11); Sleep(100); sprintf_s(buffer,"12"); oSerial.WriteData(buffer,2); Sleep(100); oSerial.ReadData(buf12,6); printf("Sensor 12 %s \n",buf12); Sleep(100);
sprintf_s(buffer,"13"); oSerial.WriteData(buffer,2); Sleep(100); oSerial.ReadData(buf13,6); printf("Sensor 13: %s\n",buf13); Sleep(100); sprintf_s(buffer,"14"); oSerial.WriteData(buffer,2); Sleep(100); oSerial.ReadData(buf14,6); printf("Sensor 14: %s \n",buf14); Sleep(100);
sprintf_s(buffer,"15"); oSerial.WriteData(buffer,2); Sleep(100); oSerial.ReadData(buf15,6); printf("Sensor 15: %s\n",buf15); Sleep(100); } }
|
|
|
|
|
6
|
Using Arduino / Interfacing w/ Software on the Computer / programming serial arduino with visual C++
|
on: December 27, 2012, 06:49:16 pm
|
Hi all I try to read sensor analog from serial using Visual studio C++ 2010. my arduino program : void setup() { // initialize serial communications at 9600 bps: Serial.begin(9600); }
void loop() { char request[1]; if(Serial.available()){ request[0]=Serial.read(); Serial.print(analogRead(atoi(request))); Serial.print("\n\r"); }; delay(2); } my Serial C++ program : #include <windows.h> #include "stdafx.h" #include "SerialClass.h"
char buffer[20]; char buf0[200];
int _tmain(int argc, _TCHAR* argv[]) { Serial oSerial("COM6:"); while(1){ sprintf_s(buffer,"0"); oSerial.WriteData(buffer,1); Sleep(1000); oSerial.ReadData(buf0,4); printf("Sensor 0: %s \n",buf0); Sleep(1000); } }
I put 5V on sensor 0 but the result is not stable: sensor 0 : sensor 0 : 10230 sensor 0: 100 sensor 0: 23 0 sensor 0: 10230
and so on, I think there is no wrong with arduino side because when I use serial monitor on arduino it seems alright. Any suggestion?
|
|
|
|
|
7
|
Using Arduino / Interfacing w/ Software on the Computer / Re: read analog sensor with arduino uno and programming C
|
on: November 25, 2012, 11:34:02 pm
|
if I change with this one on arduino: int inbyte = 0; void setup() { Serial.begin(9600); }
void loop() { inbyte = Serial.read(); if(inbyte=='0'){ Serial.print(analogRead(0)); delay(10); Serial.print(" "); delay(10); } if(inbyte=='1'){ Serial.print(analogRead(1)); delay(10); Serial.print(" "); delay(10);} }
on C: while(1){ open_port(); write(fd,"0",1); read(fd,buf0,10); printf(" %s \n",buf0); usleep(100); write(fd,"1",1); read(fd,buf1,10); printf(" %s \n",buf1); usleep(100); }
There are no result on C, but when I open the serial port monitor on arduino. The results appear on the C program. but the result is weird. I Put 0 in input 0 and put 5 v (1023) in input 1. in serial monitor appear 102 0 in c appears 3 (empty) sometimes in serial monitor 10 0 in c appears 23 (emty)
|
|
|
|
|
8
|
Using Arduino / Interfacing w/ Software on the Computer / Re: read analog sensor with arduino uno and programming C
|
on: November 25, 2012, 06:59:50 pm
|
|
Thank for the advise Pauls,
I put delay betwen sending data because I will have sensors on the pins analog in, I assume that the adc need time to read the data.
and in the end I put the " " (spaces) in the end of each data because I need to identify data. So every data has space between others.
Do you have some idea for the aduino side?
For in the PC side: I assume that PC will get all the data at once, but If I see the result may be my assume is not right.
I will try to read every line and return to the loop.
regards
daniel
|
|
|
|
|
9
|
Using Arduino / Interfacing w/ Software on the Computer / read analog sensor with arduino uno and programming C
|
on: November 24, 2012, 10:43:28 pm
|
Dear All, I want to read data from analog sensor with arduino uno and read those data in my PC using C by serial port I will make data are look like this one [header A] [data sensor0] .. [data sensor5] [footer] (8 data) But the data do not stable when I read in my PC. some times the length of the data is 8 data, but sometimes less, some times more. Any suggestion? My arduino program: void setup() { Serial.begin(9600); }
void loop() { Serial.print("A "); delay(10); Serial.print(analogRead(0)); delay(10); Serial.print(" "); delay(10); Serial.print(analogRead(1)); delay(10); Serial.print(" "); delay(10); Serial.print(analogRead(2)); delay(10); Serial.print(" "); delay(10); Serial.print(analogRead(3)); delay(10); Serial.print(" "); delay(10); Serial.print(analogRead(4)); delay(10); Serial.print(" "); delay(10); Serial.print(analogRead(5)); delay(10); Serial.print(" "); delay(10); Serial.print(" B\n"); delay(10); } and my C program: int main(int argc, char**argv) { buf=malloc(4095); open_port(); free(buf); while(1){ read(fd,buf,60); printf("%s\n",buf); } close(fd); free(buf); } regard Daniel Moderator edit: [code] [/code] tags added.
|
|
|
|
|