Connect with us

please help me, with Arduino uno serial communication

Discussion in 'Electronics Homework Help' started by bokica1991, Aug 27, 2012.

  1. bokica1991

    bokica1991

    5
    0
    Aug 27, 2012
    I have one problem, I'm new in programming and I don't have lot of experience. I have to make C# program which task is to send some array of numbers to Arduino board. On Arduino board I have to sum these numbers and to return result to C# program, but I don't understand how serial communication on Arduiono and C# works, how to stop transfer numbers from computer and how return. Please help me, i have watched some tutorial and read some explanation but I still don't understund. :(
     
  2. wingnut

    wingnut

    233
    8
    Aug 9, 2012
    Have you got your Uno up and running, and have you run a program and seen an LED flash or whatever? Have you tried out the analog program in the library and been able to read values onto the COM port window which you need to open to communicate with the Arduino?

    Then you write the array numbers to the Arduino, and you will sum these in C and the Arduino will write the sum to the COM port window.

    On my Linux computer I have to go to Accessories and double click on Terminal to open the Terminal - which is the same as the COM 1,2 or 3 port window on Windows, before I can read data back from the Uno.
     
  3. donkey

    donkey

    1,286
    56
    Feb 26, 2011
    this sounds like homework more than anything
    http://arduino.cc/en/Tutorial/AnalogReadSerial
    this link shows how to read an analog input and send it through the serial to display numbers in arduino. you can see the "Serial.println" gives the command to show the data on the serial port. you will also see the command line "Serial.begin(9600);" this is also important if you are using the arduino software (haven't had experience with other compilers so wouldn't know if it is the same there) make sure your serial monitor is set to that bitrate to display the correct numbers.

    now the only difference I see is rather than reading an anolog signal your are reading a set of numbers, then using arduino to add these numbers, then printing to serial again.
    there is another difference too... arduino uses c not c# so finding the compiler will be a fun experience. if you gave me about 20minutes and a good reason I could probably do this in an arduino sketch. but having said that this sounds alot like homework to me so will only offer guidance on what you have to look at
     
  4. dahhal

    dahhal

    58
    0
    Jul 17, 2012
    I'd would start with wingnuts suggestions and get a led flashing. The suggestion to use the andrino and output the numbers to the serial is also a good idea, even though you will end up doing the opposite and using the PC to output the numbers this is a good first step.

    I find putty good for windows available here: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

    I'm a C# programmer by trade, I never had to write a serial driver for it. If I did I'd start with an open source example like the following links especially if they compile. I assume you are using Visual Studio Express with windows?

    http://csharp.simpleserial.com/
    or
    http://www.codeproject.com/Articles/8605/Serial-Communication-using-C-and-Whidbey
     
  5. dahhal

    dahhal

    58
    0
    Jul 17, 2012
    I think the C# is for the PC to talk to the adrino board.

    The tutorial you linked to was more about reading a analogue input on the arduino and sending the value over serial.

    The following link shows a read followed by an echo back to terminal. Meaning if you were able to hook this up to a PC, you should be able to use a terminal program like putty set up the Baud Rate, and type whatever you want, and it would echo on the screen only because the program is reading the character encoded in ASCII, and writing it again. It will be a good start.


    http://arduino.cc/en/Serial/Read
     
  6. bokica1991

    bokica1991

    5
    0
    Aug 27, 2012

    please make my sketch. It is not homework, really. I'm studying electronic and I'm one of best student in my class, but in one point I realized that I don't know anything practical, only theoretical, so I asked my teacher what to learn by myself, and he gave me some tasks and one of them was this. he doesn't have time to works with me, so I have to learn all by myself. I didn't find any similar code, so I can't see how it works :) Please be good and help to improve my knowledge.
     
  7. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,174
    2,690
    Jan 21, 2010
    (moved to homework)
     
  8. dahhal

    dahhal

    58
    0
    Jul 17, 2012
    I'll try to help by breaking down the problem into manageable bits.

    A (Work on the Arduino SW)
    1. Get a LED flashing. Its the Hello World on Embedded
    2. Create a program on the Arduino to set up the Serial and continuously send a stream of message. Use the PC and a Terminal application to listen to that message
    3. Change the program on the Arduino to Print anything it receives from the terminal. 4. Change the program to except a string "12+54" and return the result to the terminal. Hint the string is encoded in ASCII and you may get a answer different then you expect if you don't account for this.

    B (Work on the PC)
    1. I'd expect it to be trivial if you can one of those C# samples that I have posted in an earlier post. You may find it easy to debug serial using an application like http://sourceforge.net/projects/com0com/. This allows you to hook up your Application to a Emulator, and you can hook up the terminal on the other end so you have the visibility what your application is sending.

    C (Put them Together)
    1. The only thing you may need to watch out for here is the protocol between PC and Arduino. is x+y an good protocol. When can your serial routine stop listening for Numbers. Its common to have a 1 byte Message Identifier in serial protocols, especially when you have multiple devices on the bus. Since ASCII would be a fine human readable protocol maybe start with the Character 'A'. A string normally will end the character '\0' then you know you can stop listening on the serial and start calculating.
     
  9. donkey

    donkey

    1,286
    56
    Feb 26, 2011
    ok let me show you how I got good at arduino in just 2 hours... and 3 easy steps
    step 1 buy arduino
    step 2 go through the tutorials on their page
    step 3 try to decipher the code from each tutorial...
    thats it.... I bang my head on a wall quite often as some coding, rf for example, still does my head in. but I try first.

    if this is homework and we give you the answer than no learning or thinking is done by you. if however you give us code and ask where you went wrong we could point out lines that might be an issue.... or connections etc
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-